Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Dynamically composing command(Dynamic composing command while executing a command)
Dynamically composing command [message #528797] Wed, 21 April 2010 19:35 Go to next message
ps  is currently offline ps Friend
Messages: 16
Registered: July 2009
Junior Member
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 14:33 Go to previous message
ps  is currently offline ps Friend
Messages: 16
Registered: July 2009
Junior Member
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!
Previous Topic:constraint based mapping
Next Topic:GMF Restructure and GMP creation
Goto Forum:
  


Current Time: Tue Mar 19 02:01:52 GMT 2024

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

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

Back to the top