Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Cancelling model changes done in a CustomFeature
Cancelling model changes done in a CustomFeature [message #1721363] Tue, 26 January 2016 20:21 Go to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
In Triquetrum, a Graphiti diagram represents a workflow where the nodes are actors with configurable names and parameters. The business/domain model is defined with EMF.

To configure an actor, I have defined an ActorConfigureFeature custom feature that is used as double-click feature in TriqToolBehaviorProvider.getDoubleClickFeature().
That one opens a dialog showing EMF Forms. These apply name/value changes directly on the underlying EMF model.

When the user then closes the dialoge via the "Ok"-button, all's well.
The problem is that I can not figure out how to implement a "Cancel"-button in the dialog, i.e. where all underlying model elements keep their original values after closing the dialogue via the Cancel button. At the moment this behaves just like the Ok button Shocked

I've been debugging this a bit and it seems that my ActorConfigureFeature is executed in GFCommandStack.execute(Command). The important section of code in there is :
tbp.preExecute(executionInfo);
	try {
		getEmfCommandStack().execute(gfPreparableCommand, options);
	} catch (RollbackException e) {
		if (e.getStatus().getSeverity() == IStatus.CANCEL) {
			// Just log it as info (operation was cancelled on purpose) 
			T.racer().log(IStatus.INFO, "GFCommandStack.execute(Command) " + e, e); //$NON-NLS-1$
		} else {
			// Just log it as an error
			T.racer().error("GFCommandStack.execute(Command) " + e, e); //$NON-NLS-1$
		}
	} catch (Exception e) {
		// Just log it as an error
		T.racer().error("GFCommandStack.execute(Command) " + e, e); //$NON-NLS-1$
	}
	tbp.postExecute(executionInfo);


It seems there's no support in the EMF command stack to do something like a "mark for rollback" from inside my feature, and that throwing an exception is the only path available to get the EMF "transaction" to rollback the model changes.

When I try that as follows :
  @Override
  public void execute(ICustomContext context) {
    PictogramElement[] pes = context.getPictogramElements();
    if (pes != null && pes.length == 1) {
      Object bo = getBusinessObjectForPictogramElement(pes[0]);
      if (bo instanceof NamedObj) {
        NamedObj modelElement = (NamedObj) bo;
        Shell shell = EclipseUtils.getActivePage().getActivePart().getSite().getShell();
        NamedObjDialog dialog = new NamedObjDialog(shell, modelElement);
        dialog.open();
        if(dialog.getReturnCode()==NamedObjDialog.CANCEL) {
          throw new OperationCanceledException();
        }
      }
    }
  }

The rollback indeed happens when clicking the Cancel button, but the logs get polluted with error stack traces for the OperationCanceledException.

Is there some proper way to react on a "cancel"-button to rollback the model changes, from within the custom feature implementation?

thanks
erwin
Re: Cancelling model changes done in a CustomFeature [message #1721470 is a reply to message #1721363] Wed, 27 January 2016 16:04 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1937
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Erwin,

actually, throwing a OperationCanceledException would be the way I would recommend to do it. Can you share the stacktraces written in the logs here?

Best regards,
Michael
Re: Cancelling model changes done in a CustomFeature [message #1721489 is a reply to message #1721470] Wed, 27 January 2016 18:51 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Hi Michael,

Thank you for the advice, I'll do it like that.

The error log is shown when launching with the "-consoleLog" argument.
Here's the stack trace I'm getting :

!ENTRY org.eclipse.graphiti.ui 1 0 2016-01-27 19:39:48.009
!MESSAGE GFCommandStack.execute(Command) org.eclipse.emf.transaction.RollbackException:
!STACK 0
org.eclipse.emf.transaction.RollbackException:
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:213)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl.execute(GFWorkspaceCommandStackImpl.java:96)
at org.eclipse.graphiti.ui.internal.editor.GFCommandStack.execute(GFCommandStack.java:138)
at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.performRequest(ShapeEditPart.java:575)
at org.eclipse.gef.tools.SelectEditPartTracker.performOpen(SelectEditPartTracker.java:194)
at org.eclipse.gef.tools.SelectEditPartTracker.handleDoubleClick(SelectEditPartTracker.java:137)
at org.eclipse.gef.tools.AbstractTool.mouseDoubleClick(AbstractTool.java:1069)
at org.eclipse.gef.tools.SelectionTool.mouseDoubleClick(SelectionTool.java:527)
at org.eclipse.gef.EditDomain.mouseDoubleClick(EditDomain.java:231)
at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouseDoubleClicked(DomainEventDispatcher.java:291)
at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseDoubleClick(LightweightSystem.java:518)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:196)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Re: Cancelling model changes done in a CustomFeature [message #1721703 is a reply to message #1721489] Fri, 29 January 2016 10:14 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1937
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Erwin,

probably we should be more defensive here and rather log that as an info or warning message instead of error with complete stacktrace. Would you please file a Bugzilla against Graphiti to track this?

Thanks,
Michael
Re: Cancelling model changes done in a CustomFeature [message #1721809 is a reply to message #1721703] Sun, 31 January 2016 08:39 Go to previous message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Michael,

I think it's already on INFO level, the IStatus.CANCEL is correctly identified in the catch section. But it's indeed the full stack trace that hints at an error, and that could maybe just be removed (or the complete log entry as such?).

I've created https://bugs.eclipse.org/bugs/show_bug.cgi?id=486902.
But this is really low priority, my most important concern was to know what the right approach was.

thanks again,
erwin
Previous Topic:Cannot move ContainerShape
Next Topic:Move diagram along with text
Goto Forum:
  


Current Time: Mon Dec 30 17:20:04 GMT 2024

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

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

Back to the top