Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CompoundCommand.appendAndExecute question
CompoundCommand.appendAndExecute question [message #1714456] Thu, 12 November 2015 18:37 Go to next message
Celine Bensoussan is currently offline Celine BensoussanFriend
Messages: 4
Registered: November 2015
Junior Member
Hi,

I have an issue understanding how appendAndExecute() works.
It seems that if I appendAndExecute a RemoveCommand it will be successfully execute once, and then it will be executed again when performing the compoundCommand.execute() where it will fail. Should it know during the execute that this command has already been executed and should not be executed again ?

private CompoundCommand deleteFeatureSelection(AssociationEnd associationEnd, EditingDomain editingDomain) {
    CompoundCommand compoundCommand = new CompoundCommand();
    
    //When this is just an append, it works nicely but I need it to be executed before createFeatureSelection
   compoundCommand.appendAndExecute(RemoveCommand.create(editingDomain, associationEnd.getFeatureSelection()));
    return compoundCommand;
}


public void doSomething(AssociationEnd associationEnd) {
    EditingDomain editingDomain = EMFEditUtil.getEditingDomain(associationEnd);
    CompoundCommand compoundCommand = new CompoundCommand();

    compoundCommand.append(deleteFeatureSelection(associationEnd, editingDomain));
    
    //This createFeatureSelection needs all command from deleteFeatureSelection to have been executed
    compoundCommand.append(createFeatureSelection(associationEnd, editingDomain));

    compoundCommand.execute();
}
Re: CompoundCommand.appendAndExecute question [message #1714625 is a reply to message #1714456] Sat, 14 November 2015 07:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Celine,



On 13/11/2015 4:25 PM, Celine Bensoussan wrote:
> Hi,
>
> I have an issue understanding how appendAndExecute() works.
> It seems that if I appendAndExecute a RemoveCommand it will be
> successfully execute once, and then it will be executed again when
> performing the compoundCommand.execute() where it will fail. Should it
> know during the execute that this command has already been executed
> and should not be executed again ?
The Javadoc shows it being using during the execute() of command.
>
> private CompoundCommand deleteFeatureSelection(AssociationEnd
> associationEnd, EditingDomain editingDomain) {
> CompoundCommand compoundCommand = new CompoundCommand();
> //When this is just an append, it works nicely but I need it to
> be executed before createFeatureSelection
> compoundCommand.appendAndExecute(RemoveCommand.create(editingDomain,
> associationEnd.getFeatureSelection()));
> return compoundCommand;
> }
This isn't using a command stack. This isn't how it should be used.
>
>
>
> public void doSomething(AssociationEnd associationEnd) {
> EditingDomain editingDomain =
> EMFEditUtil.getEditingDomain(associationEnd);
> CompoundCommand compoundCommand = new CompoundCommand();
>
> compoundCommand.append(deleteFeatureSelection(associationEnd,
> editingDomain));
> //This createFeatureSelection needs all command from
> deleteFeatureSelection to have been executed
> compoundCommand.append(createFeatureSelection(associationEnd,
> editingDomain));
>
> compoundCommand.execute();
> }
This also isn't using a command stack. Is the problem you're trying to
solve that the createFeatureSelection command isn't enabled (canExecute
is false) unless the deleteFeatureSelection is already executed? Is the
containment reference to it single valued such that a SetCommand can
simply replace the old with the new?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: CompoundCommand.appendAndExecute question [message #1714688 is a reply to message #1714625] Sun, 15 November 2015 21:42 Go to previous messageGo to next message
Celine Bensoussan is currently offline Celine BensoussanFriend
Messages: 4
Registered: November 2015
Junior Member
The commands from createFeatureSelection can execute fine after the commands of deleteFeatureSelection but I do not get the expected result.
In order to prepare the correct commands in the createFeatureSelection, the remove from the deleteFeatureSelection needs to have already been executed. The delete and create operations do a lot more than just setting a value that could be simplified to a SetCommand.

When you say this is not how it should be used, could you give me an example of what would be the correct way of using it ?
Re: CompoundCommand.appendAndExecute question [message #1714696 is a reply to message #1714688] Mon, 16 November 2015 05:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Did you read the Javadoc for
org.eclipse.emf.common.command.CompoundCommand.appendAndExecute(Command)? In
your case you could create a specialized CompoundCommand, append the
delete feature selection command to it and specialize the execute method
of the specialized compound command to appendAndExecute the create
feature selection command. A command should not be executed directly;
it should be executed by the command stack and during that execution you
can using this like appendAndExecute.

On 15/11/2015 10:42 PM, Celine Bensoussan wrote:
> The commands from createFeatureSelection can execute fine after the
> commands of deleteFeatureSelection but I do not get the expected result.
> In order to prepare the correct commands in the
> createFeatureSelection, the remove from the deleteFeatureSelection
> needs to have already been executed. The delete and create operations
> do a lot more than just setting a value that could be simplified to a
> SetCommand.
>
> When you say this is not how it should be used, could you give me an
> example of what would be the correct way of using it ?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: CompoundCommand.appendAndExecute question [message #1715040 is a reply to message #1714696] Wed, 18 November 2015 17:31 Go to previous messageGo to next message
Celine Bensoussan is currently offline Celine BensoussanFriend
Messages: 4
Registered: November 2015
Junior Member
I think I understand but I am still wondering if that answers the problem in the case where
I need delete feature selection to have been executed even before the create feature selection
prepares its commands.

It sounds like I could create a specialized compound command for the delete feature selection
with a execute method that executes the delete and the prepares and executes the commands
for create feature selection.
Would that make sense at all ?

EDIT: Nevermind, I just understood what you were suggesting Smile Thank you !

[Updated on: Wed, 18 November 2015 23:08]

Report message to a moderator

Re: CompoundCommand.appendAndExecute question [message #1715084 is a reply to message #1715040] Thu, 19 November 2015 06:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Celine,

Yes, the compound command could have the delete command already in the
command list, and when execute is called, it can call super and then can
do appendAndExecute of the create feature selection command so that it's
prepared after the execution of the delete is completed.

On 18/11/2015 6:31 PM, Celine Bensoussan wrote:
> I think I understand but I am still wondering if that answers the
> problem in the case where I need delete feature selection to have been
> executed even before the create feature selection prepares its commands.
>
> It sounds like I could create a specialized compound command for the
> delete feature selection
> with a execute method that executes the delete and the prepares and
> executes the commands for create feature selection.
> Would that make sense at all ?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: CompoundCommand.appendAndExecute question [message #1715255 is a reply to message #1715084] Fri, 20 November 2015 15:32 Go to previous message
Celine Bensoussan is currently offline Celine BensoussanFriend
Messages: 4
Registered: November 2015
Junior Member
Thank you very much for your help Ed !
Previous Topic:ArrayIndexOutOfBoundsException during XMI serialization with ASCII encoding
Next Topic:Best Practice: Get EEnumLiteral from Enumerator
Goto Forum:
  


Current Time: Thu Apr 18 08:41:30 GMT 2024

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

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

Back to the top