1 13 14 package org.eclipse.jface.viewers; 15 16 import java.util.List ; 17 18 import org.eclipse.jface.viewers.CellEditor.LayoutData; 19 import org.eclipse.swt.custom.TreeEditor; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Item; 22 import org.eclipse.swt.widgets.Tree; 23 import org.eclipse.swt.widgets.TreeItem; 24 25 30 public class TreeViewerEditor extends ColumnViewerEditor { 31 34 private TreeEditor treeEditor; 35 36 private SWTFocusCellManager focusCellManager; 37 38 48 TreeViewerEditor(TreeViewer viewer, SWTFocusCellManager focusCellManager, 49 ColumnViewerEditorActivationStrategy editorActivationStrategy, 50 int feature) { 51 super(viewer, editorActivationStrategy, feature); 52 treeEditor = new TreeEditor(viewer.getTree()); 53 this.focusCellManager = focusCellManager; 54 } 55 56 76 public static void create(TreeViewer viewer, 77 SWTFocusCellManager focusCellManager, 78 ColumnViewerEditorActivationStrategy editorActivationStrategy, 79 int feature) { 80 TreeViewerEditor editor = new TreeViewerEditor(viewer, 81 focusCellManager, editorActivationStrategy, feature); 82 viewer.setColumnViewerEditor(editor); 83 if (focusCellManager != null) { 84 focusCellManager.init(); 85 } 86 } 87 88 105 public static void create(TreeViewer viewer, 106 ColumnViewerEditorActivationStrategy editorActivationStrategy, 107 int feature) { 108 create(viewer, null, editorActivationStrategy, feature); 109 } 110 111 protected void setEditor(Control w, Item item, int fColumnNumber) { 112 treeEditor.setEditor(w, (TreeItem) item, fColumnNumber); 113 } 114 115 protected void setLayoutData(LayoutData layoutData) { 116 treeEditor.grabHorizontal = layoutData.grabHorizontal; 117 treeEditor.horizontalAlignment = layoutData.horizontalAlignment; 118 treeEditor.minimumWidth = layoutData.minimumWidth; 119 } 120 121 public ViewerCell getFocusCell() { 122 if (focusCellManager != null) { 123 return focusCellManager.getFocusCell(); 124 } 125 126 return super.getFocusCell(); 127 } 128 129 protected void updateFocusCell(ViewerCell focusCell, 130 ColumnViewerEditorActivationEvent event) { 131 if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC 134 || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) { 135 136 List l = getViewer().getSelectionFromWidget(); 137 138 if (focusCellManager != null) { 139 focusCellManager.setFocusCell(focusCell); 140 } 141 142 if (!l.contains(focusCell.getElement())) { 143 getViewer().setSelection( 144 new TreeSelection(focusCell.getViewerRow() 145 .getTreePath()),true); 146 } 147 } 148 } 149 } 150 | Popular Tags |