Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » set decorators without validation
set decorators without validation [message #987195] Sat, 24 November 2012 06:27 Go to next message
Rami D. is currently offline Rami D.
Messages: 14
Registered: August 2012
Junior Member
Hi,

I wonder if it is possible to place a validation decorator onto a node without validating the diagram. A transformation is performed when saving and in case an exception is raised, i want to attach decorators (and probably markers for the problems view) to one or more specific elements on the canvas. How can this be realized, if at all?

Regards,
Rami
Re: set decorators without validation [message #987205 is a reply to message #987195] Sat, 24 November 2012 08:02 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas Muelder
Messages: 71
Registered: July 2011
Member
Hello Rami,

you can create IMarkers for exceptions in your transformation and add them to the underlying IResource. GMFs validation decoration provider will display them if they are of type org.eclipse.gmf.runtime.common.ui.services.marker.

To map the marker to a graphical element, you should set the custom marker attribute
org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID to the URI fragment
of the notation model element to display.

Regards,

Andreas
Re: set decorators without validation [message #987223 is a reply to message #987205] Sat, 24 November 2012 12:36 Go to previous messageGo to next message
Rami D. is currently offline Rami D.
Messages: 14
Registered: August 2012
Junior Member
Hi Andreas,

wow, this sounds really straightforward. Smile I'll try this out.
Many thanks for your help.

Regards,
Rami
Re: set decorators without validation [message #987238 is a reply to message #987223] Sat, 24 November 2012 17:07 Go to previous messageGo to next message
Rami D. is currently offline Rami D.
Messages: 14
Registered: August 2012
Junior Member
Hi Andreas,

i've followed your approach and it works great. Thanks again!

For those who are interested, here is the code:

IEditorPart editor = ... ;
Diagram diagram = editor.getDiagram();
Resource diagramResource = diagram.eResource();
URI uri = diagramResource.getURI();

if(uri.isPlatformResource())
{
 String platformURI = uri.toPlatformString(true);
 IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(platformURI);

 String uriFragment = ViewUtil.getIdStr((View) editpart.getModel());

 IMarker m = res.createMarker(XXXDiagramEditorPlugin.ID + ".diagnostic");
 m.setAttribute(IMarker.MESSAGE, "transformation error occurred: " +  
   eobj.getClass().getSimpleName() + " could not be transformed.");
 m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
 m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
 m.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
   uriFragment);
}


note: the created marker must be of type XXXDiagramEditorPlugin.ID + ".diagnostic" to be handled by the validation decorator provider.
Re: set decorators without validation [message #987361 is a reply to message #987238] Mon, 26 November 2012 04:56 Go to previous message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
Registered: November 2009
Senior Member
Hi,

maybe you could add it to the wiki:
http://wiki.eclipse.org/Graphical_Modeling_Framework/Tips

Ralph
Previous Topic:Connection between nodes created in the model, don't appear in the graphical editor
Next Topic:get business object from editpart
Goto Forum:
  


Current Time: Tue Sep 02 05:26:06 EDT 2014

Powered by FUDForum. Page generated in 0.03494 seconds