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 CutAction extends Action { 46 49 ScenarioGUIEditor window; 50 ScenarioTreeViewer viewer; 51 static Category cat = Category.getInstance(CutAction.class.getName()); 52 58 public CutAction(ApplicationWindow w) { 59 cat.debug("-> constructor"); 60 this.window = (ScenarioGUIEditor) w; 61 this.setText("Cut@Ctrl+X"); 62 this.setToolTipText("Cut the selected node or selected text"); 63 try { 64 this.setImageDescriptor(ImageDescriptor.createFromURL(new URL ( 65 "file:" + FileName.CUT_ICON))); 66 } catch (Exception e) { 67 cat.warn("Unable to find cut icon file"); 68 } 69 } 70 71 public void run() { 72 cat.debug("-> run"); 73 switch (this.window.getEditorShowed()) { 74 case ScenarioGUIEditor.GUI_EDITOR : 75 this.viewer = this.window.getTreeViewer(); 76 Clipboard clipboard = this.viewer.getClipboard(); 77 ScenarioNode oldClipboard = (ScenarioNode) clipboard 79 .getContents(ScenarioTreeTransfer.getInstance()); 80 if (oldClipboard != null) { 81 TreeManager.getTreeManager(null).deleteBehaviorsTreeNode( 83 oldClipboard); 84 } 85 86 ScenarioNode node = this.viewer.getSelectedNode(); 87 if (node == null) 88 return; 89 ScenarioNode copy = TreeManager.getTreeManager(null) 91 .copyScenarioNode(node); 92 clipboard.setContents(new Object []{copy}, 93 new Transfer[]{ScenarioTreeTransfer.getInstance()}); 94 (TreeManager.getTreeManager(null)) 95 .deleteBehaviorsTreeNode(node); 96 this.viewer.refresh(); 97 this.window.getPasteNodeAction().setEnabled(true) ; 99 break; 100 case ScenarioGUIEditor.XML_EDITOR : 101 this.window.getStyledText().cut(); 102 break; 103 } 104 this.window.setScenarioSavedState(false) ; 106 } 107 } | Popular Tags |