1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
28 import java.util.List;
29
30 import org.eclipse.draw2d.geometry.Point;
31 import org.eclipse.gef.EditPart;
32 import org.eclipse.gef.ui.actions.SelectionAction;
33 import org.eclipse.ui.ISharedImages;
34 import org.eclipse.ui.IWorkbenchPart;
35 import org.eclipse.ui.actions.ActionFactory;
36 import org.wsmostudio.bpmo.model.*;
37 import org.wsmostudio.bpmo.ui.editor.ClipboardManager;
38
39 public class PasteAction extends SelectionAction {
40
41 public PasteAction(IWorkbenchPart part) {
42 super(part);
43 setId(ActionFactory.PASTE.getId());
44 setText("Paste");
45 ISharedImages sharedImages =
46 part.getSite().getWorkbenchWindow().getWorkbench().getSharedImages();
47 setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
48 setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
49 }
50
51 @Override
52 protected boolean calculateEnabled() {
53
54 ClipboardManager clipboard = ClipboardManager.getDefault();
55 if (false == clipboard.hasContent()) {
56 return false;
57 }
58 WorkflowEntitiesContainer target = getSelectedContainer();
59 if (target == null) {
60 return false;
61 }
62 return (target instanceof BpmoModel) == clipboard.checkContentType(ProcessNode.class);
63 }
64
65 public void run() {
66 WorkflowEntitiesContainer modelNode = getSelectedContainer();
67 if (modelNode == null) {
68 return;
69 }
70 WorkflowEntityNode newNode = ClipboardManager.getDefault().getContent();
71 if (newNode == null) {
72 return;
73 }
74 newNode.setLocation(new Point(5, 5));
75
76 if (modelNode instanceof BpmoModel
77 && newNode instanceof ProcessNode) {
78 ((BpmoModel)modelNode).addProcess((ProcessNode)newNode);
79 }
80 else {
81 modelNode.addWorkflow(newNode);
82 }
83 getSelectedPart().refresh();
84 }
85
86 private WorkflowEntitiesContainer getSelectedContainer() {
87 EditPart newHost = getSelectedPart();
88 if (newHost == null) {
89 return null;
90 }
91 if (false == newHost.getModel() instanceof WorkflowEntitiesContainer) {
92 return null;
93 }
94 return (WorkflowEntitiesContainer)newHost.getModel();
95 }
96
97 private EditPart getSelectedPart() {
98 List<?> targets = getSelectedObjects();
99 if (targets.size() == 0) {
100 return null;
101 }
102 return (EditPart)targets.get(0);
103 }
104
105 }