Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 151377 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-4 / +9 lines)
Lines 137-146 Link Here
137
				return table.getSelection();
137
				return table.getSelection();
138
			}
138
			}
139
139
140
			protected void setEditor(Control w, Item item, int fColumnNumber) {
141
				tableEditor.setEditor(w, (TableItem) item, fColumnNumber);
142
			}
143
144
			protected void setLayoutData(LayoutData layoutData) {
140
			protected void setLayoutData(LayoutData layoutData) {
145
				tableEditor.grabHorizontal = layoutData.grabHorizontal;
141
				tableEditor.grabHorizontal = layoutData.grabHorizontal;
146
				tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
142
				tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
Lines 151-156 Link Here
151
				table.showSelection();
147
				table.showSelection();
152
			}
148
			}
153
149
150
			protected void setEditor(Control w, ViewerCell cell) {
151
				if( cell == null ) {
152
					tableEditor.setEditor(w, null, 0);
153
				} else {
154
					tableEditor.setEditor(w, (TableItem) cell.getItem(), cell.getColumnIndex());
155
				}
156
				
157
			}
158
154
		};
159
		};
155
	}
160
	}
156
	
161
	
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-2 / +7 lines)
Lines 345-352 Link Here
345
				return tree.getSelection();
345
				return tree.getSelection();
346
			}
346
			}
347
347
348
			protected void setEditor(Control w, Item item, int fColumnNumber) {
348
			protected void setEditor(Control w, ViewerCell cell) {
349
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
349
				if( cell == null ) {
350
					treeEditor.setEditor(w, null, 0);
351
				} else {
352
					treeEditor.setEditor(w, (TreeItem)cell.getItem(), cell.getColumnIndex());
353
				}
354
				
350
			}
355
			}
351
356
352
			protected void setLayoutData(LayoutData layoutData) {
357
			protected void setLayoutData(LayoutData layoutData) {
(-)src/org/eclipse/jface/viewers/EditingSupport.java (-8 / +9 lines)
Lines 63-69 Link Here
63
	 *            a new viewer
63
	 *            a new viewer
64
	 */
64
	 */
65
	public EditingSupport(ColumnViewer viewer) {
65
	public EditingSupport(ColumnViewer viewer) {
66
		Assert.isNotNull(viewer,"Viewer is not allowed to be null"); //$NON-NLS-1$
66
		Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$
67
		this.viewer = viewer;
67
		this.viewer = viewer;
68
	}
68
	}
69
69
Lines 97-103 Link Here
97
	/**
97
	/**
98
	 * Restore the value from the CellEditor
98
	 * Restore the value from the CellEditor
99
	 * 
99
	 * 
100
	 * <p><b>Subclasses should overwrite!</b></p>
100
	 * <p>
101
	 * <b>Subclasses should overwrite!</b>
102
	 * </p>
101
	 * 
103
	 * 
102
	 * @param element
104
	 * @param element
103
	 *            the model element
105
	 *            the model element
Lines 143-151 Link Here
143
	 * @param event
145
	 * @param event
144
	 *            the travers event
146
	 *            the travers event
145
	 */
147
	 */
146
	protected void processTraversEvent(int columnIndex,
148
	protected void processTraversEvent(int columnIndex, ViewerRow row,
147
			ViewerRow row, TraverseEvent event) {
149
			TraverseEvent event) {
148
		
150
149
		ViewerCell cell2edit = null;
151
		ViewerCell cell2edit = null;
150
152
151
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
153
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
Lines 284-293 Link Here
284
		// API in ViewerColumn
286
		// API in ViewerColumn
285
		// to find row above/below itself?
287
		// to find row above/below itself?
286
		Rectangle r = row.getBounds();
288
		Rectangle r = row.getBounds();
287
		return viewer.getViewerRow(new Point(r.x,
289
		return viewer.getViewerRow(new Point(r.x, r.y + r.height + 2));
288
				r.y + r.height + 2));
289
	}
290
	}
290
	
291
291
	/**
292
	/**
292
	 * @return the viewer this editing support works for
293
	 * @return the viewer this editing support works for
293
	 */
294
	 */
(-)src/org/eclipse/jface/viewers/ColumnViewer.java (-43 / +151 lines)
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
}
(-)src/org/eclipse/jface/viewers/ViewerCell.java (+4 lines)
Lines 177-180 Link Here
177
	public Control getControl() {
177
	public Control getControl() {
178
		return row.getControl();
178
		return row.getControl();
179
	}
179
	}
180
	
181
	ViewerRow getViewerRow() {
182
		return row;
183
	}
180
}
184
}
(-)src/org/eclipse/jface/viewers/AbstractViewerEditor.java (-78 / +32 lines)
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseListener;
22
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.TraverseEvent;
23
import org.eclipse.swt.events.TraverseEvent;
24
import org.eclipse.swt.events.TraverseListener;
24
import org.eclipse.swt.events.TraverseListener;
25
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Item;
27
import org.eclipse.swt.widgets.Item;
Lines 46-66 Link Here
46
45
47
	private String[] columnProperties;
46
	private String[] columnProperties;
48
47
49
	private int columnNumber;
50
51
	private ICellEditorListener cellEditorListener;
48
	private ICellEditorListener cellEditorListener;
52
49
53
	private FocusListener focusListener;
50
	private FocusListener focusListener;
54
51
55
	private MouseListener mouseListener;
52
	private MouseListener mouseListener;
56
53
57
	private int doubleClickExpirationTime;
58
59
	private ColumnViewer viewer;
54
	private ColumnViewer viewer;
60
55
61
	private Item item;
62
63
	private TraverseListener tabeditingListener;
56
	private TraverseListener tabeditingListener;
57
	
58
	private int activationTime;
59
	
60
	private ViewerCell cell;
64
61
65
	/**
62
	/**
66
	 * Create a new editor implementation for the viewer
63
	 * Create a new editor implementation for the viewer
Lines 92-99 Link Here
92
89
93
	void activateCellEditor() {
90
	void activateCellEditor() {
94
91
95
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
92
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
96
		Object element = item.getData();
93
		Object element = cell.getElement();
97
94
98
		if (part != null && part.getEditingSupport() != null
95
		if (part != null && part.getEditingSupport() != null
99
				&& part.getEditingSupport().canEdit(element)) {
96
				&& part.getEditingSupport().canEdit(element)) {
Lines 113-119 Link Here
113
					return;
110
					return;
114
				}
111
				}
115
				setLayoutData(cellEditor.getLayoutData());
112
				setLayoutData(cellEditor.getLayoutData());
116
				setEditor(control, item, columnNumber);
113
				setEditor(control, cell);
117
				cellEditor.setFocus();
114
				cellEditor.setFocus();
118
				if (focusListener == null) {
115
				if (focusListener == null) {
119
					focusListener = new FocusAdapter() {
116
					focusListener = new FocusAdapter() {
Lines 128-134 Link Here
128
					public void mouseDown(MouseEvent e) {
125
					public void mouseDown(MouseEvent e) {
129
						// time wrap?
126
						// time wrap?
130
						// check for expiration of doubleClickTime
127
						// check for expiration of doubleClickTime
131
						if (e.time <= doubleClickExpirationTime) {
128
						if (e.time <= activationTime) {
132
							control.removeMouseListener(mouseListener);
129
							control.removeMouseListener(mouseListener);
133
							cancelEditing();
130
							cancelEditing();
134
							handleDoubleClickEvent();
131
							handleDoubleClickEvent();
Lines 143-153 Link Here
143
					tabeditingListener = new TraverseListener() {
140
					tabeditingListener = new TraverseListener() {
144
141
145
						public void keyTraversed(TraverseEvent e) {
142
						public void keyTraversed(TraverseEvent e) {
146
							ViewerColumn col = viewer.getViewerColumn(columnNumber);
143
							ViewerColumn col = viewer.getViewerColumn(cell.getColumnIndex());
147
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
144
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
148
								col.getEditingSupport().processTraversEvent(
145
								col.getEditingSupport().processTraversEvent(
149
										columnNumber,
146
										cell.getColumnIndex(),
150
										viewer.getViewerRowFromItem(item), e);
147
										cell.getViewerRow(), e);
151
							}
148
							}
152
						}
149
						}
153
					};
150
					};
Lines 159-196 Link Here
159
		}
156
		}
160
	}
157
	}
161
158
162
	/**
163
	 * Activate a cell editor for the given mouse position.
164
	 */
165
	private void activateCellEditor(MouseEvent event) {
166
		if (item == null || item.isDisposed()) {
167
			// item no longer exists
168
			return;
169
		}
170
		int columnToEdit;
171
		ViewerRow row = viewer.getViewerRowFromItem(item);
172
		int columns = row.getColumnCount();
173
		if (columns == 0) {
174
			// If no TableColumn, Table acts as if it has a single column
175
			// which takes the whole width.
176
			columnToEdit = 0;
177
		} else {
178
			columnToEdit = -1;
179
			for (int i = 0; i < columns; i++) {
180
				Rectangle bounds = row.getBounds(i);
181
				if (bounds.contains(event.x, event.y)) {
182
					columnToEdit = i;
183
					break;
184
				}
185
			}
186
			if (columnToEdit == -1) {
187
				return;
188
			}
189
		}
190
191
		columnNumber = columnToEdit;
192
		activateCellEditor();
193
	}
194
159
195
	/**
160
	/**
196
	 * Applies the current value and deactivates the currently active cell
161
	 * Applies the current value and deactivates the currently active cell
Lines 204-215 Link Here
204
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
169
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
205
			// using cell editor ?
170
			// using cell editor ?
206
			this.cellEditor = null;
171
			this.cellEditor = null;
207
			Item t = this.item;
172
			Item t = this.cell.getItem();
173
			
208
			// don't null out table item -- same item is still selected
174
			// don't null out table item -- same item is still selected
209
			if (t != null && !t.isDisposed()) {
175
			if (t != null && !t.isDisposed()) {
210
				saveEditorValue(c, t);
176
				saveEditorValue(c, t);
211
			}
177
			}
212
			setEditor(null, null, 0);
178
			setEditor(null, null);
213
			c.removeListener(cellEditorListener);
179
			c.removeListener(cellEditorListener);
214
			Control control = c.getControl();
180
			Control control = c.getControl();
215
			if (control != null) {
181
			if (control != null) {
Lines 235-241 Link Here
235
	 */
201
	 */
236
	void cancelEditing() {
202
	void cancelEditing() {
237
		if (cellEditor != null) {
203
		if (cellEditor != null) {
238
			setEditor(null, null, 0);
204
			setEditor(null, null);
239
			cellEditor.removeListener(cellEditorListener);
205
			cellEditor.removeListener(cellEditorListener);
240
206
241
			Control control = cellEditor.getControl();
207
			Control control = cellEditor.getControl();
Lines 265-275 Link Here
265
	 * 
231
	 * 
266
	 * @param event
232
	 * @param event
267
	 */
233
	 */
268
	void handleMouseDown(MouseEvent event) {
234
	void handleCellSelectionEvent(CellSelectionEvent event) {
269
		if (event.button != 1) {
235
		
270
			return;
271
		}
272
273
		if (cellEditor != null) {
236
		if (cellEditor != null) {
274
			applyEditorValue();
237
			applyEditorValue();
275
		}
238
		}
Lines 279-325 Link Here
279
		// the cell editor will be deactivated and a doubleClick event will
242
		// the cell editor will be deactivated and a doubleClick event will
280
		// be processed.
243
		// be processed.
281
		//
244
		//
282
		doubleClickExpirationTime = event.time
245
		if( event.swtEvent != null ) {
283
				+ Display.getCurrent().getDoubleClickTime();
246
			activationTime = event.swtEvent.time + Display.getCurrent().getDoubleClickTime();
284
285
		Item[] items = getSelection();
286
		// Do not edit if more than one row is selected.
287
		if (items.length != 1) {
288
			item = null;
289
			return;
290
		}
247
		}
291
		item = items[0];
248
		
292
		activateCellEditor(event);
249
250
		this.cell = event.cell;
251
		activateCellEditor();
293
	}
252
	}
294
253
295
	/**
254
	/**
296
	 * Start editing the given element.
255
	 * Start editing the given element.
297
	 * 
256
	 * 
298
	 * @param element
257
	 * @param cell the cell to edit
299
	 * @param column
300
	 */
258
	 */
301
	void editElement(Object element, int column) {
259
	void editCell(ViewerCell cell) {
302
		if (cellEditor != null) {
260
		if (cellEditor != null) {
303
			applyEditorValue();
261
			applyEditorValue();
304
		}
262
		}
305
263
306
		setSelection(createSelection(element), true);
264
		setSelection(createSelection(cell.getElement()), true);
307
		Item[] selection = getSelection();
265
		Item[] selection = getSelection();
308
		if (selection.length != 1) {
266
		if (selection.length != 1) {
309
			return;
267
			return;
310
		}
268
		}
311
269
312
		item = selection[0];
313
314
		// Make sure selection is visible
270
		// Make sure selection is visible
315
		showSelection();
271
		showSelection();
316
		columnNumber = column;
272
		
317
		activateCellEditor();
273
		activateCellEditor();
318
274
319
	}
275
	}
320
276
321
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
277
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
322
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
278
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
323
279
324
		if (part != null && part.getEditingSupport() != null) {
280
		if (part != null && part.getEditingSupport() != null) {
325
			part.getEditingSupport().setValue(tableItem.getData(),
281
			part.getEditingSupport().setValue(tableItem.getData(),
Lines 414-426 Link Here
414
	 * Position the editor inside the control
370
	 * Position the editor inside the control
415
	 * 
371
	 * 
416
	 * @param w
372
	 * @param w
417
	 *            the editor control
373
	 *            the editor control or <code>null</code> if the editor has to be reset
418
	 * @param item
374
	 * @param cell the cell in which the editor should be displayed or <code>null</code> if the editor has to be reset
419
	 *            the item (row) in which the editor is drawn in
375
	 *            
420
	 * @param fColumnNumber
421
	 *            the column number in which the editor is shown
422
	 */
376
	 */
423
	protected abstract void setEditor(Control w, Item item, int fColumnNumber);
377
	protected abstract void setEditor(Control w, ViewerCell cell);
424
378
425
	/**
379
	/**
426
	 * set the layout data for the editor
380
	 * set the layout data for the editor
(-)src/org/eclipse/jface/viewers/CellSelectionEvent.java (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Tom Schindl 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
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation (bug 151377)
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
import org.eclipse.jface.viewers.ColumnViewer;
17
import org.eclipse.jface.viewers.ViewerCell;
18
import org.eclipse.swt.widgets.Event;
19
20
/**
21
 * This event is trigger when a cell is selected through key board or any other
22
 * action
23
 * 
24
 * @since 3.3
25
 * 
26
 */
27
public class CellSelectionEvent extends EventObject {
28
	/**
29
	 * The real SWT-Event which triggered the action
30
	 */
31
	public Event swtEvent;
32
33
	/**
34
	 * The cell selected
35
	 */
36
	public ViewerCell cell;
37
38
	private static final long serialVersionUID = 1L;
39
40
	/**
41
	 * A new event object holding all data to decide what was the event that has
42
	 * been triggered
43
	 * 
44
	 * @param viewer
45
	 *            the viewer which is the source of the event
46
	 * @param cell
47
	 *            the cell selected
48
	 * @param swtEvent
49
	 *            the real swt event
50
	 */
51
	CellSelectionEvent(ColumnViewer viewer, ViewerCell cell, Event swtEvent) {
52
		super(viewer);
53
		this.cell = cell;
54
		this.swtEvent = swtEvent;
55
	}
56
57
}
(-)src/org/eclipse/jface/viewers/EditorActivationStrategy.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * This class is used to define a general editor activation strategy for all
16
 * cells in a {@link ColumnViewer}.
17
 * 
18
 * @since 3.3
19
 * 
20
 */
21
public abstract class EditorActivationStrategy {
22
	/**
23
	 * The method is consulted to decide whether an editor should be activated
24
	 * because of this event
25
	 * 
26
	 * @param event
27
	 *            the selection event
28
	 * @return <code>true</code> if event triggers editor activation
29
	 */
30
	protected abstract boolean isEditorActivationEvent(CellSelectionEvent event);
31
}
(-)src/org/eclipse/jface/viewers/ICellSelectionListener.java (+18 lines)
Added Link Here
1
package org.eclipse.jface.viewers;
2
3
/**
4
 * Classes interested when cell-selections occur in a table/tree control have to
5
 * implement this interface
6
 * 
7
 * @since 3.3
8
 * 
9
 */
10
public interface ICellSelectionListener {
11
	/**
12
	 * This method is called when a cell is selected
13
	 * 
14
	 * @param event
15
	 *            the selection event
16
	 */
17
	public void cellSelected(CellSelectionEvent event);
18
}

Return to bug 151377