Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:How to refresh title bar
Next Topic:GMF Serialization
Goto Forum:
  


Current Time: Fri Apr 26 18:31:48 GMT 2024

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

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

Back to the top