Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/ColumnViewer.d @ 54:a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 12 Apr 2008 17:53:06 +0200 |
parents | 28f6c339768e |
children | 46a6e0e6ccd4 |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
2 * Copyright (c) 2006, 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; bug 153993 | |
11 * fix in bug 163317, 151295, 167323, 167858, 184346, 187826, 200558,201002 | |
12 * Port to the D programming language: | |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 | |
16 module dwtx.jface.viewers.ColumnViewer; | |
17 | |
18 import dwtx.jface.viewers.StructuredViewer; | |
19 import dwtx.jface.viewers.CellEditor; | |
20 import dwtx.jface.viewers.ICellModifier; | |
21 import dwtx.jface.viewers.ColumnViewerEditor; | |
22 import dwtx.jface.viewers.ViewerCell; | |
23 import dwtx.jface.viewers.ViewerRow; | |
24 import dwtx.jface.viewers.ViewerColumn; | |
25 import dwtx.jface.viewers.CellLabelProvider; | |
26 import dwtx.jface.viewers.IBaseLabelProvider; | |
27 import dwtx.jface.viewers.ColumnViewerEditorActivationEvent; | |
28 import dwtx.jface.viewers.EditingSupport; | |
29 import dwtx.jface.viewers.ITableLabelProvider; | |
30 import dwtx.jface.viewers.ILabelProvider; | |
31 import dwtx.jface.viewers.StructuredSelection; | |
32 | |
33 import dwt.events.MouseAdapter; | |
34 import dwt.events.MouseEvent; | |
35 import dwt.graphics.Point; | |
36 import dwt.widgets.Control; | |
37 import dwt.widgets.Item; | |
38 import dwt.widgets.Widget; | |
39 import dwtx.core.runtime.Assert; | |
40 import dwtx.core.runtime.IStatus; | |
41 import dwtx.core.runtime.Status; | |
42 import dwtx.jface.internal.InternalPolicy; | |
43 import dwtx.jface.util.Policy; | |
44 | |
45 import dwt.dwthelper.utils; | |
46 | |
47 /** | |
48 * The ColumnViewer is the abstract superclass of viewers that have columns | |
49 * (e.g., AbstractTreeViewer and AbstractTableViewer). Concrete subclasses of | |
50 * {@link ColumnViewer} should implement a matching concrete subclass of | |
51 * {@link ViewerColumn}. | |
52 * | |
53 * <strong> This class is not intended to be subclassed outside of the JFace | |
54 * viewers framework.</strong> | |
55 * | |
56 * @since 3.3 | |
57 * | |
58 */ | |
59 public abstract class ColumnViewer : StructuredViewer { | |
60 alias StructuredViewer.getLabelProvider getLabelProvider; | |
14 | 61 alias StructuredViewer.refresh refresh; |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
62 alias StructuredViewer.update update; |
10 | 63 |
64 private CellEditor[] cellEditors; | |
65 | |
66 private ICellModifier cellModifier; | |
67 | |
68 private String[] columnProperties; | |
69 | |
70 /** | |
71 * The cell is a cached viewer cell used for refreshing. | |
72 */ | |
73 private ViewerCell cell; | |
74 | |
75 private ColumnViewerEditor viewerEditor; | |
76 | |
77 /* package */ bool busy; | |
78 /* package */ bool logWhenBusy = true; // initially true, set to false after logging for the first time | |
79 | |
80 /** | |
81 * Create a new instance of the receiver. | |
82 */ | |
83 public this() { | |
84 cell = new ViewerCell(null, 0, null); | |
85 } | |
86 | |
87 /* package */ bool isBusy() { | |
88 if (busy) { | |
89 if (logWhenBusy) { | |
90 String message = "Ignored reentrant call while viewer is busy."; //$NON-NLS-1$ | |
91 if (!InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS) { | |
92 // stop logging after the first | |
93 logWhenBusy = false; | |
94 message ~= " This is only logged once per viewer instance," ~ //$NON-NLS-1$ | |
95 " but similar calls will still be ignored."; //$NON-NLS-1$ | |
96 } | |
97 Policy.getLog().log( | |
98 new Status( | |
99 IStatus.WARNING, | |
100 Policy.JFACE, | |
101 message, new RuntimeException())); | |
102 } | |
103 return true; | |
104 } | |
105 return false; | |
106 } | |
107 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
108 protected override void hookControl(Control control) { |
10 | 109 super.hookControl(control); |
110 viewerEditor = createViewerEditor(); | |
111 hookEditingSupport(control); | |
112 } | |
113 | |
114 /** | |
115 * Hook up the editing support. Subclasses may override. | |
116 * | |
117 * @param control | |
118 * the control you want to hook on | |
119 */ | |
120 protected void hookEditingSupport(Control control) { | |
121 // Needed for backwards comp with AbstractTreeViewer and TableTreeViewer | |
122 // who are not hooked this way others may already overwrite and provide | |
123 // their | |
124 // own impl | |
125 if (viewerEditor !is null) { | |
126 control.addMouseListener(new class MouseAdapter { | |
127 public void mouseDown(MouseEvent e) { | |
128 // Workaround for bug 185817 | |
129 if( e.count !is 2 ) { | |
130 handleMouseDown(e); | |
131 } | |
132 } | |
133 | |
134 public void mouseDoubleClick(MouseEvent e) { | |
135 handleMouseDown(e); | |
136 } | |
137 }); | |
138 } | |
139 } | |
140 | |
141 /** | |
142 * Creates the viewer editor used for editing cell contents. To be | |
143 * implemented by subclasses. | |
144 * | |
145 * @return the editor, or <code>null</code> if this viewer does not | |
146 * support editing cell contents. | |
147 */ | |
148 protected abstract ColumnViewerEditor createViewerEditor(); | |
149 | |
150 /** | |
151 * Returns the viewer cell at the given widget-relative coordinates, or | |
152 * <code>null</code> if there is no cell at that location | |
153 * | |
154 * @param point | |
155 * the widget-relative coordinates | |
156 * @return the cell or <code>null</code> if no cell is found at the given | |
157 * point | |
158 */ | |
159 ViewerCell getCell(Point point) { | |
160 ViewerRow row = getViewerRow(point); | |
161 if (row !is null) { | |
162 return row.getCell(point); | |
163 } | |
164 | |
165 return null; | |
166 } | |
167 | |
168 /** | |
169 * Returns the viewer row at the given widget-relative coordinates. | |
170 * | |
171 * @param point | |
172 * the widget-relative coordinates of the viewer row | |
173 * @return ViewerRow the row or <code>null</code> if no row is found at | |
174 * the given coordinates | |
175 */ | |
176 protected ViewerRow getViewerRow(Point point) { | |
177 Item item = getItemAt(point); | |
178 | |
179 if (item !is null) { | |
180 return getViewerRowFromItem(item); | |
181 } | |
182 | |
183 return null; | |
184 } | |
185 package ViewerRow getViewerRow_package(Point point) { | |
186 return getViewerRow(point); | |
187 } | |
188 | |
189 | |
190 | |
191 /** | |
192 * Returns a {@link ViewerRow} associated with the given row widget. Implementations | |
193 * may re-use the same instance for different row widgets; callers can only use the viewer | |
194 * row locally and until the next call to this method. | |
195 * | |
196 * @param item the row widget | |
197 * @return ViewerRow a viewer row object | |
198 */ | |
199 protected abstract ViewerRow getViewerRowFromItem(Widget item); | |
200 package ViewerRow getViewerRowFromItem_package(Widget item){ | |
201 return getViewerRowFromItem(item); | |
202 } | |
203 | |
204 /** | |
205 * Returns the column widget at the given column index. | |
206 * | |
207 * @param columnIndex | |
208 * the column index | |
209 * @return Widget the column widget | |
210 */ | |
211 protected abstract Widget getColumnViewerOwner(int columnIndex); | |
212 | |
213 /** | |
214 * Returns the viewer column for the given column index. | |
215 * | |
216 * @param columnIndex | |
217 * the column index | |
218 * @return the viewer column at the given index, or <code>null</code> if | |
219 * there is none for the given index | |
220 */ | |
221 /* package */ViewerColumn getViewerColumn(int columnIndex) { | |
222 | |
223 ViewerColumn viewer; | |
224 Widget columnOwner = getColumnViewerOwner(columnIndex); | |
225 | |
226 if (columnOwner is null) { | |
227 return null; | |
228 } | |
229 | |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
230 viewer = cast(ViewerColumn) columnOwner.getData(ViewerColumn.COLUMN_VIEWER_KEY); |
10 | 231 |
232 if (viewer is null) { | |
233 viewer = createViewerColumn(columnOwner, CellLabelProvider | |
234 .createViewerLabelProvider(this, getLabelProvider())); | |
235 setupEditingSupport(columnIndex, viewer); | |
236 } | |
237 | |
238 if (viewer.getEditingSupport() is null && getCellModifier() !is null) { | |
239 setupEditingSupport(columnIndex, viewer); | |
240 } | |
241 | |
242 return viewer; | |
243 } | |
244 | |
245 /** | |
246 * Sets up editing support for the given column based on the "old" cell | |
247 * editor API. | |
248 * | |
249 * @param columnIndex | |
250 * @param viewer | |
251 */ | |
252 private void setupEditingSupport(int columnIndex, ViewerColumn viewer) { | |
253 if (getCellModifier() !is null) { | |
39 | 254 viewer.setEditingSupport(new class(this,columnIndex) EditingSupport { |
10 | 255 int columnIndex_; |
39 | 256 this(ColumnViewer cv, int ci){ |
10 | 257 super(cv); |
39 | 258 columnIndex_=ci; |
10 | 259 } |
260 /* | |
261 * (non-Javadoc) | |
262 * | |
263 * @see dwtx.jface.viewers.EditingSupport#canEdit(java.lang.Object) | |
264 */ | |
265 public bool canEdit(Object element) { | |
266 Object[] properties = getColumnProperties(); | |
267 | |
268 if( columnIndex_ < properties.length ) { | |
269 return getCellModifier().canModify(element, | |
270 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array); | |
271 } | |
272 | |
273 return false; | |
274 } | |
275 | |
276 /* | |
277 * (non-Javadoc) | |
278 * | |
279 * @see dwtx.jface.viewers.EditingSupport#getCellEditor(java.lang.Object) | |
280 */ | |
281 public CellEditor getCellEditor(Object element) { | |
282 CellEditor[] editors = getCellEditors(); | |
283 if( columnIndex_ < editors.length ) { | |
284 return getCellEditors()[columnIndex_]; | |
285 } | |
286 return null; | |
287 } | |
288 | |
289 /* | |
290 * (non-Javadoc) | |
291 * | |
292 * @see dwtx.jface.viewers.EditingSupport#getValue(java.lang.Object) | |
293 */ | |
294 public Object getValue(Object element) { | |
295 Object[] properties = getColumnProperties(); | |
296 | |
297 if( columnIndex_ < properties.length ) { | |
298 return getCellModifier().getValue(element, | |
299 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array); | |
300 } | |
301 | |
302 return null; | |
303 } | |
304 | |
305 /* | |
306 * (non-Javadoc) | |
307 * | |
308 * @see dwtx.jface.viewers.EditingSupport#setValue(java.lang.Object, | |
309 * java.lang.Object) | |
310 */ | |
311 public void setValue(Object element, Object value) { | |
312 Object[] properties = getColumnProperties(); | |
313 | |
314 if( columnIndex_ < properties.length ) { | |
315 getCellModifier().modify(findItem(element), | |
316 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array, value); | |
317 } | |
318 } | |
319 | |
320 bool isLegacySupport() { | |
321 return true; | |
322 } | |
323 }); | |
324 } | |
325 } | |
326 | |
327 /** | |
328 * Creates a generic viewer column for the given column widget, based on the | |
329 * given label provider. | |
330 * | |
331 * @param columnOwner | |
332 * the column widget | |
333 * @param labelProvider | |
334 * the label provider to use for the column | |
335 * @return ViewerColumn the viewer column | |
336 */ | |
337 private ViewerColumn createViewerColumn(Widget columnOwner, | |
338 CellLabelProvider labelProvider) { | |
339 ViewerColumn column = new class(this, columnOwner) ViewerColumn { | |
340 this( ColumnViewer cv, Widget co ){ | |
341 super(cv,co); | |
342 } | |
343 }; | |
344 column.setLabelProvider(labelProvider, false); | |
345 return column; | |
346 } | |
347 | |
348 /** | |
349 * Update the cached cell object with the given row and column. Be careful not | |
350 * to hold on to element objects longer than required. It is good practice to | |
351 * call updateCell(null, 0, null) to clear references immediately after using | |
352 * the cached cell object. (See bug 201280 for an example case where this happened.) | |
353 * | |
354 * @param rowItem | |
355 * @param column | |
356 * @return ViewerCell | |
357 */ | |
358 /* package */ViewerCell updateCell(ViewerRow rowItem, int column, Object element) { | |
359 cell.update(rowItem, column, element); | |
360 return cell; | |
361 } | |
362 | |
363 /** | |
364 * Returns the {@link Item} at the given widget-relative coordinates, or | |
365 * <code>null</code> if there is no item at the given coordinates. | |
366 * | |
367 * @param point | |
368 * the widget-relative coordinates | |
369 * @return the {@link Item} at the coordinates or <code>null</code> if | |
370 * there is no item at the given coordinates | |
371 */ | |
372 protected abstract Item getItemAt(Point point); | |
373 | |
374 /* | |
375 * (non-Javadoc) | |
376 * | |
377 * @see dwtx.jface.viewers.StructuredViewer#getItem(int, int) | |
378 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
379 protected override Item getItem(int x, int y) { |
10 | 380 return getItemAt(getControl().toControl(x, y)); |
381 } | |
382 | |
383 /** | |
384 * The column viewer implementation of this <code>Viewer</code> framework | |
385 * method ensures that the given label provider is an instance of | |
386 * <code>ITableLabelProvider</code>, <code>ILabelProvider</code>, or | |
387 * <code>CellLabelProvider</code>. | |
388 * <p> | |
389 * If the label provider is an {@link ITableLabelProvider}, then it | |
390 * provides a separate label text and image for each column. Implementers of | |
391 * <code>ITableLabelProvider</code> may also implement | |
392 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide | |
393 * colors and/or fonts. | |
394 * </p> | |
395 * <p> | |
396 * If the label provider is an <code>ILabelProvider</code>, then it | |
397 * provides only the label text and image for the first column, and any | |
398 * remaining columns are blank. Implementers of <code>ILabelProvider</code> | |
399 * may also implement {@link IColorProvider} and/or {@link IFontProvider} to | |
400 * provide colors and/or fonts. | |
401 * </p> | |
402 * | |
403 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
404 public override void setLabelProvider(IBaseLabelProvider labelProvider) { |
10 | 405 Assert.isTrue( null !is cast(ITableLabelProvider)labelProvider |
406 || null !is cast(ILabelProvider)labelProvider | |
407 || null !is cast(CellLabelProvider)labelProvider ); | |
408 updateColumnParts(labelProvider);// Reset the label providers in the | |
409 // columns | |
410 super.setLabelProvider(labelProvider); | |
411 } | |
412 | |
413 /** | |
414 * Clear the viewer parts for the columns | |
415 */ | |
416 private void updateColumnParts(IBaseLabelProvider labelProvider) { | |
417 ViewerColumn column; | |
418 int i = 0; | |
419 | |
420 while ((column = getViewerColumn(i++)) !is null) { | |
421 column.setLabelProvider(CellLabelProvider | |
422 .createViewerLabelProvider(this, labelProvider), false); | |
423 } | |
424 } | |
425 | |
426 /** | |
427 * Cancels a currently active cell editor if one is active. All changes | |
428 * already done in the cell editor are lost. | |
429 * | |
430 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
431 */ | |
432 public void cancelEditing() { | |
433 if (viewerEditor !is null) { | |
434 viewerEditor.cancelEditing(); | |
435 } | |
436 } | |
437 | |
438 /** | |
439 * Apply the value of the active cell editor if one is active. | |
440 * | |
441 * @since 3.3 | |
442 */ | |
443 protected void applyEditorValue() { | |
444 if (viewerEditor !is null) { | |
445 viewerEditor.applyEditorValue(); | |
446 } | |
447 } | |
448 | |
449 /** | |
450 * Starts editing the given element at the given column index. | |
451 * | |
452 * @param element | |
453 * the model element | |
454 * @param column | |
455 * the column index | |
456 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
457 */ | |
458 public void editElement(Object element, int column) { | |
459 if (viewerEditor !is null) { | |
460 try { | |
461 getControl().setRedraw(false); | |
462 // Set the selection at first because in Tree's | |
463 // the element might not be materialized | |
464 setSelection(new StructuredSelection(element),true); | |
465 | |
466 Widget item = findItem(element); | |
467 if (item !is null) { | |
468 ViewerRow row = getViewerRowFromItem(item); | |
469 if (row !is null) { | |
470 ViewerCell cell = row.getCell(column); | |
471 if (cell !is null) { | |
472 triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent( | |
473 cell)); | |
474 } | |
475 } | |
476 } | |
477 } finally { | |
478 getControl().setRedraw(true); | |
479 } | |
480 } | |
481 } | |
482 | |
483 /** | |
484 * Return the CellEditors for the receiver, or <code>null</code> if no | |
485 * cell editors are set. | |
486 * <p> | |
487 * Since 3.3, an alternative API is available, see | |
488 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
489 * flexible way of editing values in a column viewer. | |
490 * </p> | |
491 * | |
492 * @return CellEditor[] | |
493 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
494 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
495 * @see EditingSupport | |
496 */ | |
497 public CellEditor[] getCellEditors() { | |
498 return cellEditors; | |
499 } | |
500 | |
501 /** | |
502 * Returns the cell modifier of this viewer, or <code>null</code> if none | |
503 * has been set. | |
504 * | |
505 * <p> | |
506 * Since 3.3, an alternative API is available, see | |
507 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
508 * flexible way of editing values in a column viewer. | |
509 * </p> | |
510 * | |
511 * @return the cell modifier, or <code>null</code> | |
512 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
513 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
514 * @see EditingSupport | |
515 */ | |
516 public ICellModifier getCellModifier() { | |
517 return cellModifier; | |
518 } | |
519 | |
520 /** | |
521 * Returns the column properties of this table viewer. The properties must | |
522 * correspond with the columns of the table control. They are used to | |
523 * identify the column in a cell modifier. | |
524 * | |
525 * <p> | |
526 * Since 3.3, an alternative API is available, see | |
527 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
528 * flexible way of editing values in a column viewer. | |
529 * </p> | |
530 * | |
531 * @return the list of column properties | |
532 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
533 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
534 * @see EditingSupport | |
535 */ | |
536 public Object[] getColumnProperties() { | |
537 Object[] res; | |
538 foreach( prop; columnProperties ){ | |
539 res ~= new ArrayWrapperString( prop ); | |
540 } | |
541 return res; | |
542 } | |
543 | |
544 /** | |
545 * Returns whether there is an active cell editor. | |
546 * | |
547 * <p> | |
548 * Since 3.3, an alternative API is available, see | |
549 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
550 * flexible way of editing values in a column viewer. | |
551 * </p> | |
552 * | |
553 * @return <code>true</code> if there is an active cell editor, and | |
554 * <code>false</code> otherwise | |
555 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
556 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
557 * @see EditingSupport | |
558 */ | |
559 public bool isCellEditorActive() { | |
560 if (viewerEditor !is null) { | |
561 return viewerEditor.isCellEditorActive(); | |
562 } | |
563 return false; | |
564 } | |
565 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
566 public override void refresh(Object element) { |
10 | 567 if (isBusy()) |
568 return; | |
569 | |
570 if( isCellEditorActive() ) { | |
571 cancelEditing(); | |
572 } | |
573 | |
574 super.refresh(element); | |
575 } | |
576 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
577 public override void refresh(Object element, bool updateLabels) { |
10 | 578 if (isBusy()) |
579 return; | |
580 | |
581 if( isCellEditorActive() ) { | |
582 cancelEditing(); | |
583 } | |
584 | |
585 super.refresh(element, updateLabels); | |
586 } | |
587 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
588 public override void update(Object element, String[] properties) { |
10 | 589 if (isBusy()) |
590 return; | |
591 super.update(element, properties); | |
592 } | |
593 | |
594 /** | |
595 * Sets the cell editors of this column viewer. If editing is not supported | |
596 * by this viewer the call simply has no effect. | |
597 * | |
598 * <p> | |
599 * Since 3.3, an alternative API is available, see | |
600 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
601 * flexible way of editing values in a column viewer. | |
602 * </p> | |
603 * | |
604 * @param editors | |
605 * the list of cell editors | |
606 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
607 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
608 * @see EditingSupport | |
609 */ | |
610 public void setCellEditors(CellEditor[] editors) { | |
611 this.cellEditors = editors; | |
612 } | |
613 | |
614 /** | |
615 * Sets the cell modifier for this column viewer. This method does nothing | |
616 * if editing is not supported by this viewer. | |
617 * | |
618 * <p> | |
619 * Since 3.3, an alternative API is available, see | |
620 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
621 * flexible way of editing values in a column viewer. | |
622 * </p> | |
623 * | |
624 * @param modifier | |
625 * the cell modifier | |
626 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
627 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
628 * @see EditingSupport | |
629 */ | |
630 public void setCellModifier(ICellModifier modifier) { | |
631 this.cellModifier = modifier; | |
632 } | |
633 | |
634 /** | |
635 * Sets the column properties of this column viewer. The properties must | |
636 * correspond with the columns of the control. They are used to identify the | |
637 * column in a cell modifier. If editing is not supported by this viewer the | |
638 * call simply has no effect. | |
639 * | |
640 * <p> | |
641 * Since 3.3, an alternative API is available, see | |
642 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more | |
643 * flexible way of editing values in a column viewer. | |
644 * </p> | |
645 * | |
646 * @param columnProperties | |
647 * the list of column properties | |
648 * @since 3.1 (in subclasses, added in 3.3 to abstract class) | |
649 * @see ViewerColumn#setEditingSupport(EditingSupport) | |
650 * @see EditingSupport | |
651 */ | |
652 public void setColumnProperties(String[] columnProperties) { | |
653 this.columnProperties = columnProperties; | |
654 } | |
655 | |
656 /** | |
657 * Returns the number of columns contained in the receiver. If no columns | |
658 * were created by the programmer, this value is zero, despite the fact that | |
659 * visually, one column of items may be visible. This occurs when the | |
660 * programmer uses the column viewer like a list, adding elements but never | |
661 * creating a column. | |
662 * | |
663 * @return the number of columns | |
664 * | |
665 * @since 3.3 | |
666 */ | |
667 protected abstract int doGetColumnCount(); | |
668 package int doGetColumnCount_package(){ | |
669 return doGetColumnCount(); | |
670 } | |
671 | |
672 /** | |
673 * Returns the label provider associated with the column at the given index | |
674 * or <code>null</code> if no column with this index is known. | |
675 * | |
676 * @param columnIndex | |
677 * the column index | |
678 * @return the label provider associated with the column or | |
679 * <code>null</code> if no column with this index is known | |
680 * | |
681 * @since 3.3 | |
682 */ | |
683 public CellLabelProvider getLabelProvider(int columnIndex) { | |
684 ViewerColumn column = getViewerColumn(columnIndex); | |
685 if (column !is null) { | |
54
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
53
diff
changeset
|
686 auto res = column.getLabelProvider(); |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
53
diff
changeset
|
687 return res; |
10 | 688 } |
689 return null; | |
690 } | |
691 | |
692 private void handleMouseDown(MouseEvent e) { | |
693 ViewerCell cell = getCell(new Point(e.x, e.y)); | |
694 | |
695 if (cell !is null) { | |
696 triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent( | |
697 cell, e)); | |
698 } | |
699 } | |
700 | |
701 /** | |
702 * Invoking this method fires an editor activation event which tries to | |
703 * enable the editor but before this event is passed to | |
704 * {@link ColumnViewerEditorActivationStrategy} to see if this event should | |
705 * really trigger editor activation | |
706 * | |
707 * @param event | |
708 * the activation event | |
709 */ | |
710 protected void triggerEditorActivationEvent( | |
711 ColumnViewerEditorActivationEvent event) { | |
712 viewerEditor.handleEditorActivationEvent(event); | |
713 } | |
714 package void triggerEditorActivationEvent_package( | |
715 ColumnViewerEditorActivationEvent event) { | |
716 triggerEditorActivationEvent(event); | |
717 } | |
718 | |
719 /** | |
720 * @param columnViewerEditor | |
721 * the new column viewer editor | |
722 */ | |
723 public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) { | |
724 Assert.isNotNull(viewerEditor); | |
725 this.viewerEditor = columnViewerEditor; | |
726 } | |
727 | |
728 /** | |
729 * @return the currently attached viewer editor | |
730 */ | |
731 public ColumnViewerEditor getColumnViewerEditor() { | |
732 return viewerEditor; | |
733 } | |
734 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
735 protected override Object[] getRawChildren(Object parent) { |
10 | 736 bool oldBusy = busy; |
737 busy = true; | |
738 try { | |
739 return super.getRawChildren(parent); | |
740 } finally { | |
741 busy = oldBusy; | |
742 } | |
743 } | |
744 | |
745 /** | |
746 * Clear all cell-editors setup for backwards compatibility in | |
747 * {@link #setupEditingSupport(int, ViewerColumn)}. This has to be done | |
748 * whenever a column is disposed because the index cached when the anonymous | |
749 * class is created has to be readjusted | |
750 */ | |
751 void clearLegacyEditingSetup() { | |
752 int count = doGetColumnCount(); | |
753 | |
754 for( int i = 0; i < count || i is 0; i++ ) { | |
755 Widget owner = getColumnViewerOwner(i); | |
756 | |
757 if( owner !is null && ! owner.isDisposed() ) { | |
758 ViewerColumn column = cast(ViewerColumn) owner.getData(ViewerColumn.COLUMN_VIEWER_KEY); | |
759 if( column !is null ) { | |
760 EditingSupport e = column.getEditingSupport(); | |
761 // Ensure that only EditingSupports are wiped that are setup | |
762 // for Legacy reasons | |
763 if (e !is null && e.isLegacySupport()) { | |
764 column.setEditingSupport(null); | |
765 } | |
766 } | |
767 } | |
768 } | |
769 } | |
770 } |