Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to add an RecordingCommand to the Undo/Redo menu?
How to add an RecordingCommand to the Undo/Redo menu? [message #524753] Fri, 02 April 2010 05:16 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

I invoke intensive modifications of a model with a RecordingCommand.
Those modifications can affect referenced (or dependent) models in other
resources, too. With the following code I invoke those modifications:

ResourceSet rs = originalResource.getResourceSet();
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(rs);
CommandStack stack = domain.getCommandStack();
RecordingCommand command = new MyRecordingCommand(domain);
stack.execute(command);

Now, I want that this intensive RecordingCommand can be undone by
pressing Ctrl+Z or by clicking in the Edit menu on undo. The point is
that I want to undo all modifications which have been made in the whole
resourceSet and not only those from the original resource. With the code
above the undo command in the Edit menu doesn't provide any undo
functionality. How can I achieve this? If an exception occurres when
executing the command above I catch it and call command.undo(). Exactly
this I want to contribute to the edit menu. I found the following very
short description:
http://help.eclipse.org/galileo/topic/org.eclipse.emf.worksp ace.doc/references/overview/undoredo.html
But I don't know if I can solve the problem with an UndoActionWrapper or
RedoActionWrapper. And if I can I actually can't find those classes.
Ctrl+Shift+T returns an empty list when searching for those types. Which
plugin do I need in my workspace (I have the modeling version of Eclipse).

best regards,
Gilbert
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524802 is a reply to message #524753] Fri, 02 April 2010 14:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Gilbert,

Comments below.

Gilbert Mirenque wrote:
> I invoke intensive modifications of a model with a RecordingCommand.
> Those modifications can affect referenced (or dependent) models in other
> resources, too. With the following code I invoke those modifications:
>
> ResourceSet rs = originalResource.getResourceSet();
> TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(rs);
> CommandStack stack = domain.getCommandStack();
> RecordingCommand command = new MyRecordingCommand(domain);
> stack.execute(command);
>
> Now, I want that this intensive RecordingCommand can be undone by
> pressing Ctrl+Z or by clicking in the Edit menu on undo. The point is
> that I want to undo all modifications which have been made in the whole
> resourceSet and not only those from the original resource.
The way I read the APIs, it should be recording all changes for all
objects in the entire resource set.
> With the code
> above the undo command in the Edit menu doesn't provide any undo
> functionality.
Sounds like something else is going wrong. Most certainly it should
provide undo support.
> How can I achieve this? If an exception occurres when
> executing the command above I catch it and call command.undo().
I think the transactional support automatically does a rollback already.
> Exactly
> this I want to contribute to the edit menu.
I'm not sure what you mean be exactly this. A rolled back transaction
is a no-op. There's nothing to undo.
> I found the following very
> short description:
> http://help.eclipse.org/galileo/topic/org.eclipse.emf.worksp ace.doc/references/overview/undoredo.html
> But I don't know if I can solve the problem with an UndoActionWrapper or
> RedoActionWrapper. And if I can I actually can't find those classes.
> Ctrl+Shift+T returns an empty list when searching for those types. Which
> plugin do I need in my workspace (I have the modeling version of Eclipse).
>
I expect all this stuff just to work...
> best regards,
> Gilbert
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524821 is a reply to message #524802] Fri, 02 April 2010 13:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Ed,
> The way I read the APIs, it should be recording all changes for all
> objects in the entire resource set.
Yes, this is not the problem

> Sounds like something else is going wrong. Most certainly it should
> provide undo support.

> I think the transactional support automatically does a rollback already.

> I'm not sure what you mean be exactly this. A rolled back transaction
> is a no-op. There's nothing to undo.

Yes, transactions provide undo support. But what I want is that the user
can initiate an undo after the modifications. Therefore I can imagine
that I have to register the command in the overall workbench operation
history or something like that. When the command was executed I expect
that in the Edit menu the undo arrow is enabled but it is not in my
case. Is that explanation more understandable?
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524886 is a reply to message #524821] Sat, 03 April 2010 09:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080301050004020707030403
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Gilbert,

Comments below.

Gilbert Mirenque wrote:
> Hi Ed,
>
>> The way I read the APIs, it should be recording all changes for all
>> objects in the entire resource set.
>>
> Yes, this is not the problem
>
>
>> Sounds like something else is going wrong. Most certainly it should
>> provide undo support.
>>
>
>
>> I think the transactional support automatically does a rollback already.
>>
>
>
>> I'm not sure what you mean be exactly this. A rolled back transaction
>> is a no-op. There's nothing to undo.
>>
>
> Yes, transactions provide undo support. But what I want is that the user
> can initiate an undo after the modifications. Therefore I can imagine
> that I have to register the command in the overall workbench operation
> history or something like that. When the command was executed I expect
> that in the Edit menu the undo arrow is enabled but it is not in my
> case. Is that explanation more understandable?
>
Yes, but as I said, this should just work. All generated GMF editors
rely on this and they do have working undo support. If it's not
working, something is wrong, but you've not said anything that would
give me a clue about what's wrong. Perhaps an exception is being
thrown, a rollback is kicking in, and then there's really nothing left
to undo.


--------------080301050004020707030403
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Gilbert,<br>
<br>
Comments below.<br>
<br>
Gilbert Mirenque wrote:
<blockquote cite="mid:hp5bl4$va$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,
</pre>
<blockquote type="cite">
<pre wrap="">The way I read the APIs, it should be recording all changes for all
objects in the entire resource set.
</pre>
</blockquote>
<pre wrap=""><!---->Yes, this is not the problem

</pre>
<blockquote type="cite">
<pre wrap="">Sounds like something else is going wrong. Most certainly it should
provide undo support.
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">I think the transactional support automatically does a rollback already.
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">I'm not sure what you mean be exactly this. A rolled back transaction
is a no-op. There's nothing to undo.
</pre>
</blockquote>
<pre wrap=""><!---->
Yes, transactions provide undo support. But what I want is that the user
can initiate an undo after the modifications. Therefore I can imagine
that I have to register the command in the overall workbench operation
history or something like that. When the command was executed I expect
that in the Edit menu the undo arrow is enabled but it is not in my
case. Is that explanation more understandable?
</pre>
</blockquote>
Yes, but as I said, this should just work.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524926 is a reply to message #524886] Sun, 04 April 2010 09:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Ed,
> Yes, but as I said, this should just work. All generated GMF editors
> rely on this and they do have working undo support. If it's not
> working, something is wrong, but you've not said anything that would
> give me a clue about what's wrong. Perhaps an exception is being
> thrown, a rollback is kicking in, and then there's really nothing left
> to undo.
No rollback is executed because I see the changes in the model.
The changes have been persisted, too, i.e. they could be saved. But the
undo entry in the Edit menu still isn't activated.
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524931 is a reply to message #524886] Sun, 04 April 2010 10:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Now I tried the following:

TransactionalEditingDomain domain = // get it from somewhere;
CommandStack stack = domain.getCommandStack();
RecordingCommand command = new MyRecordingCommand(domain);
stack.execute(command);
IUndoableOperation operation = new MyUndoOperation(command);
IOperationHistory history =
PlatformUI.getWorkbench().getOperationSupport().getOperation History();
history.add(operation);

MyUndoOperation implements IUndoableOperation and delegates all methods
to the command which will be passed in the constructor, except one:
execute(IProgressMonitor,IAdaptable). This method just does nothing
because the command has already been executed. To make it always
undoable I return the following in the getContexts() method:

new IUndoContext[]{IOperationHistory.GLOBAL_UNDO_CONTEXT};

But this approach isn't successfull either. The undo entry in the Edit
menu still isn't activated. Is it possible to look into the operation
history of the platform? Maybe there is a view which can be installed?

best regards,
Gilbert
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524935 is a reply to message #524931] Sun, 04 April 2010 12:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Gilbert,

Hopefully someone more familiar with these APIs will answer but as I
keep suggesting all this just works in a generated GMF editor so perhaps
it would be good to look at one of those to see how they invoke
commands. Perhaps you've just not really hooked the Undo/Redo actions
to the command stack properly.


Gilbert Mirenque wrote:
> Now I tried the following:
>
> TransactionalEditingDomain domain = // get it from somewhere;
> CommandStack stack = domain.getCommandStack();
> RecordingCommand command = new MyRecordingCommand(domain);
> stack.execute(command);
> IUndoableOperation operation = new MyUndoOperation(command);
> IOperationHistory history =
> PlatformUI.getWorkbench().getOperationSupport().getOperation History();
> history.add(operation);
>
> MyUndoOperation implements IUndoableOperation and delegates all methods
> to the command which will be passed in the constructor, except one:
> execute(IProgressMonitor,IAdaptable). This method just does nothing
> because the command has already been executed. To make it always
> undoable I return the following in the getContexts() method:
>
> new IUndoContext[]{IOperationHistory.GLOBAL_UNDO_CONTEXT};
>
> But this approach isn't successfull either. The undo entry in the Edit
> menu still isn't activated. Is it possible to look into the operation
> history of the platform? Maybe there is a view which can be installed?
>
> best regards,
> Gilbert
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524939 is a reply to message #524935] Sun, 04 April 2010 09:24 Go to previous message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Ed,
> Hopefully someone more familiar with these APIs will answer but as I
> keep suggesting all this just works in a generated GMF editor so perhaps
> it would be good to look at one of those to see how they invoke
> commands. Perhaps you've just not really hooked the Undo/Redo actions
> to the command stack properly.
Ok, the whole story works for GMF editors. But what about other editors
like the generated tree editor? Within those it doesn't work.
Re: How to add an RecordingCommand to the Undo/Redo menu? [message #524942 is a reply to message #524939] Sun, 04 April 2010 10:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050303000306080809070703
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Gilbert,

It's clearly impossible to know from just this note thread what you've
all done to set things up. Likely some very small but important aspect
has been overlooked.

The transaction project provides downloadable examples for how to use
the framework; have you looked at those?


Gilbert Mirenque wrote:
> Hi Ed,
>
>> Hopefully someone more familiar with these APIs will answer but as I
>> keep suggesting all this just works in a generated GMF editor so perhaps
>> it would be good to look at one of those to see how they invoke
>> commands. Perhaps you've just not really hooked the Undo/Redo actions
>> to the command stack properly.
>>
> Ok, the whole story works for GMF editors. But what about other editors
> like the generated tree editor? Within those it doesn't work.
>

--------------050303000306080809070703
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Gilbert,<br>
<br>
It's clearly impossible to know from just this note thread what you've
all done to set things up.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Dropping @Override from generated source
Next Topic:EMF Validation: Marker Problem
Goto Forum:
  


Current Time: Tue Apr 16 21:16:09 GMT 2024

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

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

Back to the top