Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Command in EditHelperAdvice
Command in EditHelperAdvice [message #1782835] Fri, 02 March 2018 10:55 Go to next message
Yoann Farré is currently offline Yoann FarréFriend
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 Go to previous messageGo to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
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 #1782846 is a reply to message #1782844] Fri, 02 March 2018 12:18 Go to previous messageGo to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
Sorry, I misread your problem. So, the DestroyElementRequest is probably required for your usecase. I don't have yet other ideas for the moment.

/Vincent
Re: Command in EditHelperAdvice [message #1782849 is a reply to message #1782846] Fri, 02 March 2018 12:36 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hello Vincent,

Thank you for your reply. I also tried to return a CommandResult.newCancelledCommandResult() but, like you said, it is probably not the good way because, in this case, GMF rollback all the work previously done, including the opening of the diagram...
If an idea comes, I'm ready to test it ;)
Re: Command in EditHelperAdvice [message #1782949 is a reply to message #1782849] Mon, 05 March 2018 14:34 Go to previous messageGo to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
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 #1782955 is a reply to message #1782835] Mon, 05 March 2018 15:26 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hi,

For the code, I took my inspiration from CallBehaviorActionEditHelperAdvice (org.eclipse.papyrus.uml.diagram.activity.edit.advices)

I first try like you describe but although the diagram was correctly opened after I clicked the button, it is immediately closed because the return of a newCancelledCommandResult (I suppose). But now I work on this issue from a few days, I could give a new shot on this proposal.

Thank you for your reply. I appreciate ;)
Re: Command in EditHelperAdvice [message #1782997 is a reply to message #1782955] Tue, 06 March 2018 10:00 Go to previous messageGo to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
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 #1783254 is a reply to message #1782997] Fri, 09 March 2018 17:06 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hi,

I'm still stuck with this.

Is there a way to avoid the rollback process on a specific command?
Or to execute code in any case?

Or maybe by another way than an EditHelperAdvice class?

Thanks for reading.

Yoann.
Re: Command in EditHelperAdvice [message #1784778 is a reply to message #1783254] Wed, 04 April 2018 06:57 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
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

Re: Command in EditHelperAdvice [message #1784788 is a reply to message #1784778] Wed, 04 April 2018 07:52 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Yoann,

Quote:
As the command doesn't change the model, the OPTION_PROTECTED is not an issue.


It actually does; there is a hidden *.sash model in your workspace settings area, which tracks open diagrams and editor layout. This file is just not in your workspace projects; but it's definitely present :)

When using Unprotected transactions, just make sure Undo/Redo works properly (run Undo/Redo at least twice, as in some cases, an incorrect "redo" implementation may break the command stack; especially when it comes to unprotected operations), and you should be good to go.

HTH,
Camille


Camille Letavernier
Re: Command in EditHelperAdvice [message #1784803 is a reply to message #1784788] Wed, 04 April 2018 10:08 Go to previous message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hello Camille,

Thank you for the explanation, I didn't know this file. In my case, the behavior seems to be good but I will stay attentive to this point.

Thank you.

Yoann.
Previous Topic:Association class doubt
Next Topic:From UML to MOF with Papyrus
Goto Forum:
  


Current Time: Fri Apr 19 13:01:09 GMT 2024

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

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

Back to the top