|
Lines 15-25
Link Here
|
| 15 |
package org.eclipse.jface.viewers; |
15 |
package org.eclipse.jface.viewers; |
| 16 |
|
16 |
|
| 17 |
import org.eclipse.core.runtime.Assert; |
17 |
import org.eclipse.core.runtime.Assert; |
| 18 |
import org.eclipse.swt.events.MouseAdapter; |
18 |
import org.eclipse.core.runtime.ListenerList; |
| 19 |
import org.eclipse.swt.events.MouseEvent; |
19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.graphics.Point; |
20 |
import org.eclipse.swt.graphics.Point; |
| 21 |
import org.eclipse.swt.widgets.Control; |
21 |
import org.eclipse.swt.widgets.Control; |
|
|
22 |
import org.eclipse.swt.widgets.Event; |
| 22 |
import org.eclipse.swt.widgets.Item; |
23 |
import org.eclipse.swt.widgets.Item; |
|
|
24 |
import org.eclipse.swt.widgets.Listener; |
| 23 |
import org.eclipse.swt.widgets.Widget; |
25 |
import org.eclipse.swt.widgets.Widget; |
| 24 |
|
26 |
|
| 25 |
/** |
27 |
/** |
|
Lines 49-55
Link Here
|
| 49 |
private AbstractViewerEditor viewerEditor; |
51 |
private AbstractViewerEditor viewerEditor; |
| 50 |
|
52 |
|
| 51 |
private int tabEditingStyle = EditingSupport.TABING_NONE; |
53 |
private int tabEditingStyle = EditingSupport.TABING_NONE; |
| 52 |
|
54 |
|
|
|
55 |
private ListenerList cellSelectionListeners; |
| 56 |
|
| 57 |
private static EditorActivationStrategy defaultStrategy = new EditorActivationStrategy() { |
| 58 |
|
| 59 |
protected boolean isEditorActivationEvent(CellSelectionEvent event) { |
| 60 |
return event.swtEvent.type == SWT.MouseDown; |
| 61 |
} |
| 62 |
|
| 63 |
}; |
| 64 |
|
| 65 |
private EditorActivationStrategy editorActivationStrategy = defaultStrategy; |
| 66 |
|
| 53 |
/** |
67 |
/** |
| 54 |
* Create a new instance of the receiver. |
68 |
* Create a new instance of the receiver. |
| 55 |
*/ |
69 |
*/ |
|
Lines 74-91
Link Here
|
| 74 |
// their |
88 |
// their |
| 75 |
// own impl |
89 |
// own impl |
| 76 |
if (viewerEditor != null) { |
90 |
if (viewerEditor != null) { |
| 77 |
control.addMouseListener(new MouseAdapter() { |
91 |
Listener l = new Listener() { |
| 78 |
public void mouseDown(MouseEvent e) { |
92 |
|
| 79 |
viewerEditor.handleMouseDown(e); |
93 |
public void handleEvent(Event event) { |
|
|
94 |
handleMouseDown(event); |
| 80 |
} |
95 |
} |
| 81 |
}); |
96 |
|
|
|
97 |
}; |
| 98 |
|
| 99 |
control.addListener(SWT.MouseDown, l); |
| 100 |
control.addListener(SWT.MouseDoubleClick, l); |
| 101 |
|
| 102 |
addCellSelectionListener(new EditingListener()); |
| 82 |
} |
103 |
} |
| 83 |
} |
104 |
} |
| 84 |
|
105 |
|
| 85 |
/** |
106 |
/** |
| 86 |
* Creates the viewer editor used for editing cell contents. To be implemented by subclasses. |
107 |
* Creates the viewer editor used for editing cell contents. To be |
|
|
108 |
* implemented by subclasses. |
| 87 |
* |
109 |
* |
| 88 |
* @return the editor, or <code>null</code> if this viewer does not support editing cell contents. |
110 |
* @return the editor, or <code>null</code> if this viewer does not |
|
|
111 |
* support editing cell contents. |
| 89 |
*/ |
112 |
*/ |
| 90 |
protected abstract AbstractViewerEditor createViewerEditor(); |
113 |
protected abstract AbstractViewerEditor createViewerEditor(); |
| 91 |
|
114 |
|
|
Lines 95-101
Link Here
|
| 95 |
* |
118 |
* |
| 96 |
* @param point |
119 |
* @param point |
| 97 |
* the widget-relative coordinates |
120 |
* the widget-relative coordinates |
| 98 |
* @return the cell or <code>null</code> if no cell is found at the given point |
121 |
* @return the cell or <code>null</code> if no cell is found at the given |
|
|
122 |
* point |
| 99 |
*/ |
123 |
*/ |
| 100 |
ViewerCell getCell(Point point) { |
124 |
ViewerCell getCell(Point point) { |
| 101 |
ViewerRow row = getViewerRow(point); |
125 |
ViewerRow row = getViewerRow(point); |
|
Lines 127-133
Link Here
|
| 127 |
/** |
151 |
/** |
| 128 |
* Returns the viewer row associated with the given row widget. |
152 |
* Returns the viewer row associated with the given row widget. |
| 129 |
* |
153 |
* |
| 130 |
* @param item the row widget |
154 |
* @param item |
|
|
155 |
* the row widget |
| 131 |
* @return ViewerRow the associated viewer row |
156 |
* @return ViewerRow the associated viewer row |
| 132 |
*/ |
157 |
*/ |
| 133 |
protected ViewerRow getViewerRowFromItem(Widget item) { |
158 |
protected ViewerRow getViewerRowFromItem(Widget item) { |
|
Lines 137-143
Link Here
|
| 137 |
/** |
162 |
/** |
| 138 |
* Returns the column widget at the given column index. |
163 |
* Returns the column widget at the given column index. |
| 139 |
* |
164 |
* |
| 140 |
* @param columnIndex the column index |
165 |
* @param columnIndex |
|
|
166 |
* the column index |
| 141 |
* @return Widget the column widget |
167 |
* @return Widget the column widget |
| 142 |
*/ |
168 |
*/ |
| 143 |
protected abstract Widget getColumnViewerOwner(int columnIndex); |
169 |
protected abstract Widget getColumnViewerOwner(int columnIndex); |
|
Lines 150-156
Link Here
|
| 150 |
* @return the viewer column at the given index, or <code>null</code> if |
176 |
* @return the viewer column at the given index, or <code>null</code> if |
| 151 |
* there is none for the given index |
177 |
* there is none for the given index |
| 152 |
*/ |
178 |
*/ |
| 153 |
/* package */ ViewerColumn getViewerColumn(final int columnIndex) { |
179 |
/* package */ViewerColumn getViewerColumn(final int columnIndex) { |
| 154 |
|
180 |
|
| 155 |
ViewerColumn viewer; |
181 |
ViewerColumn viewer; |
| 156 |
Widget columnOwner = getColumnViewerOwner(columnIndex); |
182 |
Widget columnOwner = getColumnViewerOwner(columnIndex); |
|
Lines 176-182
Link Here
|
| 176 |
} |
202 |
} |
| 177 |
|
203 |
|
| 178 |
/** |
204 |
/** |
| 179 |
* Sets up editing support for the given column based on the "old" cell editor API. |
205 |
* Sets up editing support for the given column based on the "old" cell |
|
|
206 |
* editor API. |
| 180 |
* |
207 |
* |
| 181 |
* @param columnIndex |
208 |
* @param columnIndex |
| 182 |
* @param viewer |
209 |
* @param viewer |
|
Lines 229-243
Link Here
|
| 229 |
} |
256 |
} |
| 230 |
|
257 |
|
| 231 |
/** |
258 |
/** |
| 232 |
* Creates a generic viewer column for the given column widget, based on the given label provider. |
259 |
* Creates a generic viewer column for the given column widget, based on the |
|
|
260 |
* given label provider. |
| 233 |
* |
261 |
* |
| 234 |
* @param columnOwner the column widget |
262 |
* @param columnOwner |
| 235 |
* @param labelProvider the label provider to use for the column |
263 |
* the column widget |
|
|
264 |
* @param labelProvider |
| 265 |
* the label provider to use for the column |
| 236 |
* @return ViewerColumn the viewer column |
266 |
* @return ViewerColumn the viewer column |
| 237 |
*/ |
267 |
*/ |
| 238 |
private ViewerColumn createViewerColumn(Widget columnOwner, |
268 |
private ViewerColumn createViewerColumn(Widget columnOwner, |
| 239 |
CellLabelProvider labelProvider) { |
269 |
CellLabelProvider labelProvider) { |
| 240 |
ViewerColumn column = new ViewerColumn(this,columnOwner) {}; |
270 |
ViewerColumn column = new ViewerColumn(this, columnOwner) { |
|
|
271 |
}; |
| 241 |
column.setLabelProvider(labelProvider, false); |
272 |
column.setLabelProvider(labelProvider, false); |
| 242 |
return column; |
273 |
return column; |
| 243 |
} |
274 |
} |
|
Lines 269-287
Link Here
|
| 269 |
* @param column |
300 |
* @param column |
| 270 |
* @return ViewerCell |
301 |
* @return ViewerCell |
| 271 |
*/ |
302 |
*/ |
| 272 |
/* package */ ViewerCell updateCell(ViewerRow rowItem, int column) { |
303 |
/* package */ViewerCell updateCell(ViewerRow rowItem, int column) { |
| 273 |
cell.update(rowItem, column); |
304 |
cell.update(rowItem, column); |
| 274 |
return cell; |
305 |
return cell; |
| 275 |
} |
306 |
} |
| 276 |
|
307 |
|
| 277 |
/** |
308 |
/** |
| 278 |
* Returns the {@link Item} at the given widget-relative coordinates, or |
309 |
* Returns the {@link Item} at the given widget-relative coordinates, or |
| 279 |
* <code>null</code> if there is no item at the given coordinates. |
310 |
* <code>null</code> if there is no item at the given coordinates. |
| 280 |
* |
311 |
* |
| 281 |
* @param point |
312 |
* @param point |
| 282 |
* the widget-relative coordinates |
313 |
* the widget-relative coordinates |
| 283 |
* @return the {@link Item} at the coordinates or <code>null</code> if there |
314 |
* @return the {@link Item} at the coordinates or <code>null</code> if |
| 284 |
* is no item at the given coordinates |
315 |
* there is no item at the given coordinates |
| 285 |
*/ |
316 |
*/ |
| 286 |
protected abstract Item getItemAt(Point point); |
317 |
protected abstract Item getItemAt(Point point); |
| 287 |
|
318 |
|
|
Lines 339-345
Link Here
|
| 339 |
|
370 |
|
| 340 |
/** |
371 |
/** |
| 341 |
* Cancels a currently active cell editor if one is active. All changes |
372 |
* Cancels a currently active cell editor if one is active. All changes |
| 342 |
* already done in the cell editor are lost. |
373 |
* already done in the cell editor are lost. |
| 343 |
* |
374 |
* |
| 344 |
* @since 3.1 (in subclasses, added in 3.3 to abstract class) |
375 |
* @since 3.1 (in subclasses, added in 3.3 to abstract class) |
| 345 |
*/ |
376 |
*/ |
|
Lines 371-387
Link Here
|
| 371 |
*/ |
402 |
*/ |
| 372 |
public void editElement(Object element, int column) { |
403 |
public void editElement(Object element, int column) { |
| 373 |
if (viewerEditor != null) { |
404 |
if (viewerEditor != null) { |
| 374 |
viewerEditor.editElement(element, column); |
405 |
Widget item = findItem(element); |
|
|
406 |
if (item != null) { |
| 407 |
ViewerRow row = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); |
| 408 |
ViewerCell cell = row.getCell(column); |
| 409 |
if (cell != null) { |
| 410 |
viewerEditor.editCell(cell); |
| 411 |
} |
| 412 |
} |
| 375 |
} |
413 |
} |
| 376 |
} |
414 |
} |
| 377 |
|
415 |
|
| 378 |
/** |
416 |
/** |
| 379 |
* Return the CellEditors for the receiver, or <code>null</code> if no |
417 |
* Return the CellEditors for the receiver, or <code>null</code> if no |
| 380 |
* cell editors are set. |
418 |
* cell editors are set. |
| 381 |
* <p> |
419 |
* <p> |
| 382 |
* Since 3.3, an alternative API is available, see |
420 |
* Since 3.3, an alternative API is available, see |
| 383 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
421 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 384 |
* way of editing values in a column viewer. |
422 |
* flexible way of editing values in a column viewer. |
| 385 |
* </p> |
423 |
* </p> |
| 386 |
* |
424 |
* |
| 387 |
* @return CellEditor[] |
425 |
* @return CellEditor[] |
|
Lines 398-409
Link Here
|
| 398 |
|
436 |
|
| 399 |
/** |
437 |
/** |
| 400 |
* Returns the cell modifier of this viewer, or <code>null</code> if none |
438 |
* Returns the cell modifier of this viewer, or <code>null</code> if none |
| 401 |
* has been set. |
439 |
* has been set. |
| 402 |
* |
440 |
* |
| 403 |
* <p> |
441 |
* <p> |
| 404 |
* Since 3.3, an alternative API is available, see |
442 |
* Since 3.3, an alternative API is available, see |
| 405 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
443 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 406 |
* way of editing values in a column viewer. |
444 |
* flexible way of editing values in a column viewer. |
| 407 |
* </p> |
445 |
* </p> |
| 408 |
* |
446 |
* |
| 409 |
* @return the cell modifier, or <code>null</code> |
447 |
* @return the cell modifier, or <code>null</code> |
|
Lines 425-432
Link Here
|
| 425 |
* |
463 |
* |
| 426 |
* <p> |
464 |
* <p> |
| 427 |
* Since 3.3, an alternative API is available, see |
465 |
* Since 3.3, an alternative API is available, see |
| 428 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
466 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 429 |
* way of editing values in a column viewer. |
467 |
* flexible way of editing values in a column viewer. |
| 430 |
* </p> |
468 |
* </p> |
| 431 |
* |
469 |
* |
| 432 |
* @return the list of column properties |
470 |
* @return the list of column properties |
|
Lines 446-453
Link Here
|
| 446 |
* |
484 |
* |
| 447 |
* <p> |
485 |
* <p> |
| 448 |
* Since 3.3, an alternative API is available, see |
486 |
* Since 3.3, an alternative API is available, see |
| 449 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
487 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 450 |
* way of editing values in a column viewer. |
488 |
* flexible way of editing values in a column viewer. |
| 451 |
* </p> |
489 |
* </p> |
| 452 |
* |
490 |
* |
| 453 |
* @return <code>true</code> if there is an active cell editor, and |
491 |
* @return <code>true</code> if there is an active cell editor, and |
|
Lines 469-476
Link Here
|
| 469 |
* |
507 |
* |
| 470 |
* <p> |
508 |
* <p> |
| 471 |
* Since 3.3, an alternative API is available, see |
509 |
* Since 3.3, an alternative API is available, see |
| 472 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
510 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 473 |
* way of editing values in a column viewer. |
511 |
* flexible way of editing values in a column viewer. |
| 474 |
* </p> |
512 |
* </p> |
| 475 |
* |
513 |
* |
| 476 |
* @param editors |
514 |
* @param editors |
|
Lines 486-498
Link Here
|
| 486 |
} |
524 |
} |
| 487 |
|
525 |
|
| 488 |
/** |
526 |
/** |
| 489 |
* Sets the cell modifier for this column viewer. This method does nothing if editing |
527 |
* Sets the cell modifier for this column viewer. This method does nothing |
| 490 |
* is not supported by this viewer. |
528 |
* if editing is not supported by this viewer. |
| 491 |
* |
529 |
* |
| 492 |
* <p> |
530 |
* <p> |
| 493 |
* Since 3.3, an alternative API is available, see |
531 |
* Since 3.3, an alternative API is available, see |
| 494 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
532 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 495 |
* way of editing values in a column viewer. |
533 |
* flexible way of editing values in a column viewer. |
| 496 |
* </p> |
534 |
* </p> |
| 497 |
* |
535 |
* |
| 498 |
* @param modifier |
536 |
* @param modifier |
|
Lines 515-522
Link Here
|
| 515 |
* |
553 |
* |
| 516 |
* <p> |
554 |
* <p> |
| 517 |
* Since 3.3, an alternative API is available, see |
555 |
* Since 3.3, an alternative API is available, see |
| 518 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible |
556 |
* {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more |
| 519 |
* way of editing values in a column viewer. |
557 |
* flexible way of editing values in a column viewer. |
| 520 |
* </p> |
558 |
* </p> |
| 521 |
* |
559 |
* |
| 522 |
* @param columnProperties |
560 |
* @param columnProperties |
|
Lines 530-536
Link Here
|
| 530 |
viewerEditor.setColumnProperties(columnProperties); |
568 |
viewerEditor.setColumnProperties(columnProperties); |
| 531 |
} |
569 |
} |
| 532 |
} |
570 |
} |
| 533 |
|
571 |
|
| 534 |
/** |
572 |
/** |
| 535 |
* The tab-editing style used if the default implementation is used |
573 |
* The tab-editing style used if the default implementation is used |
| 536 |
* |
574 |
* |
|
Lines 544-547
Link Here
|
| 544 |
int getTabEditingStyle() { |
582 |
int getTabEditingStyle() { |
| 545 |
return this.tabEditingStyle; |
583 |
return this.tabEditingStyle; |
| 546 |
} |
584 |
} |
|
|
585 |
|
| 586 |
/** |
| 587 |
* Adding a cell selection listener |
| 588 |
* |
| 589 |
* @param listener |
| 590 |
* listener for cell selections |
| 591 |
*/ |
| 592 |
public void addCellSelectionListener(ICellSelectionListener listener) { |
| 593 |
if (cellSelectionListeners == null) { |
| 594 |
cellSelectionListeners = new ListenerList(); |
| 595 |
} |
| 596 |
this.cellSelectionListeners.add(listener); |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Remove the cell selection listener |
| 601 |
* |
| 602 |
* @param listener |
| 603 |
* listener for cell selections |
| 604 |
*/ |
| 605 |
public void removeCellSelectionListener(ICellSelectionListener listener) { |
| 606 |
this.cellSelectionListeners.remove(listener); |
| 607 |
} |
| 608 |
|
| 609 |
private void handleMouseDown(Event event) { |
| 610 |
Point p = new Point(event.x, event.y); |
| 611 |
|
| 612 |
ViewerRow row = getViewerRow(p); |
| 613 |
|
| 614 |
if (row != null) { |
| 615 |
ViewerCell cell = row.getCell(p); |
| 616 |
|
| 617 |
if (cell != null) { |
| 618 |
fireCellSelectionEvent(new CellSelectionEvent(this, cell, event)); |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
private void fireCellSelectionEvent(CellSelectionEvent event) { |
| 624 |
if (!cellSelectionListeners.isEmpty()) { |
| 625 |
Object[] listeners = cellSelectionListeners.getListeners(); |
| 626 |
for (int i = 0; i < listeners.length; i++) { |
| 627 |
((ICellSelectionListener) listeners[i]).cellSelected(event); |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
/** |
| 633 |
* Set the strategy used to determine if the editor should be activated |
| 634 |
* because of a {@link CellSelectionEvent} |
| 635 |
* |
| 636 |
* @param editorActivationStrategy |
| 637 |
* the new strategy to activate an editor. <code>null</code> is |
| 638 |
* allowed and will but the viewer in a none-editable mode |
| 639 |
*/ |
| 640 |
public void setEditorActivationStrategy( |
| 641 |
EditorActivationStrategy editorActivationStrategy) { |
| 642 |
this.editorActivationStrategy = editorActivationStrategy; |
| 643 |
} |
| 644 |
|
| 645 |
private class EditingListener implements ICellSelectionListener { |
| 646 |
|
| 647 |
public void cellSelected(CellSelectionEvent event) { |
| 648 |
if (event != null && event.cell != null && event.swtEvent != null && viewerEditor != null |
| 649 |
&& editorActivationStrategy != null |
| 650 |
&& editorActivationStrategy.isEditorActivationEvent(event)) { |
| 651 |
viewerEditor.handleCellSelectionEvent(event); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 547 |
} |
655 |
} |