comparison org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerEditor.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2007, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
11 * fixes in bug 198665, 200731
12 * Port to the D programming language:
13 * Frank Benoit <benoit@tionex.de>
14 *******************************************************************************/
15
16 module org.eclipse.jface.viewers.TableViewerEditor;
17
18 import org.eclipse.jface.viewers.ColumnViewerEditor;
19 import org.eclipse.jface.viewers.SWTFocusCellManager;
20 import org.eclipse.jface.viewers.CellEditor;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
23 import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
24 import org.eclipse.jface.viewers.ViewerCell;
25 import org.eclipse.jface.viewers.StructuredSelection;
26
27
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.custom.TableEditor;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.Item;
32 import org.eclipse.swt.widgets.Table;
33 import org.eclipse.swt.widgets.TableItem;
34
35 import java.lang.all;
36 import java.util.Set;
37
38 /**
39 * This is an editor-implementation for {@link Table}
40 *
41 * @since 3.3
42 *
43 */
44 public final class TableViewerEditor : ColumnViewerEditor {
45 /**
46 * This viewer's table editor.
47 */
48 private TableEditor tableEditor;
49
50 private SWTFocusCellManager focusCellManager;
51
52 /**
53 * @param viewer
54 * the viewer the editor is attached to
55 * @param focusCellManager
56 * the cell focus manager if one used or <code>null</code>
57 * @param editorActivationStrategy
58 * the strategy used to decide about the editor activation
59 * @param feature
60 * the feature mask
61 */
62 this(TableViewer viewer, SWTFocusCellManager focusCellManager,
63 ColumnViewerEditorActivationStrategy editorActivationStrategy,
64 int feature) {
65 super(viewer, editorActivationStrategy, feature);
66 tableEditor = new TableEditor(viewer.getTable());
67 this.focusCellManager = focusCellManager;
68 }
69
70 /**
71 * Create a customized editor with focusable cells
72 *
73 * @param viewer
74 * the viewer the editor is created for
75 * @param focusCellManager
76 * the cell focus manager if one needed else <code>null</code>
77 * @param editorActivationStrategy
78 * activation strategy to control if an editor activated
79 * @param feature
80 * bit mask controlling the editor
81 * <ul>
82 * <li>{@link ColumnViewerEditor#DEFAULT}</li>
83 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
84 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
85 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
86 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
87 * </ul>
88 * @see #create(TableViewer, ColumnViewerEditorActivationStrategy, int)
89 */
90 public static void create(TableViewer viewer,
91 SWTFocusCellManager focusCellManager,
92 ColumnViewerEditorActivationStrategy editorActivationStrategy,
93 int feature) {
94 TableViewerEditor editor = new TableViewerEditor(viewer,
95 focusCellManager, editorActivationStrategy, feature);
96 viewer.setColumnViewerEditor(editor);
97 if (focusCellManager !is null) {
98 focusCellManager.init();
99 }
100 }
101
102 /**
103 * Create a customized editor whose activation process is customized
104 *
105 * @param viewer
106 * the viewer the editor is created for
107 * @param editorActivationStrategy
108 * activation strategy to control if an editor activated
109 * @param feature
110 * bit mask controlling the editor
111 * <ul>
112 * <li>{@link ColumnViewerEditor#DEFAULT}</li>
113 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
114 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
115 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
116 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
117 * </ul>
118 */
119 public static void create(TableViewer viewer,
120 ColumnViewerEditorActivationStrategy editorActivationStrategy,
121 int feature) {
122 create(viewer, null, editorActivationStrategy, feature);
123 }
124
125 protected override void setEditor(Control w, Item item, int columnNumber) {
126 tableEditor.setEditor(w, cast(TableItem) item, columnNumber);
127 }
128
129 protected override void setLayoutData(LayoutData layoutData) {
130 tableEditor.grabHorizontal = layoutData.grabHorizontal;
131 tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
132 tableEditor.minimumWidth = layoutData.minimumWidth;
133 tableEditor.verticalAlignment = layoutData.verticalAlignment;
134
135 if( layoutData.minimumHeight !is SWT.DEFAULT ) {
136 tableEditor.minimumHeight = layoutData.minimumHeight;
137 }
138 }
139
140 public override ViewerCell getFocusCell() {
141 if (focusCellManager !is null) {
142 return focusCellManager.getFocusCell();
143 }
144
145 return super.getFocusCell();
146 }
147
148 protected override void updateFocusCell(ViewerCell focusCell,
149 ColumnViewerEditorActivationEvent event) {
150 // Update the focus cell when we activated the editor with these 2
151 // events
152 if (event.eventType is ColumnViewerEditorActivationEvent.PROGRAMMATIC
153 || event.eventType is ColumnViewerEditorActivationEvent.TRAVERSAL) {
154
155 auto l = getViewer().getSelectionFromWidget_package();
156
157 if (focusCellManager !is null) {
158 focusCellManager.setFocusCell(focusCell);
159 }
160
161 if (!l.contains(focusCell.getElement())) {
162 getViewer().setSelection(
163 new StructuredSelection(focusCell.getElement()),true);
164 }
165 }
166 }
167 }