1 23 package org.objectweb.clif.scenario.util.isac.gui.action; 24 25 import java.net.URL ; 26 27 import org.apache.log4j.Category; 28 import org.eclipse.jface.action.Action; 29 import org.eclipse.jface.resource.ImageDescriptor; 30 import org.eclipse.jface.window.ApplicationWindow; 31 import org.eclipse.swt.dnd.Clipboard; 32 import org.eclipse.swt.dnd.Transfer; 33 import org.objectweb.clif.scenario.util.isac.FileName; 34 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 35 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer; 36 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeTransfer; 37 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 38 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 39 45 public class CopyAction extends Action { 46 49 ScenarioGUIEditor window; 50 ScenarioTreeViewer viewer; 51 static Category cat = Category.getInstance(CopyAction.class.getName()); 52 58 public CopyAction(ApplicationWindow w) { 59 cat.debug("-> constructor"); 60 this.window = (ScenarioGUIEditor) w; 61 this.setText("Copy@Ctrl+C"); 62 this.setToolTipText("Copy the selected node or selected text"); 63 try { 64 this.setImageDescriptor(ImageDescriptor.createFromURL(new URL ( 65 "file:" + FileName.COPY_ICON))); 66 } catch (Exception e) { 67 cat.warn("Unable to find copy icon file"); 68 } 69 } 70 71 public void run() { 72 cat.debug("-> run"); 73 74 switch (this.window.getEditorShowed()) { 75 case ScenarioGUIEditor.GUI_EDITOR : 76 this.viewer = this.window.getTreeViewer(); 77 Clipboard clipboard = this.viewer.getClipboard(); 78 ScenarioNode oldClipboard = (ScenarioNode) clipboard 80 .getContents(ScenarioTreeTransfer.getInstance()); 81 if (oldClipboard != null) { 82 TreeManager.getTreeManager(null).deleteBehaviorsTreeNode( 84 oldClipboard); 85 } 86 ScenarioNode node = this.viewer.getSelectedNode(); 87 if (node == null) 88 return; 89 cat.warn("SET THE CLIPBOARD : " + node); 90 ScenarioNode copy = TreeManager.getTreeManager(null) 92 .copyScenarioNode(node); 93 clipboard.setContents(new Object []{copy}, 94 new Transfer[]{ScenarioTreeTransfer.getInstance()}); 95 this.window.getPasteNodeAction().setEnabled(true) ; 97 break; 98 case ScenarioGUIEditor.XML_EDITOR : 99 cat.warn("XML EDITOR COPY") ; 100 this.window.getStyledText().copy(); 101 break; 102 default : 103 } 105 } 106 } | Popular Tags |