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: * AddCommand
12: * This command adds a new child to a given parent
13: */
14: public class AddCommand extends Command {
15:
16: private FlowElement child;
17: private CompositeOrOneChild parent;
18:
19: /**
20: * @see org.eclipse.gef.commands.Command#execute()
21: */
22: public void execute() {
23: if ((parent instanceof ActivityDiagram)
24: && (!(child instanceof WorkflowElement))) {
25: MessageDialog.openInformation(null, "Alert",
26: "The first element must be a Flow Element ");
27: } else if ((!(parent instanceof ActivityDiagram))
28: && child instanceof WorkflowElement) {
29: MessageDialog.openInformation(null, "Alert",
30: "A workflow has already been defined");
31: } else {
32: parent.addChild(child);
33:
34: }
35: }
36:
37: /**
38: * Returns the CompositeOrOneChild that is the parent
39: * @return the parent
40: */
41: public CompositeOrOneChild getParent() {
42: return parent;
43: }
44:
45: /**
46: * Sets the child to the passed FlowElement
47: * @param subpart the child
48: */
49: public void setChild(FlowElement newChild) {
50: child = newChild;
51: }
52:
53: /**
54: * Sets the parent to the passed StructuredActiivty
55: * @param newParent the parent
56: */
57: public void setParent(CompositeOrOneChild newParent) {
58: parent = newParent;
59: }
60:
61: /**
62: * @see org.eclipse.gef.commands.Command#undo()
63: */
64: public void undo() {
65: parent.removeChild(child);
66: }
67:
68: }
|