Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Generated shortcut elements don't show edges until refresh?
Generated shortcut elements don't show edges until refresh? [message #208784] Thu, 16 October 2008 05:21 Go to next message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
This is an issue I totally solved by accident. My problem was that, when
adding shortcut elements to a diagram, the connections between the
diagrams would not be added until F5 was pressed.

It turns out the solution is as easy as collecting the viewDescriptors
used whilst creating the shortcut elements, and then issuing a
DeferredLayoutCommand:

// we have a list of objects we want to add as shortcuts to the current view
for (EObject newObject : toAdd) {
CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(
new EObjectAdapter(newObject), Node.class, null,
prefHint);

// create element
command = new CreateCommand(
selectedElement.getEditingDomain(), viewDescriptor, parentView);

// add shortcut
command = command.compose(new CreateShortcutDecorationsCommand(
selectedElement.getEditingDomain(), parentView, viewDescriptor,
this.getEditPartModelId()));

// execute
doExecute(command); //execute it now

// get the created element
viewAdapters.add(viewDescriptor);

}

DeferredLayoutCommand dlc = new
DeferredLayoutCommand(selectedElement.getEditingDomain(),
viewAdapters, selectedElement);
doExecute(dlc);


Hope this code helps somebody else! :)

Jevon
Re: Generated shortcut elements don't show edges until refresh? [message #208795 is a reply to message #208784] Thu, 16 October 2008 05:27 Go to previous message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
Another benefit of executing a DeferredLayoutCommand to a series of
generated elements, is that it will automatically reposition elements
that have been placed on top of each other (e.g. at (0,0)) into a more
appealing arrangement (which can be configured by an additional
parameter to DeferredLayoutCommand).

Jevon

Jevon Wright wrote:
> This is an issue I totally solved by accident. My problem was that, when
> adding shortcut elements to a diagram, the connections between the
> diagrams would not be added until F5 was pressed.
>
> It turns out the solution is as easy as collecting the viewDescriptors
> used whilst creating the shortcut elements, and then issuing a
> DeferredLayoutCommand:
>
> // we have a list of objects we want to add as shortcuts to the current
> view
> for (EObject newObject : toAdd) {
> CreateViewRequest.ViewDescriptor viewDescriptor = new
> CreateViewRequest.ViewDescriptor(
> new EObjectAdapter(newObject), Node.class, null,
> prefHint);
>
> // create element
> command = new CreateCommand(
> selectedElement.getEditingDomain(), viewDescriptor, parentView);
>
> // add shortcut
> command = command.compose(new CreateShortcutDecorationsCommand(
> selectedElement.getEditingDomain(), parentView, viewDescriptor,
> this.getEditPartModelId()));
>
> // execute
> doExecute(command); //execute it now
>
> // get the created element
> viewAdapters.add(viewDescriptor);
>
> }
>
> DeferredLayoutCommand dlc = new
> DeferredLayoutCommand(selectedElement.getEditingDomain(),
> viewAdapters, selectedElement);
> doExecute(dlc);
>
>
> Hope this code helps somebody else! :)
>
> Jevon
Previous Topic:NoClassDefFoundError:GenParserImplementation
Next Topic:how to add a scrollbar for label
Goto Forum:
  


Current Time: Wed Apr 24 19:42:34 GMT 2024

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

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

Back to the top