1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2007</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.bpmo.ui.editor.command;
26
27 import org.eclipse.draw2d.geometry.Dimension;
28 import org.eclipse.draw2d.geometry.Rectangle;
29
30 import org.eclipse.gef.commands.Command;
31
32 import org.wsmostudio.bpmo.model.*;
33
34
35 public class WorkflowEntityCreateCommand
36 extends Command
37 {
38
39 /*** The new shape. */
40 private WorkflowEntityNode newStart;
41 /*** ShapeDiagram to add to. */
42 private WorkflowEntitiesContainer parent;
43 /*** The bounds of the new Shape. */
44 private Rectangle bounds;
45
46 /***
47 * Create a command that will add a new Shape to a ShapesDiagram.
48 * @param newShape the new Shape that is to be added
49 * @param parent the ShapesDiagram that will hold the new element
50 * @param bounds the bounds of the new shape; the size can be (-1, -1) if not known
51 * @throws IllegalArgumentException if any parameter is null, or the request
52 * does not provide a new Shape instance
53 */
54 public WorkflowEntityCreateCommand(WorkflowEntityNode newTask, WorkflowEntitiesContainer host, Rectangle bounds) {
55 this.newStart = newTask;
56 this.bounds = bounds;
57 this.parent = host;
58 setLabel("creation");
59 }
60
61 /***
62 * Can execute if all the necessary information has been provided.
63 * @see org.eclipse.gef.commands.Command#canExecute()
64 */
65 public boolean canExecute() {
66 return newStart != null && parent != null && bounds != null;
67 }
68
69
70
71
72 public void execute() {
73 newStart.setLocation(bounds.getLocation());
74 Dimension size = bounds.getSize();
75 if (size.width > 0 && size.height > 0)
76 newStart.setSize(size.width, size.height);
77 redo();
78 }
79
80 public void redo() {
81 parent.addWorkflow(newStart);
82 newStart.firePropertyChange("location", null, null);
83 }
84
85 public void undo() {
86 parent.removeWorkflow(newStart);
87 }
88
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109