Dynamically composing command [message #528797] |
Wed, 21 April 2010 15:35  |
Eclipse User |
|
|
|
Hi there,
Is there a way to dynamically compose commands while executing a gmf command?
In EMF's CompoundCommand class, there is an "appendAndExecute" method which does exactly that, but in GMF I can't find anything similar, it's a very important feature, are you going to support that?
Thanks,
Paul
|
|
|
Re: Dynamically composing command [message #528984 is a reply to message #528797] |
Thu, 22 April 2010 10:33  |
Eclipse User |
|
|
|
Also I've tried to implement my own version of CompoundCommand, it is used to keep a dynamic command list which is added during the execution of a command. Here is the code snipset:
public class CompoundCommand extends org.eclipse.gef.commands.CompoundCommand {
private List commandList = new ArrayList();
private Map dynamicMap = new HashMap();
private Command current;
...
public void execute() {
Command cmd;
List dynamicList;
for (int i = 0; i < commandList.size(); i++) {
current = (Command) commandList.get(i);
current.execute();
dynamicList = (List) dynamicMap.get(current);
if (dynamicList != null) {
for(int j = 0; j < dynamicList.size(); j++) {
cmd = (Command) dynamicList.get(j);
cmd.execute();
}
}
}
}
...
public void undo() {
Command cmd, cmd1;
List dynamicList;
for (int i = commandList.size() - 1; i >= 0; i--) {
cmd = (Command) commandList.get(i);
dynamicList = (List) dynamicMap.get(cmd);
if (dynamicList != null) {
for(int j = dynamicList.size() - 1; j >= 0; j--) {
cmd1 = (Command) dynamicList.get(j);
cmd1.undo();
}
}
cmd.undo();
}
}
public void redo() {
Command cmd, cmd1;
List dynamicList;
for (int i = 0; i < commandList.size(); i++) {
cmd = (Command) commandList.get(i);
cmd.redo();
dynamicList = (List) dynamicMap.get(cmd);
if (dynamicList != null) {
for(int j = 0; j < dynamicList.size(); j++) {
cmd1 = (Command) dynamicList.get(j);
cmd1.redo();
}
}
}
}
public void appendAndExecute(Command command) {
if (current != null && command.canExecute()) {
List dynamicList = (List) dynamicMap.get(current);
if (dynamicList == null) {
dynamicList = new ArrayList();
dynamicMap.put(current, dynamicList);
}
dynamicList.add(command);
}
}
But the problem is when GMF takes the CompoundCommand, it'll decompose it and create a new CompositeCommmand and then execute it without executing the logic in "execute" method of the CompoundCommand.
Do you think it's possible to achieve this feature through code customization from our side? Thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.03331 seconds