Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How can I initializing diagrams with elements
How can I initializing diagrams with elements [message #226459] Thu, 16 April 2009 22:43 Go to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
I would like my diagrams to always contain certain default figures. (These
figures are supposed to be the "start" and "end" elements of a workflow
illustrated via the diagram)

How can I achieve this? Is there a listener that could be registered with
the diagram's DiagramEditPart class? Or can I use the diagram's
DiagramEditPart's handleNotification() method somehow? I experimented with
both but couldn't find a handler or notification type that would
successfully represent the event that I'm looking for.

I though about doing the initializing in the diagram's creation wizard,
but this is not sufficient for the following reason: Some of the elements
in the main diagram can be double-clicked and edited in a sub-diagram. And
for these sub-diagrams I need the initialization functionality, too (and
there is no wizard creating these subdiagrams).

Any ideas? Thanks heaps in advance,
Thomas
Re: How can I initializing diagrams with elements [message #226524 is a reply to message #226459] Fri, 17 April 2009 09:21 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Thomas,

Try modifying ???DiagramEditorUtil.createDiagram() method

> sub-diagram. And for these sub-diagrams I need the initialization
> functionality, too (and there is no wizard creating these
> subdiagrams).
Then modify OpenDiagramEditPolicy or (even better) - just create these particular
elements already with necessary child elements (see Feature Seq Initializers)

-----------------
Alex Shatalin
Re: How can I initializing diagrams with elements [message #226796 is a reply to message #226524] Mon, 20 April 2009 22:06 Go to previous messageGo to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Great, the combination of modifying ???DiagramEditorUtil and defining
FeatureSeqInitializers in the .gmfmap file did it as far as the element
creation is concerned.

Now missing is to actually get those elements positioned on the screen. I
tried to overwrite 'setLocation()' for the elements' figures (I need those
diagram elements in a fixed position, so I thought I just set overwrite
setLocation() to always set the same coordinates). But astonishingly this
doesn't have any effect!? The figure coordinates seem to be set purely via
notification messages!? And, well, a notification message to update the
bounds seems not to be fired when I just create the elements in the
???DiagramEditorUtil method as shown below.

public class ???DiagramEditorUtil {
...
private static Composition createInitialModel() {
Composition comp =
CompmodellingFactory.eINSTANCE.createComposition();
PreScript preScript =
CompmodellingFactory.eINSTANCE.createPreScript();
PostScript postScript =
CompmodellingFactory.eINSTANCE.createPostScript();
CompModellingElementTypes.init_PreScript_1005(preScript);
CompModellingElementTypes.init_PostScript_1003(postScript);

comp.setPostScript(postScript);
comp.setPreScript(preScript);

return comp;
}
...
}


Can I cause update bounds events to be fired on the freshly created
elements somehow?
Re: How can I initializing diagrams with elements [message #226803 is a reply to message #226524] Mon, 20 April 2009 22:07 Go to previous messageGo to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
...sorry for these maybe stupid questions, but I'm completely new to
Eclipse development and try to find my way around! Thanks...
Re: How can I initializing diagrams with elements [message #226816 is a reply to message #226796] Tue, 21 April 2009 00:26 Go to previous messageGo to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Funny enough it works for one (but only one) of my elements that I insert
in ???DiagramEditorUtil.createInitialModel() method. I overwrite
notifyChanged() of the EditParts of both the elements (they are different
of different type!) in the way you see here:

public void notifyChanged(Notification notification) {
new Throwable().printStackTrace();
if (notification.getNotifier() instanceof Bounds) {
Bounds bounds = (Bounds) notification.getNotifier();
bounds.setX(FIXED_X);
bounds.setY(FIXED_Y);
}

super.notifyChanged(notification);
}

However, the notifyChanged() seems to be only invoked for the first
element. I produced a stackTrace (as seen in the code above) then traced
back the invocation chain. Part of it is here:
...
at
org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEdi tPolicy.executeCommand(CanonicalEditPolicy.java:514)
at
org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEdi tPolicy.createViews(CanonicalEditPolicy.java:470)
...

In tracing through createViews(...) with the debugger things at first are
as expected:

protected final List createViews(List eObjects) {
List descriptors = new ArrayList();
Iterator elements = eObjects.iterator();
while( elements.hasNext() ) {
EObject element = (EObject)elements.next();
if ( element != null ) {
CreateViewRequest.ViewDescriptor descriptor =
getViewDescriptor(element);
descriptors.add(descriptor);
}
}

if ( !descriptors.isEmpty() ) {
//
// create the request
CreateViewRequest request = getCreateViewRequest(descriptors);

//
// get the command and execute it.
Command cmd = getCreateViewCommand(request);
if ( cmd != null && cmd.canExecute() ) {
SetViewMutabilityCommand.makeMutable(new
EObjectAdapter(host().getNotationView())).execute();
executeCommand(cmd);
List adapters = (List)request.getNewObject();
return adapters;
}
}
return Collections.EMPTY_LIST;
}

The 'eObjects' list contains my two elements and the 'viewDescriptors'
entry in the produced 'request' seems to be fine, too. (It contains two
CreateViewRequests).

The contents of the produced 'cmd' I don't understand and when this
command is finally executed, notifyChanged() is only called on one of the
inserted elements, not the other.

Any ideas and explanations?
Re: How can I initializing diagrams with elements [message #226842 is a reply to message #226816] Tue, 21 April 2009 11:14 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Thomas,

Try moving these elements around the diagram - notifyChanged() should be
called then.

I suggest you overriding refreshBounds() method in an EditPart - this method
will be called not only from notifyChanged() one and you can set fixed positions
for the diagram node there.

-----------------
Alex Shatalin
Re: How can I initializing diagrams with elements [message #226907 is a reply to message #226842] Tue, 21 April 2009 21:19 Go to previous message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
Yep, that worked. I overwrote the EditPart's refreshBounds() method
instead of the notifyChanged() one and then it works also for the second
automatically inserted diagram element:

protected void refreshBounds() {
int width = ((Integer)
getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_ Width())).intValue();
int height = ((Integer)
getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_ Height())).intValue();
Dimension size = new Dimension(width, height);
int x = FIXED_X;
int y = FIXED_Y;
Point loc = new Point(x, y);
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), new Rectangle(loc, size));
}

Thanks heaps for the help!
Previous Topic:FixedConnectionAnchors from logic example
Next Topic:Query with ShapeCompartmentEditPart - ConnectionRefreshMgr
Goto Forum:
  


Current Time: Fri Apr 26 03:15:34 GMT 2024

Powered by FUDForum. Page generated in 0.02815 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top