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