Cancelling model changes done in a CustomFeature [message #1721363] |
Tue, 26 January 2016 20:21 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Erwin De Ley![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=erwindl0%40gmail.com) 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
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07202 seconds