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.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   * $Log$
96   * Revision 1.2  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.1  2007/03/28 16:21:33  alex_simov
101  * no message
102  *
103  *
104  */