Home » Modeling » EMF » Undoable Set Command
Undoable Set Command [message #1314247] |
Fri, 25 April 2014 08:51 |
Ralph Gerbig Messages: 702 Registered: November 2009 |
Senior Member |
|
|
Hi,
I want to manipulate a model with a SetCommand that is undoable i.e. not appearing in "Edit -> Undo". To reach this I wrote an UndoableSetCommand [1] and use Transaction.OPTION_NO_UNDO.
Now I do have a command which is undoable and does not appear in "Edit -> Undo". The problem is that this seems to break the undo stack because all previous undo operations are not available anymore.
Does anyone have an idea on how to execute a command that is not available for undo but does allow to undo all previous commands?
Ralph
[1]
public class UndoableSetCommand extends SetCommand {
public UndoableSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value) {
super(domain, owner, feature, value);
}
public UndoableSetCommand(EditingDomain domain, EObject owner,
EStructuralFeature feature, Object value, int index) {
super(domain, owner, feature, value, index);
}
public static Command create(EditingDomain domain, final Object owner,
Object feature, Object value) {
return create(domain, owner, feature, value, CommandParameter.NO_INDEX);
}
public static Command create(EditingDomain domain, final Object owner, Object feature, Object value, int index){
Command setCommand = SetCommand.create(domain, owner, feature, value, index);
CompoundCommand result = new CompoundCommand(setCommand.getLabel()){
@Override
public boolean canUndo() {
return false;
}
};
result.append(setCommand);
return result;
}
@Override
public boolean doCanUndo() {
return false;
}
|
|
|
Re: Undoable Set Command [message #1314433 is a reply to message #1314247] |
Fri, 25 April 2014 11:19 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Ralph,
Comments below.
On 25/04/2014 10:51 AM, Ralph Gerbig wrote:
> Hi,
>
> I want to manipulate a model with a SetCommand that is undoable i.e.
> not appearing in "Edit -> Undo". To reach this I wrote an
> UndoableSetCommand [1] and use Transaction.OPTION_NO_UNDO.
>
> Now I do have a command which is undoable and does not appear in "Edit
> -> Undo". The problem is that this seems to break the undo stack
> because all previous undo operations are not available anymore.
>
> Does anyone have an idea on how to execute a command that is not
> available for undo but does allow to undo all previous commands?
That sounds logically inconceivable. The overall consistency of an undo
stack relies on the model being in the expected state during the undo
processing. If something modified the model in a way that's not
undoable, that expectation is no longer valid, and the behavior of undo
is undefined. How does this make sense?
>
> Ralph
>
> [1]
>
> public class UndoableSetCommand extends SetCommand {
>
> public UndoableSetCommand(EditingDomain domain, EObject owner,
> EStructuralFeature feature, Object value) {
> super(domain, owner, feature, value);
> }
>
> public UndoableSetCommand(EditingDomain domain, EObject owner,
> EStructuralFeature feature, Object value, int index) {
> super(domain, owner, feature, value, index);
> }
>
> public static Command create(EditingDomain domain, final Object
> owner,
> Object feature, Object value) {
> return create(domain, owner, feature, value,
> CommandParameter.NO_INDEX);
> }
>
> public static Command create(EditingDomain domain, final Object
> owner, Object feature, Object value, int index){
> Command setCommand = SetCommand.create(domain, owner, feature,
> value, index);
>
> CompoundCommand result = new
> CompoundCommand(setCommand.getLabel()){
> @Override
> public boolean canUndo() {
> return false;
> }
> };
>
> result.append(setCommand);
>
> return result;
> }
>
> @Override
> public boolean doCanUndo() {
> return false;
> }
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Undoable Set Command [message #1341404 is a reply to message #1314433] |
Thu, 08 May 2014 13:15 |
Ralph Gerbig Messages: 702 Registered: November 2009 |
Senior Member |
|
|
Hi,
you are right that for undos you do rely on the complete undo history. I however, do have parts in a model that are only maintained by my program which are never undone. Other parts of the model are changed by the user who wants to do an undo. I found a solution to my problem which is to start and commit transactions using a transactional editing domain.
Ralph
[Updated on: Thu, 08 May 2014 13:16] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Apr 20 02:49:29 GMT 2024
Powered by FUDForum. Page generated in 0.03124 seconds
|