View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2008, 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-2008</p>
22   * <p>Company: Ontotext Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.bpmo.ui.actions;
26  
27  import org.eclipse.gef.EditPart;
28  import org.eclipse.gef.ui.actions.SelectionAction;
29  import org.eclipse.ui.ISharedImages;
30  import org.eclipse.ui.IWorkbenchPart;
31  import org.eclipse.ui.actions.ActionFactory;
32  import org.wsmostudio.bpmo.model.WorkflowEntityNode;
33  import org.wsmostudio.bpmo.ui.editor.ClipboardManager;
34  
35  public class CopyAction extends SelectionAction {
36  
37      public CopyAction(IWorkbenchPart part) {
38          super(part);
39          setId(ActionFactory.COPY.getId());
40          setText("&Copy");
41          ISharedImages sharedImages = 
42              part.getSite().getWorkbenchWindow().getWorkbench().getSharedImages();
43          setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
44          setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
45      }
46  
47      @Override
48      protected boolean calculateEnabled() {
49          return findSelectedNode() != null;
50      }
51      
52      public void run() {
53          if (calculateEnabled() == false) { // double protection
54              return;
55          }
56          ClipboardManager.getDefault().setContent(findSelectedNode());
57      }
58      
59      private WorkflowEntityNode findSelectedNode() {
60          for(Object sel : getSelectedObjects()) {
61              if (sel instanceof EditPart 
62                      && ((EditPart)sel).getModel() instanceof WorkflowEntityNode) {
63                  return (WorkflowEntityNode)((EditPart)sel).getModel();
64              }
65          }
66          return null;
67      }
68  
69  }