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
|
|
61 alias StructuredViewer.getLabelProvider getLabelProvider;
|
|
62
|
|
63 private CellEditor[] cellEditors;
|
|
64
|
|
65 private ICellModifier cellModifier;
|
|
66
|
|
67 private String[] columnProperties;
|
|
68
|
|
69 /**
|
|
70 * The cell is a cached viewer cell used for refreshing.
|
|
71 */
|
|
72 private ViewerCell cell;
|
|
73
|
|
74 private ColumnViewerEditor viewerEditor;
|
|
75
|
|
76 /* package */ bool busy;
|
|
77 /* package */ bool logWhenBusy = true; // initially true, set to false after logging for the first time
|
|
78
|
|
79 /**
|
|
80 * Create a new instance of the receiver.
|
|
81 */
|
|
82 public this() {
|
|
83 cell = new ViewerCell(null, 0, null);
|
|
84 }
|
|
85
|
|
86 /* package */ bool isBusy() {
|
|
87 if (busy) {
|
|
88 if (logWhenBusy) {
|
|
89 String message = "Ignored reentrant call while viewer is busy."; //$NON-NLS-1$
|
|
90 if (!InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS) {
|
|
91 // stop logging after the first
|
|
92 logWhenBusy = false;
|
|
93 message ~= " This is only logged once per viewer instance," ~ //$NON-NLS-1$
|
|
94 " but similar calls will still be ignored."; //$NON-NLS-1$
|
|
95 }
|
|
96 Policy.getLog().log(
|
|
97 new Status(
|
|
98 IStatus.WARNING,
|
|
99 Policy.JFACE,
|
|
100 message, new RuntimeException()));
|
|
101 }
|
|
102 return true;
|
|
103 }
|
|
104 return false;
|
|
105 }
|
|
106
|
|
107 protected void hookControl(Control control) {
|
|
108 super.hookControl(control);
|
|
109 viewerEditor = createViewerEditor();
|
|
110 hookEditingSupport(control);
|
|
111 }
|
|
112
|
|
113 /**
|
|
114 * Hook up the editing support. Subclasses may override.
|
|
115 *
|
|
116 * @param control
|
|
117 * the control you want to hook on
|
|
118 */
|
|
119 protected void hookEditingSupport(Control control) {
|
|
120 // Needed for backwards comp with AbstractTreeViewer and TableTreeViewer
|
|
121 // who are not hooked this way others may already overwrite and provide
|
|
122 // their
|
|
123 // own impl
|
|
124 if (viewerEditor !is null) {
|
|
125 control.addMouseListener(new class MouseAdapter {
|
|
126 public void mouseDown(MouseEvent e) {
|
|
127 // Workaround for bug 185817
|
|
128 if( e.count !is 2 ) {
|
|
129 handleMouseDown(e);
|
|
130 }
|
|
131 }
|
|
132
|
|
133 public void mouseDoubleClick(MouseEvent e) {
|
|
134 handleMouseDown(e);
|
|
135 }
|
|
136 });
|
|
137 }
|
|
138 }
|
|
139
|
|
140 /**
|
|
141 * Creates the viewer editor used for editing cell contents. To be
|
|
142 * implemented by subclasses.
|
|
143 *
|
|
144 * @return the editor, or <code>null</code> if this viewer does not
|
|
145 * support editing cell contents.
|
|
146 */
|
|
147 protected abstract ColumnViewerEditor createViewerEditor();
|
|
148
|
|
149 /**
|
|
150 * Returns the viewer cell at the given widget-relative coordinates, or
|
|
151 * <code>null</code> if there is no cell at that location
|
|
152 *
|
|
153 * @param point
|
|
154 * the widget-relative coordinates
|
|
155 * @return the cell or <code>null</code> if no cell is found at the given
|
|
156 * point
|
|
157 */
|
|
158 ViewerCell getCell(Point point) {
|
|
159 ViewerRow row = getViewerRow(point);
|
|
160 if (row !is null) {
|
|
161 return row.getCell(point);
|
|
162 }
|
|
163
|
|
164 return null;
|
|
165 }
|
|
166
|
|
167 /**
|
|
168 * Returns the viewer row at the given widget-relative coordinates.
|
|
169 *
|
|
170 * @param point
|
|
171 * the widget-relative coordinates of the viewer row
|
|
172 * @return ViewerRow the row or <code>null</code> if no row is found at
|
|
173 * the given coordinates
|
|
174 */
|
|
175 protected ViewerRow getViewerRow(Point point) {
|
|
176 Item item = getItemAt(point);
|
|
177
|
|
178 if (item !is null) {
|
|
179 return getViewerRowFromItem(item);
|
|
180 }
|
|
181
|
|
182 return null;
|
|
183 }
|
|
184 package ViewerRow getViewerRow_package(Point point) {
|
|
185 return getViewerRow(point);
|
|
186 }
|
|
187
|
|
188
|
|
189
|
|
190 /**
|
|
191 * Returns a {@link ViewerRow} associated with the given row widget. Implementations
|
|
192 * may re-use the same instance for different row widgets; callers can only use the viewer
|
|
193 * row locally and until the next call to this method.
|
|
194 *
|
|
195 * @param item the row widget
|
|
196 * @return ViewerRow a viewer row object
|
|
197 */
|
|
198 protected abstract ViewerRow getViewerRowFromItem(Widget item);
|
|
199 package ViewerRow getViewerRowFromItem_package(Widget item){
|
|
200 return getViewerRowFromItem(item);
|
|
201 }
|
|
202
|
|
203 /**
|
|
204 * Returns the column widget at the given column index.
|
|
205 *
|
|
206 * @param columnIndex
|
|
207 * the column index
|
|
208 * @return Widget the column widget
|
|
209 */
|
|
210 protected abstract Widget getColumnViewerOwner(int columnIndex);
|
|
211
|
|
212 /**
|
|
213 * Returns the viewer column for the given column index.
|
|
214 *
|
|
215 * @param columnIndex
|
|
216 * the column index
|
|
217 * @return the viewer column at the given index, or <code>null</code> if
|
|
218 * there is none for the given index
|
|
219 */
|
|
220 /* package */ViewerColumn getViewerColumn(int columnIndex) {
|
|
221
|
|
222 ViewerColumn viewer;
|
|
223 Widget columnOwner = getColumnViewerOwner(columnIndex);
|
|
224
|
|
225 if (columnOwner is null) {
|
|
226 return null;
|
|
227 }
|
|
228
|
|
229 viewer = cast(ViewerColumn) columnOwner
|
|
230 .getData(ViewerColumn.COLUMN_VIEWER_KEY);
|
|
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) {
|
|
254 viewer.setEditingSupport(new class(this) EditingSupport {
|
|
255 int columnIndex_;
|
|
256 this(ColumnViewer cv){
|
|
257 super(cv);
|
|
258 columnIndex_=columnIndex;
|
|
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 */
|
|
379 protected Item getItem(int x, int y) {
|
|
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 */
|
|
404 public void setLabelProvider(IBaseLabelProvider labelProvider) {
|
|
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
|
|
566 public void refresh(Object element) {
|
|
567 if (isBusy())
|
|
568 return;
|
|
569
|
|
570 if( isCellEditorActive() ) {
|
|
571 cancelEditing();
|
|
572 }
|
|
573
|
|
574 super.refresh(element);
|
|
575 }
|
|
576
|
|
577 public void refresh(Object element, bool updateLabels) {
|
|
578 if (isBusy())
|
|
579 return;
|
|
580
|
|
581 if( isCellEditorActive() ) {
|
|
582 cancelEditing();
|
|
583 }
|
|
584
|
|
585 super.refresh(element, updateLabels);
|
|
586 }
|
|
587
|
|
588 public void update(Object element, String[] properties) {
|
|
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) {
|
|
686 return column.getLabelProvider();
|
|
687 }
|
|
688 return null;
|
|
689 }
|
|
690
|
|
691 private void handleMouseDown(MouseEvent e) {
|
|
692 ViewerCell cell = getCell(new Point(e.x, e.y));
|
|
693
|
|
694 if (cell !is null) {
|
|
695 triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
|
|
696 cell, e));
|
|
697 }
|
|
698 }
|
|
699
|
|
700 /**
|
|
701 * Invoking this method fires an editor activation event which tries to
|
|
702 * enable the editor but before this event is passed to
|
|
703 * {@link ColumnViewerEditorActivationStrategy} to see if this event should
|
|
704 * really trigger editor activation
|
|
705 *
|
|
706 * @param event
|
|
707 * the activation event
|
|
708 */
|
|
709 protected void triggerEditorActivationEvent(
|
|
710 ColumnViewerEditorActivationEvent event) {
|
|
711 viewerEditor.handleEditorActivationEvent(event);
|
|
712 }
|
|
713 package void triggerEditorActivationEvent_package(
|
|
714 ColumnViewerEditorActivationEvent event) {
|
|
715 triggerEditorActivationEvent(event);
|
|
716 }
|
|
717
|
|
718 /**
|
|
719 * @param columnViewerEditor
|
|
720 * the new column viewer editor
|
|
721 */
|
|
722 public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) {
|
|
723 Assert.isNotNull(viewerEditor);
|
|
724 this.viewerEditor = columnViewerEditor;
|
|
725 }
|
|
726
|
|
727 /**
|
|
728 * @return the currently attached viewer editor
|
|
729 */
|
|
730 public ColumnViewerEditor getColumnViewerEditor() {
|
|
731 return viewerEditor;
|
|
732 }
|
|
733
|
|
734 protected Object[] getRawChildren(Object parent) {
|
|
735 bool oldBusy = busy;
|
|
736 busy = true;
|
|
737 try {
|
|
738 return super.getRawChildren(parent);
|
|
739 } finally {
|
|
740 busy = oldBusy;
|
|
741 }
|
|
742 }
|
|
743
|
|
744 /**
|
|
745 * Clear all cell-editors setup for backwards compatibility in
|
|
746 * {@link #setupEditingSupport(int, ViewerColumn)}. This has to be done
|
|
747 * whenever a column is disposed because the index cached when the anonymous
|
|
748 * class is created has to be readjusted
|
|
749 */
|
|
750 void clearLegacyEditingSetup() {
|
|
751 int count = doGetColumnCount();
|
|
752
|
|
753 for( int i = 0; i < count || i is 0; i++ ) {
|
|
754 Widget owner = getColumnViewerOwner(i);
|
|
755
|
|
756 if( owner !is null && ! owner.isDisposed() ) {
|
|
757 ViewerColumn column = cast(ViewerColumn) owner.getData(ViewerColumn.COLUMN_VIEWER_KEY);
|
|
758 if( column !is null ) {
|
|
759 EditingSupport e = column.getEditingSupport();
|
|
760 // Ensure that only EditingSupports are wiped that are setup
|
|
761 // for Legacy reasons
|
|
762 if (e !is null && e.isLegacySupport()) {
|
|
763 column.setEditingSupport(null);
|
|
764 }
|
|
765 }
|
|
766 }
|
|
767 }
|
|
768 }
|
|
769 }
|