Command in EditHelperAdvice [message #1782835] |
Fri, 02 March 2018 10:55 |
Yoann Farré Messages: 235 Registered: November 2017 |
Senior Member |
|
|
Hello everyone,
I created a new elementtype (derived from InvariantState) and I can add it to a sequence diagram. Well.
First, a stereotype is applied (thanks to a "Specialization Type Configuration"). Then, through an EditHelperAdvice class, a popup dialog box is opened to set an attribute of the stereotype. As a side option in the popup, I put a button to enable an easy access to another diagram.
What I want to obtain is the following behavior:
When the user click on the button:
- The pop up box is closed,
- The element is not created on the diagram (or delete immediately)
- And the wanted diagram is opened.
Unfortunately, I can't obtain this full behavior. Here is my simplified code (see comments in code)
@Override
protected ICommand getAfterConfigureCommand(final ConfigureRequest request) {
Shell shell = Display.getCurrent().getActiveShell();
EObject elementToConfigure = request.getElementToConfigure();
/*
* some tests
*/
CompositeCommand compositeCommand = new CompositeCommand("Configure created element");
// Create the dialogbox function of StateInvariant present on the lifeline
DialogBox dialog = new DialogBox(shell, elementToConfigure);
dialog.open();
if (IDialogConstants.OK_ID == dialog.getReturnCode()) {
//This is the standard case, not the problematic one
ICommand configureCommand = new ConfigureStateInvariantCommand(request, dialog.getSelectedEObject());
compositeCommand.add(configureCommand);
} else if (IDialogConstants.ABORT_ID == dialog.getReturnCode()) {
// the dialog box returns the ABORT_ID code when the famous button is clicked
ModelSet modelSet = getCurrentModelSet();
Resource notationResource = NotationUtils.getNotationResource(modelSet);
List<Diagram> diagramList = NotationUtils.getDiagrams(notationResource, dialog.getService());
for (Diagram diagram : diagramList) {
OpenDiagramCommand openDiagramCommand = new OpenDiagramCommand(modelSet.getTransactionalEditingDomain(), diagram);
compositeCommand.add(openDiagramCommand);
}
IElementEditService service = ElementEditServiceUtils.getCommandProvider(elementToConfigure);
DestroyElementRequest destroyRequest = new DestroyElementRequest(elementToConfigure, false);
compositeCommand.add(service.getEditCommand(destroyRequest));
}
return compositeCommand;
}
When I test this code and click on the famous button, the diagram that I want to open is opened but the element to create is not well destroyed. It is destroyed in the model but not in the diagram and I have an error message when reopening the model (dangling stereotype).
Is it a bug of the DestroyElementCommand or anything else?
What could be the workaround for this use case? I already tried to open directly the diagram in the listener of the button without success. Help would be greatly appreciated.
Thank you for reading.
Yoann.
|
|
|
Re: Command in EditHelperAdvice [message #1782844 is a reply to message #1782835] |
Fri, 02 March 2018 12:13 |
|
Hello Yoann,
The current implementation with the DestroyElementRequest is not the good way to get this behavior.
I think you should just return a command with the CommandResult value is CommandResult.newCancelledCommandResult(); I think it will be enough, and GMF will rollback the work previously done.
/Vincent
|
|
|
|
|
Re: Command in EditHelperAdvice [message #1782949 is a reply to message #1782849] |
Mon, 05 March 2018 14:34 |
|
Hi,
In fact, I find strange to open a dialog in the method getAfterConfigureCommand. The helpers are called very often by Papyrus and GMF framework, so I fear your dialog opens just when we try to build a command. It should be embedded in a command and your if/else must be in the body of this command. By this way, you will be able to return the newCancelledCommandResult.
|
|
|
|
Re: Command in EditHelperAdvice [message #1782997 is a reply to message #1782955] |
Tue, 06 March 2018 10:00 |
|
Hi, I didn't know the class CallBehaviorActionEditHelperAdvice. I continue to think it is strange to open a dialog in an helper advice...
Sorry, each time, I forgot you want to open a diagram AND deleting the objects previously created... yes, returning the cancelCommandResult will close the diagram too. I have no more idea.
|
|
|
|
Re: Command in EditHelperAdvice [message #1784778 is a reply to message #1783254] |
Wed, 04 April 2018 06:57 |
Yoann Farré Messages: 235 Registered: November 2017 |
Senior Member |
|
|
Hello,
I finally found a solution. I added to my CompositeCommand an OpenDiagramCommand with the following code:
TransactionalEditingDomain domain = getEditingDomain();
Map<String, Boolean> options = new HashMap<String, Boolean>();
options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
Diagram diagram = getDiagram();
OpenDiagramCommand openDiagramCmd = new OpenDiagramCommand(domain, diagram);
openDiagramCmd.setOptions(options);
compositeCommand.add(openDiagramCmd);
When the rollback process occurs, the newly created element is deleted and this command is eluded. The diagram is opened properly.
As the command doesn't change the model, the OPTION_UNPROTECTED is not an issue.
Yoann.
[Updated on: Wed, 04 April 2018 09:43] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08388 seconds