10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 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> - bug 153993
|
|
11 * Port to the D programming language:
|
|
12 * Frank Benoit <benoit@tionex.de>
|
|
13 *******************************************************************************/
|
|
14
|
|
15 module dwtx.jface.viewers.TableTreeViewer;
|
|
16
|
|
17 import dwtx.jface.viewers.AbstractTreeViewer;
|
|
18 import dwtx.jface.viewers.CellEditor;
|
|
19 import dwtx.jface.viewers.ICellEditorListener;
|
|
20 import dwtx.jface.viewers.ICellModifier;
|
|
21 import dwtx.jface.viewers.ColumnViewer;
|
|
22 import dwtx.jface.viewers.IBaseLabelProvider;
|
|
23 import dwtx.jface.viewers.StructuredSelection;
|
|
24 import dwtx.jface.viewers.Viewer;
|
|
25 import dwtx.jface.viewers.DoubleClickEvent;
|
|
26 import dwtx.jface.viewers.OpenEvent;
|
|
27 import dwtx.jface.viewers.ITableLabelProvider;
|
|
28 import dwtx.jface.viewers.ViewerLabel;
|
|
29
|
|
30 import tango.util.collection.model.SeqView;
|
|
31
|
|
32 import dwt.DWT;
|
|
33 import dwt.custom.TableTree;
|
|
34 import dwt.custom.TableTreeEditor;
|
|
35 import dwt.custom.TableTreeItem;
|
|
36 import dwt.events.FocusAdapter;
|
|
37 import dwt.events.FocusEvent;
|
|
38 import dwt.events.FocusListener;
|
|
39 import dwt.events.MouseAdapter;
|
|
40 import dwt.events.MouseEvent;
|
|
41 import dwt.events.MouseListener;
|
|
42 import dwt.events.TreeListener;
|
|
43 import dwt.graphics.Image;
|
|
44 import dwt.graphics.Point;
|
|
45 import dwt.graphics.Rectangle;
|
|
46 import dwt.widgets.Composite;
|
|
47 import dwt.widgets.Control;
|
|
48 import dwt.widgets.Display;
|
|
49 import dwt.widgets.Item;
|
|
50 import dwt.widgets.Widget;
|
|
51
|
|
52 import dwt.dwthelper.utils;
|
|
53
|
|
54 /**
|
|
55 * A concrete viewer based on a DWT <code>TableTree</code> control.
|
|
56 * <p>
|
|
57 * This class is not intended to be subclassed outside the viewer framework. It
|
|
58 * is designed to be instantiated with a pre-existing DWT table tree control and
|
|
59 * configured with a domain-specific content provider, label provider, element
|
|
60 * filter (optional), and element sorter (optional).
|
|
61 * </p>
|
|
62 * <p>
|
|
63 * Content providers for table tree viewers must implement the
|
|
64 * <code>ITreeContentProvider</code> interface.
|
|
65 * </p>
|
|
66 * <p>
|
|
67 * Label providers for table tree viewers must implement either the
|
|
68 * <code>ITableLabelProvider</code> or the <code>ILabelProvider</code>
|
|
69 * interface (see <code>TableTreeViewer.setLabelProvider</code> for more
|
|
70 * details).
|
|
71 * </p>
|
|
72 *
|
|
73 * @deprecated As of 3.1 use {@link TreeViewer} instead
|
|
74 */
|
|
75 public class TableTreeViewer : AbstractTreeViewer {
|
|
76 alias AbstractTreeViewer.setSelection setSelection;
|
|
77 /**
|
|
78 * Internal table viewer implementation.
|
|
79 */
|
|
80 private TableTreeEditorImpl tableEditorImpl;
|
|
81
|
|
82 /**
|
|
83 * This viewer's table tree control.
|
|
84 */
|
|
85 private TableTree tableTree;
|
|
86
|
|
87 /**
|
|
88 * This viewer's table tree editor.
|
|
89 */
|
|
90 private TableTreeEditor tableTreeEditor;
|
|
91
|
|
92 /**
|
|
93 * Copied from original TableEditorImpl and moved here since refactoring
|
|
94 * completely wiped out the original implementation in 3.3
|
|
95 *
|
|
96 * @since 3.1
|
|
97 */
|
|
98 class TableTreeEditorImpl {
|
|
99
|
|
100 private CellEditor cellEditor;
|
|
101
|
|
102 private CellEditor[] cellEditors;
|
|
103
|
|
104 private ICellModifier cellModifier;
|
|
105
|
|
106 private String[] columnProperties;
|
|
107
|
|
108 private Item tableItem;
|
|
109
|
|
110 private int columnNumber;
|
|
111
|
|
112 private ICellEditorListener cellEditorListener;
|
|
113
|
|
114 private FocusListener focusListener;
|
|
115
|
|
116 private MouseListener mouseListener;
|
|
117
|
|
118 private int doubleClickExpirationTime;
|
|
119
|
|
120 private ColumnViewer viewer;
|
|
121
|
|
122 private this(ColumnViewer viewer) {
|
|
123 this.viewer = viewer;
|
|
124 initCellEditorListener();
|
|
125 }
|
|
126
|
|
127 /**
|
|
128 * Returns this <code>TableViewerImpl</code> viewer
|
|
129 *
|
|
130 * @return the viewer
|
|
131 */
|
|
132 public ColumnViewer getViewer() {
|
|
133 return viewer;
|
|
134 }
|
|
135
|
|
136 private void activateCellEditor() {
|
|
137 if( cellEditors !is null ) {
|
|
138 if( cellEditors[columnNumber] !is null && cellModifier !is null ) {
|
|
139 Object element = tableItem.getData();
|
|
140 String property = columnProperties[columnNumber];
|
|
141
|
|
142 if( cellModifier.canModify(element, property) ) {
|
|
143 cellEditor = cellEditors[columnNumber];
|
|
144
|
|
145 cellEditor.addListener(cellEditorListener);
|
|
146
|
|
147 Object value = cellModifier.getValue(element, property);
|
|
148 cellEditor.setValue(value);
|
|
149 // Tricky flow of control here:
|
|
150 // activate() can trigger callback to cellEditorListener
|
|
151 // which will clear cellEditor
|
|
152 // so must get control first, but must still call activate()
|
|
153 // even if there is no control.
|
|
154 final Control control = cellEditor.getControl();
|
|
155 cellEditor.activate();
|
|
156 if (control is null) {
|
|
157 return;
|
|
158 }
|
|
159 setLayoutData(cellEditor.getLayoutData());
|
|
160 setEditor(control, tableItem, columnNumber);
|
|
161 cellEditor.setFocus();
|
|
162 if (focusListener is null) {
|
|
163 focusListener = new class FocusAdapter {
|
|
164 public void focusLost(FocusEvent e) {
|
|
165 applyEditorValue();
|
|
166 }
|
|
167 };
|
|
168 }
|
|
169 control.addFocusListener(focusListener);
|
|
170 mouseListener = new class MouseAdapter {
|
|
171 Control control_;
|
|
172 this(){
|
|
173 control_=control;
|
|
174 }
|
|
175 public void mouseDown(MouseEvent e) {
|
|
176 // time wrap?
|
|
177 // check for expiration of doubleClickTime
|
|
178 if (e.time <= doubleClickExpirationTime) {
|
|
179 control_.removeMouseListener(mouseListener);
|
|
180 cancelEditing();
|
|
181 handleDoubleClickEvent();
|
|
182 } else if (mouseListener !is null) {
|
|
183 control_.removeMouseListener(mouseListener);
|
|
184 }
|
|
185 }
|
|
186 };
|
|
187 control.addMouseListener(mouseListener);
|
|
188 }
|
|
189 }
|
|
190 }
|
|
191 }
|
|
192
|
|
193 /**
|
|
194 * Activate a cell editor for the given mouse position.
|
|
195 */
|
|
196 private void activateCellEditor(MouseEvent event) {
|
|
197 if (tableItem is null || tableItem.isDisposed()) {
|
|
198 // item no longer exists
|
|
199 return;
|
|
200 }
|
|
201 int columnToEdit;
|
|
202 int columns = getColumnCount();
|
|
203 if (columns is 0) {
|
|
204 // If no TableColumn, Table acts as if it has a single column
|
|
205 // which takes the whole width.
|
|
206 columnToEdit = 0;
|
|
207 } else {
|
|
208 columnToEdit = -1;
|
|
209 for (int i = 0; i < columns; i++) {
|
|
210 Rectangle bounds = getBounds(tableItem, i);
|
|
211 if (bounds.contains(event.x, event.y)) {
|
|
212 columnToEdit = i;
|
|
213 break;
|
|
214 }
|
|
215 }
|
|
216 if (columnToEdit is -1) {
|
|
217 return;
|
|
218 }
|
|
219 }
|
|
220
|
|
221 columnNumber = columnToEdit;
|
|
222 activateCellEditor();
|
|
223 }
|
|
224
|
|
225 /**
|
|
226 * Deactivates the currently active cell editor.
|
|
227 */
|
|
228 public void applyEditorValue() {
|
|
229 CellEditor c = this.cellEditor;
|
|
230 if (c !is null) {
|
|
231 // null out cell editor before calling save
|
|
232 // in case save results in applyEditorValue being re-entered
|
|
233 // see 1GAHI8Z: ITPUI:ALL - How to code event notification when
|
|
234 // using cell editor ?
|
|
235 this.cellEditor = null;
|
|
236 Item t = this.tableItem;
|
|
237 // don't null out table item -- same item is still selected
|
|
238 if (t !is null && !t.isDisposed()) {
|
|
239 saveEditorValue(c, t);
|
|
240 }
|
|
241 setEditor(null, null, 0);
|
|
242 c.removeListener(cellEditorListener);
|
|
243 Control control = c.getControl();
|
|
244 if (control !is null) {
|
|
245 if (mouseListener !is null) {
|
|
246 control.removeMouseListener(mouseListener);
|
|
247 }
|
|
248 if (focusListener !is null) {
|
|
249 control.removeFocusListener(focusListener);
|
|
250 }
|
|
251 }
|
|
252 c.deactivate();
|
|
253 }
|
|
254 }
|
|
255
|
|
256 /**
|
|
257 * Cancels the active cell editor, without saving the value back to the
|
|
258 * domain model.
|
|
259 */
|
|
260 public void cancelEditing() {
|
|
261 if (cellEditor !is null) {
|
|
262 setEditor(null, null, 0);
|
|
263 cellEditor.removeListener(cellEditorListener);
|
|
264 CellEditor oldEditor = cellEditor;
|
|
265 cellEditor = null;
|
|
266 oldEditor.deactivate();
|
|
267 }
|
|
268 }
|
|
269
|
|
270 /**
|
|
271 * Start editing the given element.
|
|
272 *
|
|
273 * @param element
|
|
274 * @param column
|
|
275 */
|
|
276 public void editElement(Object element, int column) {
|
|
277 if (cellEditor !is null) {
|
|
278 applyEditorValue();
|
|
279 }
|
|
280
|
|
281 setSelection(new StructuredSelection(element), true);
|
|
282 Item[] selection = getSelection();
|
|
283 if (selection.length !is 1) {
|
|
284 return;
|
|
285 }
|
|
286
|
|
287 tableItem = selection[0];
|
|
288
|
|
289 // Make sure selection is visible
|
|
290 showSelection();
|
|
291 columnNumber = column;
|
|
292 activateCellEditor();
|
|
293
|
|
294 }
|
|
295
|
|
296 /**
|
|
297 * Return the array of CellEditors used in the viewer
|
|
298 *
|
|
299 * @return the cell editors
|
|
300 */
|
|
301 public CellEditor[] getCellEditors() {
|
|
302 return cellEditors;
|
|
303 }
|
|
304
|
|
305 /**
|
|
306 * Get the cell modifier
|
|
307 *
|
|
308 * @return the cell modifier
|
|
309 */
|
|
310 public ICellModifier getCellModifier() {
|
|
311 return cellModifier;
|
|
312 }
|
|
313
|
|
314 /**
|
|
315 * Return the properties for the column
|
|
316 *
|
|
317 * @return the array of column properties
|
|
318 */
|
|
319 public Object[] getColumnProperties() {
|
|
320 Object[] res;
|
|
321 foreach( str; columnProperties ){
|
|
322 res ~= new ArrayWrapperString( str );
|
|
323 }
|
|
324 return res;
|
|
325 }
|
|
326
|
|
327 /**
|
|
328 * Handles the mouse down event; activates the cell editor.
|
|
329 *
|
|
330 * @param event
|
|
331 * the mouse event that should be handled
|
|
332 */
|
|
333 public void handleMouseDown(MouseEvent event) {
|
|
334 if (event.button !is 1) {
|
|
335 return;
|
|
336 }
|
|
337
|
|
338 if (cellEditor !is null) {
|
|
339 applyEditorValue();
|
|
340 }
|
|
341
|
|
342 // activate the cell editor immediately. If a second mouseDown
|
|
343 // is received prior to the expiration of the doubleClick time then
|
|
344 // the cell editor will be deactivated and a doubleClick event will
|
|
345 // be processed.
|
|
346 //
|
|
347 doubleClickExpirationTime = event.time
|
|
348 + Display.getCurrent().getDoubleClickTime();
|
|
349
|
|
350 Item[] items = getSelection();
|
|
351 // Do not edit if more than one row is selected.
|
|
352 if (items.length !is 1) {
|
|
353 tableItem = null;
|
|
354 return;
|
|
355 }
|
|
356 tableItem = items[0];
|
|
357
|
|
358 activateCellEditor(event);
|
|
359 }
|
|
360
|
|
361 private void initCellEditorListener() {
|
|
362 cellEditorListener = new class ICellEditorListener {
|
|
363 public void editorValueChanged(bool oldValidState,
|
|
364 bool newValidState) {
|
|
365 // Ignore.
|
|
366 }
|
|
367
|
|
368 public void cancelEditor() {
|
|
369 this.outer.cancelEditing();
|
|
370 }
|
|
371
|
|
372 public void applyEditorValue() {
|
|
373 this.outer.applyEditorValue();
|
|
374 }
|
|
375 };
|
|
376 }
|
|
377
|
|
378 /**
|
|
379 * Return whether there is an active cell editor.
|
|
380 *
|
|
381 * @return <code>true</code> if there is an active cell editor;
|
|
382 * otherwise <code>false</code> is returned.
|
|
383 */
|
|
384 public bool isCellEditorActive() {
|
|
385 return cellEditor !is null;
|
|
386 }
|
|
387
|
|
388 /**
|
|
389 * Saves the value of the currently active cell editor, by delegating to
|
|
390 * the cell modifier.
|
|
391 */
|
|
392 private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
|
|
393 if( cellModifier !is null ) {
|
|
394 if( ! cellEditor.isValueValid() ) {
|
|
395 // Do what????
|
|
396 }
|
|
397 }
|
|
398 String property = null;
|
|
399
|
|
400 if( columnProperties !is null && columnNumber < columnProperties.length ) {
|
|
401 property = columnProperties[columnNumber];
|
|
402 }
|
|
403 cellModifier.modify(tableItem, property, cellEditor.getValue());
|
|
404 }
|
|
405
|
|
406 /**
|
|
407 * Set the cell editors
|
|
408 *
|
|
409 * @param editors
|
|
410 */
|
|
411 public void setCellEditors(CellEditor[] editors) {
|
|
412 this.cellEditors = editors;
|
|
413 }
|
|
414
|
|
415 /**
|
|
416 * Set the cell modifier
|
|
417 *
|
|
418 * @param modifier
|
|
419 */
|
|
420 public void setCellModifier(ICellModifier modifier) {
|
|
421 this.cellModifier = modifier;
|
|
422 }
|
|
423
|
|
424 /**
|
|
425 * Set the column properties
|
|
426 *
|
|
427 * @param columnProperties
|
|
428 */
|
|
429 public void setColumnProperties(String[] columnProperties) {
|
|
430 this.columnProperties = columnProperties;
|
|
431 }
|
|
432
|
|
433 Rectangle getBounds(Item item, int columnNumber) {
|
|
434 return (cast(TableTreeItem) item).getBounds(columnNumber);
|
|
435 }
|
|
436
|
|
437 int getColumnCount() {
|
|
438 // getColumnCount() should be a API in TableTree.
|
|
439 return getTableTree().getTable().getColumnCount();
|
|
440 }
|
|
441
|
|
442 Item[] getSelection() {
|
|
443 return getTableTree().getSelection();
|
|
444 }
|
|
445
|
|
446 void setEditor(Control w, Item item, int columnNumber) {
|
|
447 tableTreeEditor.setEditor(w, cast(TableTreeItem) item, columnNumber);
|
|
448 }
|
|
449
|
|
450 void setSelection(StructuredSelection selection, bool b) {
|
|
451 this.outer.setSelection(selection, b);
|
|
452 }
|
|
453
|
|
454 void showSelection() {
|
|
455 getTableTree().showSelection();
|
|
456 }
|
|
457
|
|
458 void setLayoutData(CellEditor.LayoutData layoutData) {
|
|
459 tableTreeEditor.horizontalAlignment = layoutData.horizontalAlignment;
|
|
460 tableTreeEditor.grabHorizontal = layoutData.grabHorizontal;
|
|
461 tableTreeEditor.minimumWidth = layoutData.minimumWidth;
|
|
462 }
|
|
463
|
|
464 void handleDoubleClickEvent() {
|
|
465 Viewer viewer = getViewer();
|
|
466 fireDoubleClick(new DoubleClickEvent(viewer, viewer.getSelection()));
|
|
467 fireOpen(new OpenEvent(viewer, viewer.getSelection()));
|
|
468 }
|
|
469 }
|
|
470
|
|
471 /**
|
|
472 * Creates a table tree viewer on the given table tree control. The viewer
|
|
473 * has no input, no content provider, a default label provider, no sorter,
|
|
474 * and no filters.
|
|
475 *
|
|
476 * @param tree
|
|
477 * the table tree control
|
|
478 */
|
|
479 public this(TableTree tree) {
|
|
480 super();
|
|
481 tableTree = tree;
|
|
482 hookControl(tree);
|
|
483 tableTreeEditor = new TableTreeEditor(tableTree);
|
|
484 tableEditorImpl = new TableTreeEditorImpl(this);
|
|
485 }
|
|
486
|
|
487 /**
|
|
488 * Creates a table tree viewer on a newly-created table tree control under
|
|
489 * the given parent. The table tree control is created using the DWT style
|
|
490 * bits <code>MULTI, H_SCROLL, V_SCROLL, and BORDER</code>. The viewer
|
|
491 * has no input, no content provider, a default label provider, no sorter,
|
|
492 * and no filters.
|
|
493 *
|
|
494 * @param parent
|
|
495 * the parent control
|
|
496 */
|
|
497 public this(Composite parent) {
|
|
498 this(parent, DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
|
|
499 }
|
|
500
|
|
501 /**
|
|
502 * Creates a table tree viewer on a newly-created table tree control under
|
|
503 * the given parent. The table tree control is created using the given DWT
|
|
504 * style bits. The viewer has no input, no content provider, a default label
|
|
505 * provider, no sorter, and no filters.
|
|
506 *
|
|
507 * @param parent
|
|
508 * the parent control
|
|
509 * @param style
|
|
510 * the DWT style bits
|
|
511 */
|
|
512 public this(Composite parent, int style) {
|
|
513 this(new TableTree(parent, style));
|
|
514 }
|
|
515
|
|
516 /*
|
|
517 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
518 */
|
|
519 protected void addTreeListener(Control c, TreeListener listener) {
|
|
520 (cast(TableTree) c).addTreeListener(listener);
|
|
521 }
|
|
522
|
|
523 /**
|
|
524 * Cancels a currently active cell editor. All changes already done in the
|
|
525 * cell editor are lost.
|
|
526 */
|
|
527 public void cancelEditing() {
|
|
528 tableEditorImpl.cancelEditing();
|
|
529 }
|
|
530
|
|
531 /*
|
|
532 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
533 */
|
|
534 protected void doUpdateItem(Item item, Object element) {
|
|
535 // update icon and label
|
|
536 // Similar code in TableTreeViewer.doUpdateItem()
|
|
537 IBaseLabelProvider prov = getLabelProvider();
|
|
538 ITableLabelProvider tprov = null;
|
|
539
|
|
540 if ( auto t = cast(ITableLabelProvider) prov ) {
|
|
541 tprov = t;
|
|
542 }
|
|
543
|
|
544 int columnCount = tableTree.getTable().getColumnCount();
|
|
545 TableTreeItem ti = cast(TableTreeItem) item;
|
|
546 // Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT -
|
|
547 // TableViewer with 0 columns does not work
|
|
548 for (int column = 0; column < columnCount || column is 0; column++) {
|
|
549 String text = "";//$NON-NLS-1$
|
|
550 Image image = null;
|
|
551 if (tprov !is null) {
|
|
552 text = tprov.getColumnText(element, column);
|
|
553 image = tprov.getColumnImage(element, column);
|
|
554 } else {
|
|
555 if (column is 0) {
|
|
556 ViewerLabel updateLabel = new ViewerLabel(item.getText(),
|
|
557 item.getImage());
|
|
558 buildLabel(updateLabel, element);
|
|
559
|
|
560 // As it is possible for user code to run the event
|
|
561 // loop check here.
|
|
562 if (item.isDisposed()) {
|
|
563 unmapElement(element, item);
|
|
564 return;
|
|
565 }
|
|
566
|
|
567 text = updateLabel.getText();
|
|
568 image = updateLabel.getImage();
|
|
569 }
|
|
570 }
|
|
571
|
|
572 // Avoid setting text to null
|
|
573 if (text is null) {
|
|
574 text = ""; //$NON-NLS-1$
|
|
575 }
|
|
576
|
|
577 ti.setText(column, text);
|
|
578 // Apparently a problem to setImage to null if already null
|
|
579 if (ti.getImage(column) !is image) {
|
|
580 ti.setImage(column, image);
|
|
581 }
|
|
582
|
|
583 getColorAndFontCollector().setFontsAndColors(element);
|
|
584 getColorAndFontCollector().applyFontsAndColors(ti);
|
|
585 }
|
|
586
|
|
587 }
|
|
588
|
|
589 /**
|
|
590 * Starts editing the given element.
|
|
591 *
|
|
592 * @param element
|
|
593 * the element
|
|
594 * @param column
|
|
595 * the column number
|
|
596 */
|
|
597 public void editElement(Object element, int column) {
|
|
598 tableEditorImpl.editElement(element, column);
|
|
599 }
|
|
600
|
|
601 /**
|
|
602 * Returns the cell editors of this viewer.
|
|
603 *
|
|
604 * @return the list of cell editors
|
|
605 */
|
|
606 public CellEditor[] getCellEditors() {
|
|
607 return tableEditorImpl.getCellEditors();
|
|
608 }
|
|
609
|
|
610 /**
|
|
611 * Returns the cell modifier of this viewer.
|
|
612 *
|
|
613 * @return the cell modifier
|
|
614 */
|
|
615 public ICellModifier getCellModifier() {
|
|
616 return tableEditorImpl.getCellModifier();
|
|
617 }
|
|
618
|
|
619 /*
|
|
620 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
621 */
|
|
622 protected Item[] getChildren(Widget o) {
|
|
623 if (auto i = cast(TableTreeItem) o ) {
|
|
624 return i.getItems();
|
|
625 }
|
|
626 if (auto i = cast(TableTree) o ) {
|
|
627 return i.getItems();
|
|
628 }
|
|
629 return null;
|
|
630 }
|
|
631
|
|
632 /*
|
|
633 * (non-Javadoc)
|
|
634 *
|
|
635 * @see dwtx.jface.viewers.AbstractTreeViewer#getChild(dwt.widgets.Widget,
|
|
636 * int)
|
|
637 */
|
|
638 protected Item getChild(Widget widget, int index) {
|
|
639 if (auto w = cast(TableTreeItem) widget ) {
|
|
640 return w.getItem(index);
|
|
641 }
|
|
642 if (auto w = cast(TableTree) widget ) {
|
|
643 return w.getItem(index);
|
|
644 }
|
|
645 return null;
|
|
646 }
|
|
647
|
|
648 /**
|
|
649 * Returns the column properties of this viewer. The properties must
|
|
650 * correspond with the columns of the table control. They are used to
|
|
651 * identify the column in a cell modifier.
|
|
652 *
|
|
653 * @return the list of column properties
|
|
654 */
|
|
655 public Object[] getColumnProperties() {
|
|
656 return tableEditorImpl.getColumnProperties();
|
|
657 }
|
|
658
|
|
659 /*
|
|
660 * (non-Javadoc) Method declared on Viewer.
|
|
661 */
|
|
662 public Control getControl() {
|
|
663 return tableTree;
|
|
664 }
|
|
665
|
|
666 /**
|
|
667 * Returns the element with the given index from this viewer. Returns
|
|
668 * <code>null</code> if the index is out of range.
|
|
669 * <p>
|
|
670 * This method is internal to the framework.
|
|
671 * </p>
|
|
672 *
|
|
673 * @param index
|
|
674 * the zero-based index
|
|
675 * @return the element at the given index, or <code>null</code> if the
|
|
676 * index is out of range
|
|
677 */
|
|
678 public Object getElementAt(int index) {
|
|
679 // XXX: Workaround for 1GBCSB1: DWT:WIN2000 - TableTree should have
|
|
680 // getItem(int index)
|
|
681 TableTreeItem i = tableTree.getItems()[index];
|
|
682 if (i !is null) {
|
|
683 return i.getData();
|
|
684 }
|
|
685 return null;
|
|
686 }
|
|
687
|
|
688 /*
|
|
689 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
690 */
|
|
691 protected bool getExpanded(Item item) {
|
|
692 return (cast(TableTreeItem) item).getExpanded();
|
|
693 }
|
|
694
|
|
695 /*
|
|
696 * (non-Javadoc)
|
|
697 *
|
|
698 * @see dwtx.jface.viewers.ColumnViewer#getItemAt(dwt.graphics.Point)
|
|
699 */
|
|
700 protected Item getItemAt(Point p) {
|
|
701 return getTableTree().getTable().getItem(p);
|
|
702 }
|
|
703
|
|
704 /*
|
|
705 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
706 */
|
|
707 protected int getItemCount(Control widget) {
|
|
708 return (cast(TableTree) widget).getItemCount();
|
|
709 }
|
|
710
|
|
711 /*
|
|
712 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
713 */
|
|
714 protected int getItemCount(Item item) {
|
|
715 return (cast(TableTreeItem) item).getItemCount();
|
|
716 }
|
|
717
|
|
718 /*
|
|
719 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
720 */
|
|
721 protected dwt.widgets.Item.Item[] getItems(
|
|
722 dwt.widgets.Item.Item item) {
|
|
723 return (cast(TableTreeItem) item).getItems();
|
|
724 }
|
|
725
|
|
726 /**
|
|
727 * The table tree viewer implementation of this <code>Viewer</code>
|
|
728 * framework method returns the label provider, which in the case of table
|
|
729 * tree viewers will be an instance of either
|
|
730 * <code>ITableLabelProvider</code> or <code>ILabelProvider</code>. If
|
|
731 * it is an <code>ITableLabelProvider</code>, then it provides a separate
|
|
732 * label text and image for each column. If it is an
|
|
733 * <code>ILabelProvider</code>, then it provides only the label text and
|
|
734 * image for the first column, and any remaining columns are blank.
|
|
735 */
|
|
736 public IBaseLabelProvider getLabelProvider() {
|
|
737 return super.getLabelProvider();
|
|
738 }
|
|
739
|
|
740 /*
|
|
741 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
742 */
|
|
743 protected Item getParentItem(Item item) {
|
|
744 return (cast(TableTreeItem) item).getParentItem();
|
|
745 }
|
|
746
|
|
747 /*
|
|
748 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
749 */
|
|
750 protected Item[] getSelection(Control widget) {
|
|
751 return (cast(TableTree) widget).getSelection();
|
|
752 }
|
|
753
|
|
754 /**
|
|
755 * Returns this table tree viewer's table tree control.
|
|
756 *
|
|
757 * @return the table tree control
|
|
758 */
|
|
759 public TableTree getTableTree() {
|
|
760 return tableTree;
|
|
761 }
|
|
762
|
|
763 /*
|
|
764 * (non-Javadoc) Method declared on AbstractTreeViewer.
|
|
765 */
|
|
766 protected void hookControl(Control control) {
|
|
767 super.hookControl(control);
|
|
768 tableTree.getTable().addMouseListener(new class MouseAdapter {
|
|
769 public void mouseDown(MouseEvent e) {
|
|
770 /*
|
|
771 * If user clicked on the [+] or [-], do not activate
|
|
772 * CellEditor.
|
|
773 */
|
|
774 // XXX: This code should not be here. DWT should either have
|
|
775 // support to see
|
|
776 // if the user clicked on the [+]/[-] or manage the table editor
|
|
777 // activation
|
|
778 dwt.widgets.TableItem.TableItem[] items = tableTree
|
|
779 .getTable().getItems();
|
|
780 for (int i = 0; i < items.length; i++) {
|
|
781 Rectangle rect = items[i].getImageBounds(0);
|
|
782 if (rect.contains(e.x, e.y)) {
|
|
783 return;
|
|
784 }
|
|
785 }
|
|
786
|
|
787 tableEditorImpl.handleMouseDown(e);
|
|
788 }
|
|
789 });
|
|
790 }
|
|
791
|
|
792 /**
|
|
793 * Returns whether there is an active cell editor.
|
|
794 *
|
|
795 * @return <code>true</code> if there is an active cell editor, and
|
|
796 * <code>false</code> otherwise
|
|
797 */
|
|
798 public bool isCellEditorActive() {
|
|
799 return tableEditorImpl.isCellEditorActive();
|
|
800 }
|
|
801
|
|
802 /*
|
|
803 * (non-Javadoc) Method declared in AbstractTreeViewer.
|
|
804 */
|
|
805 protected Item newItem(Widget parent, int flags, int ix) {
|
|
806 TableTreeItem item;
|
|
807 if (ix >= 0) {
|
|
808 if (cast(TableTreeItem) parent ) {
|
|
809 item = new TableTreeItem(cast(TableTreeItem) parent, flags, ix);
|
|
810 } else {
|
|
811 item = new TableTreeItem(cast(TableTree) parent, flags, ix);
|
|
812 }
|
|
813 } else {
|
|
814 if (cast(TableTreeItem)parent ) {
|
|
815 item = new TableTreeItem(cast(TableTreeItem) parent, flags);
|
|
816 } else {
|
|
817 item = new TableTreeItem(cast(TableTree) parent, flags);
|
|
818 }
|
|
819 }
|
|
820 return item;
|
|
821 }
|
|
822
|
|
823 /*
|
|
824 * (non-Javadoc) Method declared in AbstractTreeViewer.
|
|
825 */
|
|
826 protected void removeAll(Control widget) {
|
|
827 (cast(TableTree) widget).removeAll();
|
|
828 }
|
|
829
|
|
830 /**
|
|
831 * Sets the cell editors of this table viewer.
|
|
832 *
|
|
833 * @param editors
|
|
834 * the list of cell editors
|
|
835 */
|
|
836 public void setCellEditors(CellEditor[] editors) {
|
|
837 tableEditorImpl.setCellEditors(editors);
|
|
838 }
|
|
839
|
|
840 /**
|
|
841 * Sets the cell modifier of this table viewer.
|
|
842 *
|
|
843 * @param modifier
|
|
844 * the cell modifier
|
|
845 */
|
|
846 public void setCellModifier(ICellModifier modifier) {
|
|
847 tableEditorImpl.setCellModifier(modifier);
|
|
848 }
|
|
849
|
|
850 /**
|
|
851 * Sets the column properties of this table viewer. The properties must
|
|
852 * correspond with the columns of the table control. They are used to
|
|
853 * identify the column in a cell modifier.
|
|
854 *
|
|
855 * @param columnProperties
|
|
856 * the list of column properties
|
|
857 */
|
|
858 public void setColumnProperties(String[] columnProperties) {
|
|
859 tableEditorImpl.setColumnProperties(columnProperties);
|
|
860 }
|
|
861
|
|
862 /*
|
|
863 * (non-Javadoc) Method declared in AbstractTreeViewer.
|
|
864 */
|
|
865 protected void setExpanded(Item node, bool expand) {
|
|
866 (cast(TableTreeItem) node).setExpanded(expand);
|
|
867 }
|
|
868
|
|
869 /*
|
|
870 * (non-Javadoc) Method declared in AbstractTreeViewer.
|
|
871 */
|
|
872 protected void setSelection(SeqView!(Item) items) {
|
|
873 getTableTree().setSelection(cast(TableTreeItem[]) items.toArray);
|
|
874 }
|
|
875
|
|
876 /*
|
|
877 * (non-Javadoc) Method declared in AbstractTreeViewer.
|
|
878 */
|
|
879 protected void showItem(Item item) {
|
|
880 getTableTree().showItem(cast(TableTreeItem) item);
|
|
881 }
|
|
882 }
|