1 23 package org.objectweb.clif.scenario.util.isac.gui.tree.dnd; 24 25 import java.util.Vector ; 26 27 import org.apache.log4j.Category; 28 import org.eclipse.jface.viewers.TreeViewer; 29 import org.eclipse.jface.viewers.ViewerDropAdapter; 30 import org.eclipse.swt.dnd.DND; 31 import org.eclipse.swt.dnd.TransferData; 32 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer; 33 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 34 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 35 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 36 42 public class ScenarioTreeDropAdapter extends ViewerDropAdapter { 43 static Category cat = Category.getInstance(ScenarioTreeDropAdapter.class.getName()); 44 private TreeManager treeManager; 45 46 public ScenarioTreeDropAdapter(TreeViewer viewer) { 47 super(viewer); 48 cat.debug("-> constructor") ; 49 this.treeManager = TreeManager.getTreeManager(null); 50 } 51 52 55 public boolean performDrop(Object data) { 56 cat.debug("-> performDrop") ; 57 ScenarioNode target = (ScenarioNode) getCurrentTarget(); 58 if (target == null) 59 target = (ScenarioNode) getViewer().getInput(); 60 ScenarioNode toDrop = (ScenarioNode) data; 61 TreeViewer viewer = (TreeViewer) getViewer(); 62 if (toDrop.contains(target)) 64 return false; 65 66 String typeToDrop = treeManager.getNodeType(toDrop); 68 Vector childrenAllowed = treeManager.childrenAllowed((ScenarioNode)target); 69 if (!childrenAllowed.contains(typeToDrop)) 70 return false; 71 72 ScenarioNode copy = treeManager.copyScenarioNode(toDrop) ; 74 target.addChild(copy) ; 76 77 ((ScenarioTreeViewer)viewer).expand(copy, true) ; 78 79 viewer.refresh(); 80 81 return true; 82 } 83 84 87 public boolean validateDrop(Object target, int op, TransferData type) { 88 cat.debug("-> validateDrop") ; 89 if (treeManager.getNodeType((ScenarioNode)target).equals(Node.PLUGINS)) 92 if (op == DND.DROP_MOVE) 93 return false ; 94 if (ScenarioTreeTransfer.getInstance().isSupportedType(type)) { 95 return true ; 96 } 97 return false; 98 } 99 100 } | Popular Tags |