Home » Modeling » GMF (Graphical Modeling Framework) » Cancelling a Dialog opened in a Command
Cancelling a Dialog opened in a Command [message #171793] |
Thu, 07 February 2008 15:44 |
Eclipse User |
|
|
|
Originally posted by: tobk42.gmx.de
Hello,
I have a simple Dialog for editing some elements that are not visible on
my diagram editor. That dialog is embedded in a Command which can be
executed in an action or by clicking a button on a custom property section.
My problem is: How can I cancel the dialog, reverting all changes? Below
is my Command class:
public class OrganizePropertiesCommand extends
AbstractTransactionalCommand {
private EObject modelElement;
public OrganizePropertiesCommand(EObject modelElement) {
super(TransactionUtil.getEditingDomain(modelElement), "Organize
Properties", Collections
..singletonList(WorkspaceSynchronizer.getFile(modelElement.e Resource())));
this.modelElement= modelElement;
}
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
//display dialog
OrganizePropertiesDialog dialog = new OrganizePropertiesDialog(
new Shell(),modelElement);
if (dialog.open() == Dialog.OK){
return CommandResult.newOKCommandResult(modelElement);
} else {
return CommandResult.newCancelledCommandResult();
}
}
}
As can be seen I check whether the dialog has been cancelled, in which
case I return a CancelledCommandResult, expecting that this will result
in not executing the changes made in the course of the command's
execution. But instead all the changes are made, only the command does
not appear on the command stack (and thus can not even be undone).
I thought about making a copy of the objects in question, but this would
cause trouble with the opposite references, I guess. Could you please
point me to a better solution for this problem?
Regards,
Tobias
|
|
|
Re: Cancelling a Dialog opened in a Command [message #171801 is a reply to message #171793] |
Thu, 07 February 2008 15:56 |
Eclipse User |
|
|
|
Originally posted by: tobk42.gmx.de
I found a workaround by wrapping the dialog in another command executed
inside of the other command. If the dialog has been cancelled, the inner
command will be undone by the outer command, which then returns a
CancelledCommandResult.
This seems to work, but it doesn't look nice. I'd still be thankful for
any better idea. ^^;;
Tobias
Tobias schrieb:
> Hello,
>
> I have a simple Dialog for editing some elements that are not visible on
> my diagram editor. That dialog is embedded in a Command which can be
> executed in an action or by clicking a button on a custom property section.
>
> My problem is: How can I cancel the dialog, reverting all changes? Below
> is my Command class:
>
> public class OrganizePropertiesCommand extends
> AbstractTransactionalCommand {
>
> private EObject modelElement;
>
> public OrganizePropertiesCommand(EObject modelElement) {
> super(TransactionUtil.getEditingDomain(modelElement), "Organize
> Properties", Collections
>
> .singletonList(WorkspaceSynchronizer.getFile(modelElement.eR esource())));
> this.modelElement= modelElement;
> }
>
> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> //display dialog
> OrganizePropertiesDialog dialog = new OrganizePropertiesDialog(
> new Shell(),modelElement);
> if (dialog.open() == Dialog.OK){
> return CommandResult.newOKCommandResult(modelElement);
> } else {
> return CommandResult.newCancelledCommandResult();
> }
> }
> }
>
> As can be seen I check whether the dialog has been cancelled, in which
> case I return a CancelledCommandResult, expecting that this will result
> in not executing the changes made in the course of the command's
> execution. But instead all the changes are made, only the command does
> not appear on the command stack (and thus can not even be undone).
>
> I thought about making a copy of the objects in question, but this would
> cause trouble with the opposite references, I guess. Could you please
> point me to a better solution for this problem?
>
> Regards,
> Tobias
|
|
|
Re: Cancelling a Dialog opened in a Command [message #171809 is a reply to message #171801] |
Thu, 07 February 2008 16:37 |
Eclipse User |
|
|
|
Originally posted by: ali.akar.geensys.com
hello,
look at the rollback in emf, maybe that help you.
Tobias a écrit :
> I found a workaround by wrapping the dialog in another command executed
> inside of the other command. If the dialog has been cancelled, the inner
> command will be undone by the outer command, which then returns a
> CancelledCommandResult.
>
> This seems to work, but it doesn't look nice. I'd still be thankful for
> any better idea. ^^;;
>
> Tobias
>
>
> Tobias schrieb:
>> Hello,
>>
>> I have a simple Dialog for editing some elements that are not visible
>> on my diagram editor. That dialog is embedded in a Command which can
>> be executed in an action or by clicking a button on a custom property
>> section.
>>
>> My problem is: How can I cancel the dialog, reverting all changes?
>> Below is my Command class:
>>
>> public class OrganizePropertiesCommand extends
>> AbstractTransactionalCommand {
>>
>> private EObject modelElement;
>>
>> public OrganizePropertiesCommand(EObject modelElement) {
>> super(TransactionUtil.getEditingDomain(modelElement), "Organize
>> Properties", Collections
>>
>> .singletonList(WorkspaceSynchronizer.getFile(modelElement.eR esource())));
>> this.modelElement= modelElement;
>> }
>>
>> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
>> IAdaptable info) throws ExecutionException {
>> //display dialog
>> OrganizePropertiesDialog dialog = new OrganizePropertiesDialog(
>> new Shell(),modelElement);
>> if (dialog.open() == Dialog.OK){
>> return CommandResult.newOKCommandResult(modelElement);
>> } else {
>> return CommandResult.newCancelledCommandResult();
>> }
>> }
>> }
>>
>> As can be seen I check whether the dialog has been cancelled, in which
>> case I return a CancelledCommandResult, expecting that this will
>> result in not executing the changes made in the course of the
>> command's execution. But instead all the changes are made, only the
>> command does not appear on the command stack (and thus can not even be
>> undone).
>>
>> I thought about making a copy of the objects in question, but this
>> would cause trouble with the opposite references, I guess. Could you
>> please point me to a better solution for this problem?
>>
>> Regards,
>> Tobias
|
|
|
Goto Forum:
Current Time: Fri Apr 26 18:31:48 GMT 2024
Powered by FUDForum. Page generated in 0.03156 seconds
|