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.actions;
26  
27  
28  import java.util.List;
29  
30  import org.eclipse.gef.editparts.AbstractEditPart;
31  import org.eclipse.gef.ui.actions.SelectionAction;
32  import org.wsmostudio.bpmo.model.WorkflowEntitiesContainer;
33  import org.wsmostudio.bpmo.ui.editor.BpmoEditor;
34  import org.wsmostudio.bpmo.ui.editor.layout.BPMOModelLayouter;
35  
36  public class LayoutAction extends SelectionAction {
37  
38      public static final String ID = "Reset Layout";
39      
40      private BpmoEditor editor;
41      
42      public LayoutAction(BpmoEditor editor) {
43          super(editor);
44          this.editor = editor;
45      }
46  
47      public String getId() {
48          return ID;
49      }
50  
51      public String getText() {
52          return ID;
53      }
54      
55      protected boolean calculateEnabled() {
56          List<?> selection = getSelectedObjects();
57          if (selection.size() == 0) {
58              return true;
59          }
60          if (selection.size() == 1) {
61              return selection.get(0) instanceof AbstractEditPart
62                      && ((AbstractEditPart)selection.get(0)).getModel() instanceof WorkflowEntitiesContainer;
63          }
64          return false;
65      }    
66      public void run() {
67  
68          if (getSelectedObjects().size() == 1) {
69              BPMOModelLayouter.doLayout((WorkflowEntitiesContainer)
70                  ((AbstractEditPart)getSelectedObjects().get(0)).getModel());
71          }
72          else {
73              BPMOModelLayouter.doLayout(editor.getModel());
74          }
75          editor.getModel().notifyContentChanged();
76      }
77  }