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  
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      /* (non-Javadoc)
70       * @see org.eclipse.gef.commands.Command#execute()
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   * $Log$
93   * Revision 1.5  2007/08/22 16:19:10  alex_simov
94   * no message
95   *
96   * Revision 1.4  2007/08/01 15:47:24  alex_simov
97   * ui model refactoring: classnames are suffixed by "Node" to avoid name
98   * clashes with BPMO-API entities
99   *
100  * Revision 1.3  2007/03/28 16:59:55  alex_simov
101  * no message
102  *
103  * Revision 1.2  2007/03/28 16:21:33  alex_simov
104  * no message
105  *
106  * Revision 1.1  2007/03/20 10:05:48  alex_simov
107  * SBP modeller initial version
108  *
109  */