Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » RemoveCommand multiple executions
RemoveCommand multiple executions [message #416233] Tue, 22 January 2008 23:36 Go to next message
Vasanth Velusamy is currently offline Vasanth VelusamyFriend
Messages: 31
Registered: July 2009
Member
I have a question/issue with the use of CompoundCommand in a multi-page
editor (the mpe code-generated using the EMF framework).

I am using a CompoundCommand to encapsulate several SetCommand /
AddCommand / RemoveCommand. Each of these sub commands are appended and
executed using CompoundCommand.appendAndExecute(..). Finally, this
CompoundCommand is executed in the multi-page editor's command stack
using CommandStack.execute(..).

As you can see, the sub commands are executed initially, and also at the
end when the compound command is executed in the mpe's command stack.
This works fine for SetCommand and AddCommand as they are idempotent
(AddCommand, for example, does not add duplicates when executed again).
However, RemoveCommand doesn't behave so. It throws an exception during
the second execution.

Is it not correct to execute sub commands, and then execute the compound
command again? If I should not be executing the compound command at
the end, how do I add the compound command to the mpe's command stack? I
cannot use CompoundCommand.append(..) since I do need some of the sub
command executions to happen earlier, rather than wait till the compound
command to get executed.

Would I have to subclass RemoveCommand to make it idempotent, or maybe
subclass CompoundCommand and not allow it to be executed twice? Am I
missing something here?

Thanks,
Vasanth
Re: RemoveCommand multiple executions [message #416235 is a reply to message #416233] Wed, 23 January 2008 00:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vasanth,

Comments below.


Vasanth Velusamy wrote:
> I have a question/issue with the use of CompoundCommand in a
> multi-page editor (the mpe code-generated using the EMF framework).
>
> I am using a CompoundCommand to encapsulate several SetCommand /
> AddCommand / RemoveCommand. Each of these sub commands are appended
> and executed using CompoundCommand.appendAndExecute(..). Finally, this
> CompoundCommand is executed in the multi-page editor's command stack
> using CommandStack.execute(..).
That's sounding problematic. I would expect appendAndExecute would
only be used during the execute of the compound command itself.
>
> As you can see, the sub commands are executed initially, and also at
> the end when the compound command is executed in the mpe's command stack.
Sounds bad.
> This works fine for SetCommand and AddCommand as they are idempotent
> (AddCommand, for example, does not add duplicates when executed
> again). However, RemoveCommand doesn't behave so. It throws an
> exception during the second execution.
It sounds like you should be using appendIfCanExecute.
>
> Is it not correct to execute sub commands, and then execute the
> compound command again?
No.
> If I should not be executing the compound command at the end, how do I
> add the compound command to the mpe's command stack?
You should just append them.
> I cannot use CompoundCommand.append(..) since I do need some of the
> sub command executions to happen earlier, rather than wait till the
> compound command to get executed.
I don't understand this part. The things that should happen first
should be at the beginning of the list of commands.
>
> Would I have to subclass RemoveCommand to make it idempotent, or maybe
> subclass CompoundCommand and not allow it to be executed twice? Am I
> missing something here?
I'm not sure. I don't understand how executing commands outside of the
execution of the parent command's execution on the command stack is
necessary for the behavior you are trying to achieve. I'd expect the
compound command to be a list of commands that can be executed in order
to achieve the final desired result...
>
> Thanks,
> Vasanth


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: RemoveCommand multiple executions [message #416251 is a reply to message #416235] Wed, 23 January 2008 15:11 Go to previous messageGo to next message
Vasanth Velusamy is currently offline Vasanth VelusamyFriend
Messages: 31
Registered: July 2009
Member
Ed,

Taking a step back,

I have sub commands A, B, C, .. (combination of SetCommand, AddCommand,
RemoveCommand) to be combined as one operation in a CompoundCommand (for
consolidated undo/redo). I also want command A to be executed right
away, when A is prepared (so cannot use CompoundCommand.append(), but
will have to use CompoundCommand.appendAndExecute()).

Now, finally, in order to add the CompoundCommand to the command stack
in the multi-page editor, I have to execute the CompoundCommand in the
context of the command stack (something like
AdapterFactoryEditingDomain.getEditingDomainFor(myModel).get CommandStack().execute(myCompoundCommand)).

So, should I be preparing my CompoundCommand a different way,
or,
is there a way to add the already-executed CompoundCommand to the
editing domain's command stack? If there is such a way , I can do
CompoundCommand.appendAndExecute(..) for all my sub-commands A, B, C and
not have to execute the CompoundCommand again at the end.

Hope that clarifies my issue.

Thanks,
Vasanth


Ed Merks wrote:
> Vasanth,
>
> Comments below.
>
>
> Vasanth Velusamy wrote:
>> I have a question/issue with the use of CompoundCommand in a
>> multi-page editor (the mpe code-generated using the EMF framework).
>>
>> I am using a CompoundCommand to encapsulate several SetCommand /
>> AddCommand / RemoveCommand. Each of these sub commands are appended
>> and executed using CompoundCommand.appendAndExecute(..). Finally, this
>> CompoundCommand is executed in the multi-page editor's command stack
>> using CommandStack.execute(..).
> That's sounding problematic. I would expect appendAndExecute would
> only be used during the execute of the compound command itself.
>>
>> As you can see, the sub commands are executed initially, and also at
>> the end when the compound command is executed in the mpe's command stack.
> Sounds bad.
>> This works fine for SetCommand and AddCommand as they are idempotent
>> (AddCommand, for example, does not add duplicates when executed
>> again). However, RemoveCommand doesn't behave so. It throws an
>> exception during the second execution.
> It sounds like you should be using appendIfCanExecute.
>>
>> Is it not correct to execute sub commands, and then execute the
>> compound command again?
> No.
>> If I should not be executing the compound command at the end, how do I
>> add the compound command to the mpe's command stack?
> You should just append them.
>> I cannot use CompoundCommand.append(..) since I do need some of the
>> sub command executions to happen earlier, rather than wait till the
>> compound command to get executed.
> I don't understand this part. The things that should happen first
> should be at the beginning of the list of commands.
>>
>> Would I have to subclass RemoveCommand to make it idempotent, or maybe
>> subclass CompoundCommand and not allow it to be executed twice? Am I
>> missing something here?
> I'm not sure. I don't understand how executing commands outside of the
> execution of the parent command's execution on the command stack is
> necessary for the behavior you are trying to achieve. I'd expect the
> compound command to be a list of commands that can be executed in order
> to achieve the final desired result...
>>
>> Thanks,
>> Vasanth
Re: RemoveCommand multiple executions [message #416253 is a reply to message #416251] Wed, 23 January 2008 15:19 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vasanth,

Comments below.

Vasanth Velusamy wrote:
> Ed,
>
> Taking a step back,
>
> I have sub commands A, B, C, .. (combination of SetCommand,
> AddCommand, RemoveCommand) to be combined as one operation in a
> CompoundCommand (for consolidated undo/redo). I also want command A to
> be executed right away, when A is prepared (so cannot use
> CompoundCommand.append(), but will have to use
> CompoundCommand.appendAndExecute()).
Why? If you have this kind of need, you should defer creating A until
you are executing the compound command. After all, in general, when
commands are only being created they may never be executed.
>
> Now, finally, in order to add the CompoundCommand to the command stack
> in the multi-page editor, I have to execute the CompoundCommand in the
> context of the command stack (something like
> AdapterFactoryEditingDomain.getEditingDomainFor(myModel).get CommandStack().execute(myCompoundCommand)).
>
>
> So, should I be preparing my CompoundCommand a different way,
Yes.
> or,
> is there a way to add the already-executed CompoundCommand to the
> editing domain's command stack?
No.
> If there is such a way , I can do CompoundCommand.appendAndExecute(..)
> for all my sub-commands A, B, C and not have to execute the
> CompoundCommand again at the end.
>
> Hope that clarifies my issue.
Not so much. It sounds to me like you should have a specialized
compound command and as part of the specialized execute you'd invoke
your appendAndExecute for the A, B, and C commands you create at that
point in time. You'd also have to override prepare to simply return
true; presumably the command will always be executable...
>
> Thanks,
> Vasanth
>
>
> Ed Merks wrote:
>> Vasanth,
>>
>> Comments below.
>>
>>
>> Vasanth Velusamy wrote:
>>> I have a question/issue with the use of CompoundCommand in a
>>> multi-page editor (the mpe code-generated using the EMF framework).
>>>
>>> I am using a CompoundCommand to encapsulate several SetCommand /
>>> AddCommand / RemoveCommand. Each of these sub commands are appended
>>> and executed using CompoundCommand.appendAndExecute(..). Finally,
>>> this CompoundCommand is executed in the multi-page editor's command
>>> stack using CommandStack.execute(..).
>> That's sounding problematic. I would expect appendAndExecute would
>> only be used during the execute of the compound command itself.
>>>
>>> As you can see, the sub commands are executed initially, and also at
>>> the end when the compound command is executed in the mpe's command
>>> stack.
>> Sounds bad.
>>> This works fine for SetCommand and AddCommand as they are idempotent
>>> (AddCommand, for example, does not add duplicates when executed
>>> again). However, RemoveCommand doesn't behave so. It throws an
>>> exception during the second execution.
>> It sounds like you should be using appendIfCanExecute.
>>>
>>> Is it not correct to execute sub commands, and then execute the
>>> compound command again?
>> No.
>>> If I should not be executing the compound command at the end, how do
>>> I add the compound command to the mpe's command stack?
>> You should just append them.
>>> I cannot use CompoundCommand.append(..) since I do need some of the
>>> sub command executions to happen earlier, rather than wait till the
>>> compound command to get executed.
>> I don't understand this part. The things that should happen first
>> should be at the beginning of the list of commands.
>>>
>>> Would I have to subclass RemoveCommand to make it idempotent, or
>>> maybe subclass CompoundCommand and not allow it to be executed
>>> twice? Am I missing something here?
>> I'm not sure. I don't understand how executing commands outside of
>> the execution of the parent command's execution on the command stack
>> is necessary for the behavior you are trying to achieve. I'd expect
>> the compound command to be a list of commands that can be executed in
>> order to achieve the final desired result...
>>>
>>> Thanks,
>>> Vasanth


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ComposedAdapterFactory - documentation ?
Next Topic:Automatic Modification Tracking does not work
Goto Forum:
  


Current Time: Sat Apr 27 00:59:14 GMT 2024

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

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

Back to the top