comparison dwtx/jface/viewers/TableViewerEditor.d @ 10:b6c35faf97c8

Viewers
author Frank Benoit <benoit@tionex.de>
date Mon, 31 Mar 2008 00:47:19 +0200
parents
children ea8ff534f622
comparison
equal deleted inserted replaced
9:6c14e54dfc11 10:b6c35faf97c8
1 /*******************************************************************************
2 * Copyright (c) 2007 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
12 * Port to the D programming language:
13 * Frank Benoit <benoit@tionex.de>
14 ******************************************************************************/
15
16 module dwtx.jface.viewers.TableViewerEditor;
17
18 import dwtx.jface.viewers.ColumnViewerEditor;
19 import dwtx.jface.viewers.SWTFocusCellManager;
20 import dwtx.jface.viewers.CellEditor;
21 import dwtx.jface.viewers.TableViewer;
22 import dwtx.jface.viewers.ColumnViewerEditorActivationStrategy;
23 import dwtx.jface.viewers.ColumnViewerEditorActivationEvent;
24 import dwtx.jface.viewers.ViewerCell;
25 import dwtx.jface.viewers.StructuredSelection;
26
27 // import tango.util.collection.model.Seq;
28
29 import dwt.custom.TableEditor;
30 import dwt.widgets.Control;
31 import dwt.widgets.Item;
32 import dwt.widgets.Table;
33 import dwt.widgets.TableItem;
34
35 import dwt.dwthelper.utils;
36
37 /**
38 * This is an editor-implementation for {@link Table}
39 *
40 * @since 3.3
41 *
42 */
43 public final class TableViewerEditor : ColumnViewerEditor {
44 /**
45 * This viewer's table editor.
46 */
47 private TableEditor tableEditor;
48
49 private SWTFocusCellManager focusCellManager;
50
51 /**
52 * @param viewer
53 * the viewer the editor is attached to
54 * @param focusCellManager
55 * the cell focus manager if one used or <code>null</code>
56 * @param editorActivationStrategy
57 * the strategy used to decide about the editor activation
58 * @param feature
59 * the feature mask
60 */
61 this(TableViewer viewer, SWTFocusCellManager focusCellManager,
62 ColumnViewerEditorActivationStrategy editorActivationStrategy,
63 int feature) {
64 super(viewer, editorActivationStrategy, feature);
65 tableEditor = new TableEditor(viewer.getTable());
66 this.focusCellManager = focusCellManager;
67 }
68
69 /**
70 * Create a customized editor with focusable cells
71 *
72 * @param viewer
73 * the viewer the editor is created for
74 * @param focusCellManager
75 * the cell focus manager if one needed else <code>null</code>
76 * @param editorActivationStrategy
77 * activation strategy to control if an editor activated
78 * @param feature
79 * bit mask controlling the editor
80 * <ul>
81 * <li>{@link ColumnViewerEditor#DEFAULT}</li>
82 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
83 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
84 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
85 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
86 * </ul>
87 * @see #create(TableViewer, ColumnViewerEditorActivationStrategy, int)
88 */
89 public static void create(TableViewer viewer,
90 SWTFocusCellManager focusCellManager,
91 ColumnViewerEditorActivationStrategy editorActivationStrategy,
92 int feature) {
93 TableViewerEditor editor = new TableViewerEditor(viewer,
94 focusCellManager, editorActivationStrategy, feature);
95 viewer.setColumnViewerEditor(editor);
96 if (focusCellManager !is null) {
97 focusCellManager.init();
98 }
99 }
100
101 /**
102 * Create a customized editor whose activation process is customized
103 *
104 * @param viewer
105 * the viewer the editor is created for
106 * @param editorActivationStrategy
107 * activation strategy to control if an editor activated
108 * @param feature
109 * bit mask controlling the editor
110 * <ul>
111 * <li>{@link ColumnViewerEditor#DEFAULT}</li>
112 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
113 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
114 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
115 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
116 * </ul>
117 */
118 public static void create(TableViewer viewer,
119 ColumnViewerEditorActivationStrategy editorActivationStrategy,
120 int feature) {
121 create(viewer, null, editorActivationStrategy, feature);
122 }
123
124 protected void setEditor(Control w, Item item, int columnNumber) {
125 tableEditor.setEditor(w, cast(TableItem) item, columnNumber);
126 }
127
128 protected void setLayoutData(CellEditor.LayoutData layoutData) {
129 tableEditor.grabHorizontal = layoutData.grabHorizontal;
130 tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
131 tableEditor.minimumWidth = layoutData.minimumWidth;
132 }
133
134 public ViewerCell getFocusCell() {
135 if (focusCellManager !is null) {
136 return focusCellManager.getFocusCell();
137 }
138
139 return super.getFocusCell();
140 }
141
142 protected void updateFocusCell(ViewerCell focusCell,
143 ColumnViewerEditorActivationEvent event) {
144 // Update the focus cell when we activated the editor with these 2
145 // events
146 if (event.eventType is ColumnViewerEditorActivationEvent.PROGRAMMATIC
147 || event.eventType is ColumnViewerEditorActivationEvent.TRAVERSAL) {
148
149 auto l = getViewer().getSelectionFromWidget_package();
150
151 if (focusCellManager !is null) {
152 focusCellManager.setFocusCell(focusCell);
153 }
154
155 if (!l.contains(focusCell.getElement())) {
156 getViewer().setSelection(
157 new StructuredSelection(focusCell.getElement()),true);
158 }
159 }
160 }
161 }