1 17 package org.eclipse.emf.common.ui.celleditor; 18 19 20 import org.eclipse.swt.custom.TreeEditor; 21 import org.eclipse.swt.events.KeyEvent; 22 import org.eclipse.swt.events.KeyListener; 23 import org.eclipse.swt.events.MouseEvent; 24 import org.eclipse.swt.events.MouseListener; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.events.SelectionListener; 27 import org.eclipse.swt.graphics.Point; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Tree; 30 import org.eclipse.swt.widgets.TreeItem; 31 32 33 39 public abstract class ExtendedTreeEditor extends TreeEditor implements SelectionListener, MouseListener, KeyListener 40 { 41 protected Tree tree; 42 protected TreeItem selectedTreeItem; 43 protected TreeItem editTreeItem; 44 45 public ExtendedTreeEditor(Tree tree) 46 { 47 super(tree); 48 this.tree = tree; 49 tree.addKeyListener(this); 50 tree.addMouseListener(this); 51 tree.addSelectionListener(this); 52 } 53 54 public void mouseDoubleClick(MouseEvent event) 55 { 56 } 57 58 public void mouseDown(MouseEvent event) 59 { 60 if (event.button == 1) 61 { 62 TreeItem treeItem = tree.getItem(new Point(event.x, event.y)); 63 editTreeItem = treeItem == selectedTreeItem ? treeItem : null; 64 } 65 } 66 67 public void mouseUp(MouseEvent event) 68 { 69 if (event.button == 1) 70 { 71 TreeItem treeItem = tree.getItem(new Point(event.x, event.y)); 72 if (editTreeItem == treeItem && editTreeItem != null) 73 { 74 editTreeItem = null; 75 editItem(treeItem); 76 } 77 } 78 } 79 80 public void widgetDefaultSelected(SelectionEvent event) 81 { 82 widgetSelected(event); 83 } 84 85 public void widgetSelected(SelectionEvent event) 86 { 87 Control control = getEditor(); 88 if (control != null && !control.isDisposed()) 89 { 90 setEditor(null); 91 control.dispose(); 92 } 93 94 TreeItem [] selection = tree.getSelection(); 95 selectedTreeItem = selection.length == 1 ? selection[0] : null; 96 } 97 98 public void keyPressed(KeyEvent event) 99 { 100 } 101 102 public void keyReleased(KeyEvent event) 103 { 104 if (event.character == ' ' && selectedTreeItem != null) 105 { 106 editItem(selectedTreeItem); 107 } 108 } 109 110 protected abstract void editItem(TreeItem treeItem); 111 } 112 | Popular Tags |