View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2007, Ontotext Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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