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.dialogs.MessageDialog; 30 import org.eclipse.jface.resource.ImageDescriptor; 31 import org.eclipse.jface.window.ApplicationWindow; 32 import org.eclipse.swt.dnd.Clipboard; 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 PasteAction extends Action { 46 49 ScenarioGUIEditor window; 50 ScenarioTreeViewer viewer; 51 static Category cat = Category.getInstance(PasteAction.class.getName()); 52 58 public PasteAction(ApplicationWindow w) { 59 cat.debug("-> constructor"); 60 this.window = (ScenarioGUIEditor) w; 61 this.setText("Paste@Ctrl+V"); 62 this.setToolTipText("Paste as child of the selected node or the selected text"); 63 try { 64 this.setImageDescriptor(ImageDescriptor.createFromURL(new URL ( 65 "file:" + FileName.PASTE_ICON))); 66 } catch (Exception e) { 67 cat.warn("Unable to find paste 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 node = this.viewer.getSelectedNode(); 78 if (node == null) 79 node = (ScenarioNode) this.viewer.getInput(); 80 if (node == null) 82 return; 83 ScenarioNode child = (ScenarioNode) clipboard 84 .getContents(ScenarioTreeTransfer.getInstance()); 85 if (child == null) { 86 cat.warn("CHILD IS NULL !!!"); 87 return; 88 } 89 TreeManager treeManager = TreeManager.getTreeManager(null); 91 ScenarioNode copy = treeManager.copyScenarioNode(child); 92 if (treeManager.childrenAllowed(node).contains( 93 treeManager.getNodeType(child))) { 94 cat.warn("ADDING A " + treeManager.getNodeType(child) 95 + " ON A " + treeManager.getNodeType(node)); 96 node.addChild(copy); 97 this.viewer.expand(copy, true); 98 } else { 99 MessageDialog.openError(this.window.getShell(), 100 "Clipboard error", "Can not copy a \"" 101 + treeManager.getNodeType(child) 102 + "\" node into a \"" 103 + treeManager.getNodeType(node) 104 + "\" node !"); 105 treeManager.deleteBehaviorsTreeNode(copy); 107 } 108 this.viewer.refresh(); 109 break; 110 case ScenarioGUIEditor.XML_EDITOR : 111 cat.warn("XML EDITOR PASTE") ; 112 this.window.getStyledText().paste() ; 113 break; 114 default : 115 } 117 this.window.setScenarioSavedState(false) ; 119 } 120 } | Popular Tags |