01: package org.openwfe.gpe.model.commands;
02:
03: import org.eclipse.gef.commands.Command;
04: import org.eclipse.jface.dialogs.MessageDialog;
05: import org.openwfe.gpe.model.ActivityDiagram;
06: import org.openwfe.gpe.model.CompositeOrOneChild;
07: import org.openwfe.gpe.model.FlowElement;
08: import org.openwfe.gpe.model.WorkflowElement;
09:
10: /**
11: * @author christelle
12: */
13: public class CreateCommand extends Command {
14: private CompositeOrOneChild parent;
15: private FlowElement child;
16: private int index = -1;
17:
18: /**
19: * @see org.eclipse.gef.commands.Command#execute()
20: */
21: public void execute() {
22: if (parent instanceof ActivityDiagram
23: && (!(child instanceof WorkflowElement))) {
24: MessageDialog.openInformation(null, "Alert",
25: "The first element must be a Flow Element");
26: } else if ((!(parent instanceof ActivityDiagram))
27: && child instanceof WorkflowElement) {
28: MessageDialog.openInformation(null, "Alert",
29: "A workflow has already been defined");
30: } else {
31: if (index > 0)
32: parent.addChild(child, index);
33: else
34: parent.addChild(child);
35: }
36: }
37:
38: /**
39: * Sets the index to the passed value
40: * @param i the index
41: */
42: public void setIndex(int i) {
43: index = i;
44: }
45:
46: /**
47: * Sets the parent ActivityDiagram
48: * @param sa the parent
49: */
50: public void setParent(CompositeOrOneChild sa) {
51: parent = sa;
52: }
53:
54: /**
55: * Sets the FlowElement to create
56: * @param activity the FlowElement to create
57: */
58: public void setChild(FlowElement activity) {
59: child = activity;
60: child.setName(activity.getName().substring(0, 1).toUpperCase()
61: + activity.getName().substring(1));
62: }
63:
64: /**
65: * @see org.eclipse.gef.commands.Command#undo()
66: */
67: public void undo() {
68: parent.removeChild(child);
69: }
70:
71: }
|