Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Undo/Redo two Commands at once
Undo/Redo two Commands at once [message #1016463] Wed, 06 March 2013 14:55 Go to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi,

I created an action that creates two Command-chains that must be executed one after another.

The problem is, that "Undo" only 'undoes' the second Command-chain, which leads to an inconsistent state.

Is there a possibility to execute both Command-chains in a way that they will be undone with one Undo-Command (same for Redo)?

I'm thinking of adding an CommandStackListener to manually execute both Command-chains on Undo/Redo but this doesn't seem to be an elegant way (or is it?).

Thanks in advance!

Best regards,
Ralph
Re: Undo/Redo two Commands at once [message #1016475 is a reply to message #1016463] Wed, 06 March 2013 15:20 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 06-03-13 15:55, Ralph P wrote:
> Hi,
>
> I created an action that creates two Command-chains that must be
> executed one after another.
>
What's a command-chain? Do you mean you have two sets of
CompoundCommands? or you have 'regular' commands executing in sequence?

> The problem is, that "Undo" only 'undoes' the second Command-chain,
> which leads to an inconsistent state.
>
> Is there a possibility to execute both Command-chains in a way that they
> will be undone with one Undo-Command (same for Redo)?
Isn't CompoundCommand what you are looking for?
>
> I'm thinking of adding an CommandStackListener to manually execute both
> Command-chains on Undo/Redo but this doesn't seem to be an elegant way
> (or is it?).
>
> Thanks in advance!
>
> Best regards,
> Ralph
Re: Undo/Redo two Commands at once [message #1016485 is a reply to message #1016475] Wed, 06 March 2013 16:00 Go to previous messageGo to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi Christophe,

thanks you for your help!

> What's a command-chain? Do you mean you have two sets of
> CompoundCommands? or you have 'regular' commands executing in sequence?
It's a bunch of Add- and SetCommands chained together with Command#chain(Command) (so actually I have two AbstractCommands to execute).

> Isn't CompoundCommand what you are looking for?
Actually, StrictCompoundCommand at first sounds just like what I was looking for. But the following paragraph from the JavaDoc is probably the reason why it's not working for me:

 * It is important for all but the last command to have no visible side-effect!
 * Multiple commands with visible side-effects must be composed into a single command using just a {@link CompoundCommand}
 * and that composite could be the last command of a strict composite.


I have only commands with visible side effects.

I will have a closer look at that tomorrow!

Best regards,
Ralph
Re: Undo/Redo two Commands at once [message #1016517 is a reply to message #1016463] Wed, 06 March 2013 18:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ralph,

Is sounds like you just need to compose the two of them into a single
CompoundCommand... That's all the chains do under the covers too...


On 06/03/2013 3:55 PM, Ralph P wrote:
> Hi,
>
> I created an action that creates two Command-chains that must be
> executed one after another.
>
> The problem is, that "Undo" only 'undoes' the second Command-chain,
> which leads to an inconsistent state.
>
> Is there a possibility to execute both Command-chains in a way that
> they will be undone with one Undo-Command (same for Redo)?
>
> I'm thinking of adding an CommandStackListener to manually execute
> both Command-chains on Undo/Redo but this doesn't seem to be an
> elegant way (or is it?).
>
> Thanks in advance!
>
> Best regards,
> Ralph


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo two Commands at once [message #1016632 is a reply to message #1016517] Thu, 07 March 2013 08:26 Go to previous messageGo to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Thanks for the help! I found why it was not working even with a compound command.
The second Command(-chain) was invalid, since it expected the result of the first Command on creation (which was not yet executed).

In other words I did:
- Create Command 1
- Create Command 2 (<- That's the problem. Command 2 needs Command 1 to be executed before creation/initialization.)
- Execute both commands using a CompoundCommand

I will try to create my own AbstractOverrideableCommand and add it to a CompoundCommand, so it will be using the "new" EObjects after the first Command was executed.
EDIT: Creating a new CompundCommand is probably a better approach.

I know my explanations are kind of blurry, but it is fairly complicated what I'm trying to do(importing EObjects from one Resouruce into another, including lots of EReferences and a merge mechanism).

You already helped me a lot, I have no questions left right now. I'll post a status update as soon as I made some progress.

[Updated on: Thu, 07 March 2013 08:45]

Report message to a moderator

Re: Undo/Redo two Commands at once [message #1016643 is a reply to message #1016632] Thu, 07 March 2013 08:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ralph,

You might want to look at
org.eclipse.emf.common.command.CompoundCommand.appendAndExecute(Command).


On 07/03/2013 9:26 AM, Ralph P wrote:
> Thanks for the help! I found why it was not working even with a
> compound command.
> The second Command(-chain) was invalid, since it expected the result
> of the first Command on creation (which was not yet executed).
>
> In other words I did:
> - Create Command 1
> - Create Command 2 (<- That's the problem. Command 2 needs Command 1
> to be executed before creation/initialization.)
> - Execute both commands using a CompoundCommand
>
> I will try to create my own AbstractOverrideableCommand and add it to
> a CompoundCommand, so it will be using the "new" EObjects after the
> first Command was executed.
>
> I know my explanations are kind of blurry, but it is fairly
> complicated what I'm trying to do(importing EObjects from one
> Resouruce into another, including lots of EReferences and a merge
> mechanism).
>
> You already helped me a lot, I have no questions left right now. I'll
> post a status update as soon as I made some progress.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo two Commands at once [message #1016650 is a reply to message #1016643] Thu, 07 March 2013 09:18 Go to previous message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi Ed,

I got it! Thanks both of you!

I did something very similar to the DeleteCommand:
	
public class ImportCommand extends CompoundCommand {

	@Override
	protected boolean prepare() {
		Command ic = createImportCommand();
		append(ic);
		return ic.canExecute();
	}

	@Override
	public void execute() {
		super.execute();
		appendAndExecute(createMaintainCommand());
	}
}

Best regards,
Ralph
Previous Topic:Non-EMF object XMI serialization
Next Topic:[CDO] Need to refresh the Server after modify security model?
Goto Forum:
  


Current Time: Tue Apr 16 10:44:40 GMT 2024

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

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

Back to the top