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