[EMF] [CommandStack] Best Practices to use ChangeCommand around UI Dialog [message #900231] |
Sun, 05 August 2012 18:08  |
Eclipse User |
|
|
|
I try to do this:
- To change an EMF model object by an UI Dialog (jface TitleAreaDialog)
- To register the changes in the CommandStack only if user does a click in the Ok Button of the Dialog
- To undo the possible changes in the dialog if user does a click in the Cancel Button (not register the changes in the CommandStack)
To register the changes, I use ChangeCommand.
My Code is more or less the next:
Collection<Notifier> objectsToRecord = new ArrayList<Notifier>();
objectsToRecord.add(objectToRegisterChanges);
cancel = false;
ChangeCommand changeCommand = new ChangeCommand(objectsToRecord) {
@Override
protected void doExecute() {
CustomDialog editorDialog = new CustomDialog(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NONE,
objectToRegisterChanges);
editorDialog.create();
if (editorDialog.open() != Window.OK) {
cancel = true;
}
}
};
getCommandStack().execute(command);
if(cancel) {
getCommandStack().undo();
}
objectToRegisterChanges is an EMF Object
CustomDialog extends JFace TitleAreaDialog where attributes and list belong to objectToRegisterChanges are changed
getCommandStack() returns my own BasicCommandStack
Even if user does a click in Cancel Button, the changes in the objectToRegisterChanges are added to CommandStack by the ChangeCommand. My code logically does the undo in this case but the command is on the top of the CommandStack and it can be redo
Does someone say to me the best solution for my situation or guide me??
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07827 seconds