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.TableEditor; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Item; 22 import org.eclipse.swt.widgets.Table; 23 import org.eclipse.swt.widgets.TableItem; 24 25 31 public final class TableViewerEditor extends ColumnViewerEditor { 32 35 private TableEditor tableEditor; 36 37 private SWTFocusCellManager focusCellManager; 38 39 49 TableViewerEditor(TableViewer viewer, SWTFocusCellManager focusCellManager, 50 ColumnViewerEditorActivationStrategy editorActivationStrategy, 51 int feature) { 52 super(viewer, editorActivationStrategy, feature); 53 tableEditor = new TableEditor(viewer.getTable()); 54 this.focusCellManager = focusCellManager; 55 } 56 57 77 public static void create(TableViewer viewer, 78 SWTFocusCellManager focusCellManager, 79 ColumnViewerEditorActivationStrategy editorActivationStrategy, 80 int feature) { 81 TableViewerEditor editor = new TableViewerEditor(viewer, 82 focusCellManager, editorActivationStrategy, feature); 83 viewer.setColumnViewerEditor(editor); 84 if (focusCellManager != null) { 85 focusCellManager.init(); 86 } 87 } 88 89 106 public static void create(TableViewer viewer, 107 ColumnViewerEditorActivationStrategy editorActivationStrategy, 108 int feature) { 109 create(viewer, null, editorActivationStrategy, feature); 110 } 111 112 protected void setEditor(Control w, Item item, int columnNumber) { 113 tableEditor.setEditor(w, (TableItem) item, columnNumber); 114 } 115 116 protected void setLayoutData(LayoutData layoutData) { 117 tableEditor.grabHorizontal = layoutData.grabHorizontal; 118 tableEditor.horizontalAlignment = layoutData.horizontalAlignment; 119 tableEditor.minimumWidth = layoutData.minimumWidth; 120 } 121 122 public ViewerCell getFocusCell() { 123 if (focusCellManager != null) { 124 return focusCellManager.getFocusCell(); 125 } 126 127 return super.getFocusCell(); 128 } 129 130 protected void updateFocusCell(ViewerCell focusCell, 131 ColumnViewerEditorActivationEvent event) { 132 if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC 135 || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) { 136 137 List l = getViewer().getSelectionFromWidget(); 138 139 if (focusCellManager != null) { 140 focusCellManager.setFocusCell(focusCell); 141 } 142 143 if (!l.contains(focusCell.getElement())) { 144 getViewer().setSelection( 145 new StructuredSelection(focusCell.getElement()),true); 146 } 147 } 148 } 149 } 150 | Popular Tags |