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