1 23 package org.objectweb.clif.scenario.util.isac.gui.tree; 24 25 import org.apache.log4j.Category; 26 import org.eclipse.jface.action.MenuManager; 27 import org.eclipse.jface.viewers.DoubleClickEvent; 28 import org.eclipse.jface.viewers.IDoubleClickListener; 29 import org.eclipse.jface.viewers.ISelectionChangedListener; 30 import org.eclipse.jface.viewers.IStructuredSelection; 31 import org.eclipse.jface.viewers.SelectionChangedEvent; 32 import org.eclipse.jface.viewers.TreeViewer; 33 import org.eclipse.jface.window.Window; 34 import org.eclipse.swt.dnd.Clipboard; 35 import org.eclipse.swt.dnd.DND; 36 import org.eclipse.swt.dnd.Transfer; 37 import org.eclipse.swt.events.FocusEvent; 38 import org.eclipse.swt.events.FocusListener; 39 import org.eclipse.swt.events.MouseEvent; 40 import org.eclipse.swt.events.MouseListener; 41 import org.eclipse.swt.widgets.Composite; 42 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 43 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeDragListener; 44 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeDropAdapter; 45 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeTransfer; 46 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 47 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 48 49 55 public class ScenarioTreeViewer extends TreeViewer 56 implements 57 ISelectionChangedListener, 58 IDoubleClickListener, 59 FocusListener, 60 MouseListener { 61 static Category cat = Category.getInstance(ScenarioTreeViewer.class.getName()); 62 private TreeManager treeManager; 63 private ScenarioGUIEditor window; 64 private Clipboard clipboard; 65 private ScenarioNode lastNodeSelected ; 66 67 76 public ScenarioTreeViewer(Composite c, int style, Window w) { 77 super(c, style); 78 cat.debug("-> constructor") ; 79 this.window = (ScenarioGUIEditor) w; 80 81 this.treeManager = TreeManager.getTreeManager(null); 83 84 this.setContentProvider(new ScenarioTreeContentProvider()); 85 this.setLabelProvider(new ScenarioTreeLabelProvider()); 86 this.setInput(this.treeManager.getTree()); 87 88 this.addSelectionChangedListener(this); 89 this.addDoubleClickListener(this); 90 this.getTree().addMouseListener(this) ; 91 Transfer[] types = new Transfer[]{ScenarioTreeTransfer.getInstance()}; 92 int operations = DND.DROP_MOVE | DND.DROP_COPY; 93 this.addDragSupport(operations, types, new ScenarioTreeDragListener( 94 this)); 95 this.addDropSupport(operations, types, 96 new ScenarioTreeDropAdapter(this)); 97 this.clipboard = new Clipboard(c.getDisplay()); 99 } 100 101 105 public void setPopUpMenu(MenuManager menuManager) { 106 this.getTree().setMenu(menuManager.createContextMenu(this.getTree())) ; 107 } 108 109 114 public Clipboard getClipboard() { 115 cat.debug("-> getClipboard") ; 116 return this.clipboard; 117 } 118 119 124 public ScenarioNode getSelectedNode() { 125 cat.debug("-> getSelectedNode") ; 126 IStructuredSelection selection = (IStructuredSelection) super 127 .getSelection(); 128 if (selection != null) { 129 return (ScenarioNode) selection.getFirstElement(); 130 } 131 return (ScenarioNode) this.getInput(); 132 } 133 134 139 public void selectionChanged(SelectionChangedEvent event) { 140 cat.debug("-> selectionChanged") ; 141 ScenarioNode node = getSelectedNode(); 142 if (node == lastNodeSelected) 143 return ; 144 this.window.notifySelectionChanged(node); 145 lastNodeSelected = node ; 146 } 147 148 153 public void doubleClick(DoubleClickEvent event) { 154 cat.debug("-> doubleClick") ; 155 IStructuredSelection selection = (IStructuredSelection) event 156 .getSelection(); 157 158 Object selected_element = selection.getFirstElement(); 159 this.setExpandedState(selected_element, !this 160 .getExpandedState(selected_element)); 161 } 162 163 168 public void expand(Object element, boolean state) { 169 cat.debug("-> expand") ; 170 ScenarioNode parent = ((ScenarioNode) element).getParent(); 171 if (parent != null) 172 expand(parent, state); 173 this.setExpandedState(element, state); 174 } 175 176 179 public void focusGained(FocusEvent arg0) { 180 cat.warn("Gain the focus on treeViwer") ; 181 } 182 185 public void focusLost(FocusEvent arg0) { 186 cat.warn("Lost the focus on treeViwer") ; 187 } 188 189 192 public void mouseDoubleClick(MouseEvent arg0) { 193 this.getTree().setFocus() ; 194 } 195 198 public void mouseDown(MouseEvent arg0) { 199 } 200 203 public void mouseUp(MouseEvent arg0) { 204 this.getTree().setFocus() ; 205 } 206 } | Popular Tags |