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 import org.wsmostudio.bpmo.model.blockpatterns.BlockPatternNode;
34
35
36 /***
37 * A command to add a Shape to a ShapeDiagram.
38 * The command can be undone or redone.
39 * @author Elias Volanakis
40 */
41 public class BlockPatternCreateCommand
42 extends Command
43 {
44
45 /*** The new shape. */
46 private BlockPatternNode newPattern;
47 /*** ShapeDiagram to add to. */
48 private WorkflowEntitiesContainer parent;
49 /*** The bounds of the new Shape. */
50 private Rectangle bounds;
51
52 /***
53 * Create a command that will add a new Shape to a ShapesDiagram.
54 * @param newShape the new Shape that is to be added
55 * @param parent the ShapesDiagram that will hold the new element
56 * @param bounds the bounds of the new shape; the size can be (-1, -1) if not known
57 * @throws IllegalArgumentException if any parameter is null, or the request
58 * does not provide a new Shape instance
59 */
60 public BlockPatternCreateCommand(BlockPatternNode newPattern, WorkflowEntitiesContainer owner, Rectangle bounds) {
61 this.newPattern = newPattern;
62 this.parent = owner;
63 this.bounds = bounds;
64 setLabel("shape creation");
65 }
66
67 /***
68 * Can execute if all the necessary information has been provided.
69 * @see org.eclipse.gef.commands.Command#canExecute()
70 */
71 public boolean canExecute() {
72 return newPattern != null && parent != null && bounds != null;
73 }
74
75 public void execute() {
76 newPattern.setLocation(bounds.getLocation());
77 Dimension size = bounds.getSize();
78 if (size.width > 0 && size.height > 0)
79 newPattern.setSize(size.width, size.height);
80 redo();
81 }
82
83 public void redo() {
84 parent.addWorkflow(newPattern);
85 newPattern.firePropertyChange("location", null, null);
86 }
87
88 public void undo() {
89 parent.removeWorkflow(newPattern);
90 }
91
92 }
93
94
95
96
97
98
99
100
101
102
103
104