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.ProcessNode;
34
35
36 public class ProcessCreateCommand
37 extends Command
38 {
39
40 /*** The new shape. */
41 private ProcessNode newProcess;
42 /*** ShapeDiagram to add to. */
43 private BpmoModel parent;
44 /*** The bounds of the new Shape. */
45 private Rectangle bounds;
46
47 /***
48 * Create a command that will add a new Shape to a ShapesDiagram.
49 * @param newShape the new Shape that is to be added
50 * @param parent the ShapesDiagram that will hold the new element
51 * @param bounds the bounds of the new shape; the size can be (-1, -1) if not known
52 * @throws IllegalArgumentException if any parameter is null, or the request
53 * does not provide a new Shape instance
54 */
55 public ProcessCreateCommand(ProcessNode newProcess, BpmoModel host, Rectangle bounds) {
56 this.newProcess = newProcess;
57 this.bounds = bounds;
58 this.parent = host;
59 setLabel("creation");
60 }
61
62 /***
63 * Can execute if all the necessary information has been provided.
64 * @see org.eclipse.gef.commands.Command#canExecute()
65 */
66 public boolean canExecute() {
67 return newProcess != null && parent != null && bounds != null;
68 }
69
70 public void execute() {
71 newProcess.setLocation(bounds.getLocation());
72 Dimension size = bounds.getSize();
73 if (size.width > 0 && size.height > 0)
74 newProcess.setSize(size.width, size.height);
75 redo();
76 }
77
78 public void redo() {
79 parent.addProcess(newProcess);
80 newProcess.firePropertyChange("location", null, null);
81 }
82
83 public void undo() {
84 parent.removeProcess(newProcess);
85 }
86
87 }
88