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;
|
14
|
62 alias StructuredViewer.refresh refresh;
|
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
|
|
108 protected void hookControl(Control control) {
|
|
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
|
|
230 viewer = cast(ViewerColumn) columnOwner
|
|
231 .getData(ViewerColumn.COLUMN_VIEWER_KEY);
|
|
232
|
|
233 if (viewer is null) {
|
|
234 viewer = createViewerColumn(columnOwner, CellLabelProvider
|
|
235 .createViewerLabelProvider(this, getLabelProvider()));
|
|
236 setupEditingSupport(columnIndex, viewer);
|
|
237 }
|
|
238
|
|
239 if (viewer.getEditingSupport() is null && getCellModifier() !is null) {
|
|
240 setupEditingSupport(columnIndex, viewer);
|
|
241 }
|
|
242
|
|
243 return viewer;
|
|
244 }
|
|
245
|
|
246 /**
|
|
247 * Sets up editing support for the given column based on the "old" cell
|
|
248 * editor API.
|
|
249 *
|
|
250 * @param columnIndex
|
|
251 * @param viewer
|
|
252 */
|
|
253 private void setupEditingSupport(int columnIndex, ViewerColumn viewer) {
|
|
254 if (getCellModifier() !is null) {
|
39
|
255 viewer.setEditingSupport(new class(this,columnIndex) EditingSupport {
|
10
|
256 int columnIndex_;
|
39
|
257 this(ColumnViewer cv, int ci){
|
10
|
258 super(cv);
|
39
|
259 columnIndex_=ci;
|
10
|
260 }
|
|
261 /*
|
|
262 * (non-Javadoc)
|
|
263 *
|
|
264 * @see dwtx.jface.viewers.EditingSupport#canEdit(java.lang.Object)
|
|
265 */
|
|
266 public bool canEdit(Object element) {
|
|
267 Object[] properties = getColumnProperties();
|
|
268
|
|
269 if( columnIndex_ < properties.length ) {
|
|
270 return getCellModifier().canModify(element,
|
|
271 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array);
|
|
272 }
|
|
273
|
|
274 return false;
|
|
275 }
|
|
276
|
|
277 /*
|
|
278 * (non-Javadoc)
|
|
279 *
|
|
280 * @see dwtx.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
|
|
281 */
|
|
282 public CellEditor getCellEditor(Object element) {
|
|
283 CellEditor[] editors = getCellEditors();
|
|
284 if( columnIndex_ < editors.length ) {
|
|
285 return getCellEditors()[columnIndex_];
|
|
286 }
|
|
287 return null;
|
|
288 }
|
|
289
|
|
290 /*
|
|
291 * (non-Javadoc)
|
|
292 *
|
|
293 * @see dwtx.jface.viewers.EditingSupport#getValue(java.lang.Object)
|
|
294 */
|
|
295 public Object getValue(Object element) {
|
|
296 Object[] properties = getColumnProperties();
|
|
297
|
|
298 if( columnIndex_ < properties.length ) {
|
|
299 return getCellModifier().getValue(element,
|
|
300 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array);
|
|
301 }
|
|
302
|
|
303 return null;
|
|
304 }
|
|
305
|
|
306 /*
|
|
307 * (non-Javadoc)
|
|
308 *
|
|
309 * @see dwtx.jface.viewers.EditingSupport#setValue(java.lang.Object,
|
|
310 * java.lang.Object)
|
|
311 */
|
|
312 public void setValue(Object element, Object value) {
|
|
313 Object[] properties = getColumnProperties();
|
|
314
|
|
315 if( columnIndex_ < properties.length ) {
|
|
316 getCellModifier().modify(findItem(element),
|
|
317 (cast(ArrayWrapperString) getColumnProperties()[columnIndex_]).array, value);
|
|
318 }
|
|
319 }
|
|
320
|
|
321 bool isLegacySupport() {
|
|
322 return true;
|
|
323 }
|
|
324 });
|
|
325 }
|
|
326 }
|
|
327
|
|
328 /**
|
|
329 * Creates a generic viewer column for the given column widget, based on the
|
|
330 * given label provider.
|
|
331 *
|
|
332 * @param columnOwner
|
|
333 * the column widget
|
|
334 * @param labelProvider
|
|
335 * the label provider to use for the column
|
|
336 * @return ViewerColumn the viewer column
|
|
337 */
|
|
338 private ViewerColumn createViewerColumn(Widget columnOwner,
|
|
339 CellLabelProvider labelProvider) {
|
|
340 ViewerColumn column = new class(this, columnOwner) ViewerColumn {
|
|
341 this( ColumnViewer cv, Widget co ){
|
|
342 super(cv,co);
|
|
343 }
|
|
344 };
|
|
345 column.setLabelProvider(labelProvider, false);
|
|
346 return column;
|
|
347 }
|
|
348
|
|
349 /**
|
|
350 * Update the cached cell object with the given row and column. Be careful not
|
|
351 * to hold on to element objects longer than required. It is good practice to
|
|
352 * call updateCell(null, 0, null) to clear references immediately after using
|
|
353 * the cached cell object. (See bug 201280 for an example case where this happened.)
|
|
354 *
|
|
355 * @param rowItem
|
|
356 * @param column
|
|
357 * @return ViewerCell
|
|
358 */
|
|
359 /* package */ViewerCell updateCell(ViewerRow rowItem, int column, Object element) {
|
|
360 cell.update(rowItem, column, element);
|
|
361 return cell;
|
|
362 }
|
|
363
|
|
364 /**
|
|
365 * Returns the {@link Item} at the given widget-relative coordinates, or
|
|
366 * <code>null</code> if there is no item at the given coordinates.
|
|
367 *
|
|
368 * @param point
|
|
369 * the widget-relative coordinates
|
|
370 * @return the {@link Item} at the coordinates or <code>null</code> if
|
|
371 * there is no item at the given coordinates
|
|
372 */
|
|
373 protected abstract Item getItemAt(Point point);
|
|
374
|
|
375 /*
|
|
376 * (non-Javadoc)
|
|
377 *
|
|
378 * @see dwtx.jface.viewers.StructuredViewer#getItem(int, int)
|
|
379 */
|
|
380 protected Item getItem(int x, int y) {
|
|
381 return getItemAt(getControl().toControl(x, y));
|
|
382 }
|
|
383
|
|
384 /**
|
|
385 * The column viewer implementation of this <code>Viewer</code> framework
|
|
386 * method ensures that the given label provider is an instance of
|
|
387 * <code>ITableLabelProvider</code>, <code>ILabelProvider</code>, or
|
|
388 * <code>CellLabelProvider</code>.
|
|
389 * <p>
|
|
390 * If the label provider is an {@link ITableLabelProvider}, then it
|
|
391 * provides a separate label text and image for each column. Implementers of
|
|
392 * <code>ITableLabelProvider</code> may also implement
|
|
393 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide
|
|
394 * colors and/or fonts.
|
|
395 * </p>
|
|
396 * <p>
|
|
397 * If the label provider is an <code>ILabelProvider</code>, then it
|
|
398 * provides only the label text and image for the first column, and any
|
|
399 * remaining columns are blank. Implementers of <code>ILabelProvider</code>
|
|
400 * may also implement {@link IColorProvider} and/or {@link IFontProvider} to
|
|
401 * provide colors and/or fonts.
|
|
402 * </p>
|
|
403 *
|
|
404 */
|
|
405 public void setLabelProvider(IBaseLabelProvider labelProvider) {
|
|
406 Assert.isTrue( null !is cast(ITableLabelProvider)labelProvider
|
|
407 || null !is cast(ILabelProvider)labelProvider
|
|
408 || null !is cast(CellLabelProvider)labelProvider );
|
|
409 updateColumnParts(labelProvider);// Reset the label providers in the
|
|
410 // columns
|
|
411 super.setLabelProvider(labelProvider);
|
|
412 }
|
|
413
|
|
414 /**
|
|
415 * Clear the viewer parts for the columns
|
|
416 */
|
|
417 private void updateColumnParts(IBaseLabelProvider labelProvider) {
|
|
418 ViewerColumn column;
|
|
419 int i = 0;
|
|
420
|
|
421 while ((column = getViewerColumn(i++)) !is null) {
|
|
422 column.setLabelProvider(CellLabelProvider
|
|
423 .createViewerLabelProvider(this, labelProvider), false);
|
|
424 }
|
|
425 }
|
|
426
|
|
427 /**
|
|
428 * Cancels a currently active cell editor if one is active. All changes
|
|
429 * already done in the cell editor are lost.
|
|
430 *
|
|
431 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
432 */
|
|
433 public void cancelEditing() {
|
|
434 if (viewerEditor !is null) {
|
|
435 viewerEditor.cancelEditing();
|
|
436 }
|
|
437 }
|
|
438
|
|
439 /**
|
|
440 * Apply the value of the active cell editor if one is active.
|
|
441 *
|
|
442 * @since 3.3
|
|
443 */
|
|
444 protected void applyEditorValue() {
|
|
445 if (viewerEditor !is null) {
|
|
446 viewerEditor.applyEditorValue();
|
|
447 }
|
|
448 }
|
|
449
|
|
450 /**
|
|
451 * Starts editing the given element at the given column index.
|
|
452 *
|
|
453 * @param element
|
|
454 * the model element
|
|
455 * @param column
|
|
456 * the column index
|
|
457 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
458 */
|
|
459 public void editElement(Object element, int column) {
|
|
460 if (viewerEditor !is null) {
|
|
461 try {
|
|
462 getControl().setRedraw(false);
|
|
463 // Set the selection at first because in Tree's
|
|
464 // the element might not be materialized
|
|
465 setSelection(new StructuredSelection(element),true);
|
|
466
|
|
467 Widget item = findItem(element);
|
|
468 if (item !is null) {
|
|
469 ViewerRow row = getViewerRowFromItem(item);
|
|
470 if (row !is null) {
|
|
471 ViewerCell cell = row.getCell(column);
|
|
472 if (cell !is null) {
|
|
473 triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
|
|
474 cell));
|
|
475 }
|
|
476 }
|
|
477 }
|
|
478 } finally {
|
|
479 getControl().setRedraw(true);
|
|
480 }
|
|
481 }
|
|
482 }
|
|
483
|
|
484 /**
|
|
485 * Return the CellEditors for the receiver, or <code>null</code> if no
|
|
486 * cell editors are set.
|
|
487 * <p>
|
|
488 * Since 3.3, an alternative API is available, see
|
|
489 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
490 * flexible way of editing values in a column viewer.
|
|
491 * </p>
|
|
492 *
|
|
493 * @return CellEditor[]
|
|
494 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
495 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
496 * @see EditingSupport
|
|
497 */
|
|
498 public CellEditor[] getCellEditors() {
|
|
499 return cellEditors;
|
|
500 }
|
|
501
|
|
502 /**
|
|
503 * Returns the cell modifier of this viewer, or <code>null</code> if none
|
|
504 * has been set.
|
|
505 *
|
|
506 * <p>
|
|
507 * Since 3.3, an alternative API is available, see
|
|
508 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
509 * flexible way of editing values in a column viewer.
|
|
510 * </p>
|
|
511 *
|
|
512 * @return the cell modifier, or <code>null</code>
|
|
513 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
514 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
515 * @see EditingSupport
|
|
516 */
|
|
517 public ICellModifier getCellModifier() {
|
|
518 return cellModifier;
|
|
519 }
|
|
520
|
|
521 /**
|
|
522 * Returns the column properties of this table viewer. The properties must
|
|
523 * correspond with the columns of the table control. They are used to
|
|
524 * identify the column in a cell modifier.
|
|
525 *
|
|
526 * <p>
|
|
527 * Since 3.3, an alternative API is available, see
|
|
528 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
529 * flexible way of editing values in a column viewer.
|
|
530 * </p>
|
|
531 *
|
|
532 * @return the list of column properties
|
|
533 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
534 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
535 * @see EditingSupport
|
|
536 */
|
|
537 public Object[] getColumnProperties() {
|
|
538 Object[] res;
|
|
539 foreach( prop; columnProperties ){
|
|
540 res ~= new ArrayWrapperString( prop );
|
|
541 }
|
|
542 return res;
|
|
543 }
|
|
544
|
|
545 /**
|
|
546 * Returns whether there is an active cell editor.
|
|
547 *
|
|
548 * <p>
|
|
549 * Since 3.3, an alternative API is available, see
|
|
550 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
551 * flexible way of editing values in a column viewer.
|
|
552 * </p>
|
|
553 *
|
|
554 * @return <code>true</code> if there is an active cell editor, and
|
|
555 * <code>false</code> otherwise
|
|
556 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
557 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
558 * @see EditingSupport
|
|
559 */
|
|
560 public bool isCellEditorActive() {
|
|
561 if (viewerEditor !is null) {
|
|
562 return viewerEditor.isCellEditorActive();
|
|
563 }
|
|
564 return false;
|
|
565 }
|
|
566
|
|
567 public void refresh(Object element) {
|
|
568 if (isBusy())
|
|
569 return;
|
|
570
|
|
571 if( isCellEditorActive() ) {
|
|
572 cancelEditing();
|
|
573 }
|
|
574
|
|
575 super.refresh(element);
|
|
576 }
|
|
577
|
|
578 public void refresh(Object element, bool updateLabels) {
|
|
579 if (isBusy())
|
|
580 return;
|
|
581
|
|
582 if( isCellEditorActive() ) {
|
|
583 cancelEditing();
|
|
584 }
|
|
585
|
|
586 super.refresh(element, updateLabels);
|
|
587 }
|
|
588
|
|
589 public void update(Object element, String[] properties) {
|
|
590 if (isBusy())
|
|
591 return;
|
|
592 super.update(element, properties);
|
|
593 }
|
|
594
|
|
595 /**
|
|
596 * Sets the cell editors of this column viewer. If editing is not supported
|
|
597 * by this viewer the call simply has no effect.
|
|
598 *
|
|
599 * <p>
|
|
600 * Since 3.3, an alternative API is available, see
|
|
601 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
602 * flexible way of editing values in a column viewer.
|
|
603 * </p>
|
|
604 *
|
|
605 * @param editors
|
|
606 * the list of cell editors
|
|
607 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
608 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
609 * @see EditingSupport
|
|
610 */
|
|
611 public void setCellEditors(CellEditor[] editors) {
|
|
612 this.cellEditors = editors;
|
|
613 }
|
|
614
|
|
615 /**
|
|
616 * Sets the cell modifier for this column viewer. This method does nothing
|
|
617 * if editing is not supported by this viewer.
|
|
618 *
|
|
619 * <p>
|
|
620 * Since 3.3, an alternative API is available, see
|
|
621 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
622 * flexible way of editing values in a column viewer.
|
|
623 * </p>
|
|
624 *
|
|
625 * @param modifier
|
|
626 * the cell modifier
|
|
627 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
628 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
629 * @see EditingSupport
|
|
630 */
|
|
631 public void setCellModifier(ICellModifier modifier) {
|
|
632 this.cellModifier = modifier;
|
|
633 }
|
|
634
|
|
635 /**
|
|
636 * Sets the column properties of this column viewer. The properties must
|
|
637 * correspond with the columns of the control. They are used to identify the
|
|
638 * column in a cell modifier. If editing is not supported by this viewer the
|
|
639 * call simply has no effect.
|
|
640 *
|
|
641 * <p>
|
|
642 * Since 3.3, an alternative API is available, see
|
|
643 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
|
|
644 * flexible way of editing values in a column viewer.
|
|
645 * </p>
|
|
646 *
|
|
647 * @param columnProperties
|
|
648 * the list of column properties
|
|
649 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
|
|
650 * @see ViewerColumn#setEditingSupport(EditingSupport)
|
|
651 * @see EditingSupport
|
|
652 */
|
|
653 public void setColumnProperties(String[] columnProperties) {
|
|
654 this.columnProperties = columnProperties;
|
|
655 }
|
|
656
|
|
657 /**
|
|
658 * Returns the number of columns contained in the receiver. If no columns
|
|
659 * were created by the programmer, this value is zero, despite the fact that
|
|
660 * visually, one column of items may be visible. This occurs when the
|
|
661 * programmer uses the column viewer like a list, adding elements but never
|
|
662 * creating a column.
|
|
663 *
|
|
664 * @return the number of columns
|
|
665 *
|
|
666 * @since 3.3
|
|
667 */
|
|
668 protected abstract int doGetColumnCount();
|
|
669 package int doGetColumnCount_package(){
|
|
670 return doGetColumnCount();
|
|
671 }
|
|
672
|
|
673 /**
|
|
674 * Returns the label provider associated with the column at the given index
|
|
675 * or <code>null</code> if no column with this index is known.
|
|
676 *
|
|
677 * @param columnIndex
|
|
678 * the column index
|
|
679 * @return the label provider associated with the column or
|
|
680 * <code>null</code> if no column with this index is known
|
|
681 *
|
|
682 * @since 3.3
|
|
683 */
|
|
684 public CellLabelProvider getLabelProvider(int columnIndex) {
|
|
685 ViewerColumn column = getViewerColumn(columnIndex);
|
|
686 if (column !is null) {
|
|
687 return column.getLabelProvider();
|
|
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
|
|
735 protected Object[] getRawChildren(Object parent) {
|
|
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 }
|