Generated shortcut elements don't show edges until refresh? [message #208784] |
Thu, 16 October 2008 05:21 |
Jevon 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 |
Jevon 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
|
|
|
Powered by
FUDForum. Page generated in 0.02400 seconds