View | Details | Raw Unified | Return to bug 142655 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-6 / +124 lines)
Lines 16-26 Link Here
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.jface.util.Assert;
18
import org.eclipse.jface.util.Assert;
19
import org.eclipse.jface.viewers.editing.ITabulatorTraversingSupport;
20
import org.eclipse.jface.viewers.editing.AbstractEditableTableColumn;
21
import org.eclipse.jface.viewers.editing.TabulatorTraversingDelegate;
22
import org.eclipse.jface.viewers.editing.TabulatorTraversingSupportWrapper;
19
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.TableEditor;
24
import org.eclipse.swt.custom.TableEditor;
21
import org.eclipse.swt.events.MouseAdapter;
25
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseEvent;
26
import org.eclipse.swt.events.MouseEvent;
27
import org.eclipse.swt.events.TraverseEvent;
28
import org.eclipse.swt.events.TraverseListener;
23
import org.eclipse.swt.graphics.Image;
29
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.graphics.Rectangle;
31
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Control;
Lines 63-70 Link Here
63
 * @see #doFindItem(Object)
70
 * @see #doFindItem(Object)
64
 * @see #internalRefresh(Object, boolean)
71
 * @see #internalRefresh(Object, boolean)
65
 */
72
 */
66
public class TableViewer extends StructuredViewer {
73
public class TableViewer extends StructuredViewer implements ITabulatorTraversingSupport {
67
		
74
	
68
	private class VirtualManager{
75
	private class VirtualManager{
69
76
70
		/**
77
		/**
Lines 255-260 Link Here
255
	 */
262
	 */
256
	private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp();
263
	private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp();
257
	
264
	
265
	private boolean tabediting = false;
266
	
267
	private TabeditingListener tabeditingListener = new TabeditingListener();
268
269
	private TabulatorTraversingDelegate tabeditingDelgate = new TabulatorTraversingDelegate();
270
	
271
	private TooltipSupport tooltipSupport;
272
	
258
	/**
273
	/**
259
	 * Creates a table viewer on a newly-created table control under the given
274
	 * Creates a table viewer on a newly-created table control under the given
260
	 * parent. The table control is created using the SWT style bits
275
	 * parent. The table control is created using the SWT style bits
Lines 297-309 Link Here
297
		hookControl(table);
312
		hookControl(table);
298
		tableEditor = new TableEditor(table);
313
		tableEditor = new TableEditor(table);
299
		initTableViewerImpl();
314
		initTableViewerImpl();
315
		initTooltip();
300
		initializeVirtualManager(table.getStyle());
316
		initializeVirtualManager(table.getStyle());
301
	}
317
	}
302
	
318
	
319
	private void initTooltip() {
320
		tooltipSupport = new TooltipSupport(this,
321
				new TooltipSupportDataProvider() {
322
323
					public TooltipData getData(Event event) {
324
						TooltipData data = new TooltipData();
325
326
						TableItem item = getTable().getItem(
327
								new Point(event.x, event.y));
328
329
						if (item != null) {
330
							data.modelObject = item.getData();
331
							int columnIndex = -1;
332
							Rectangle bounds = null;
333
							for (int i = 0; i < getTable().getColumnCount(); i++) {
334
								bounds = item.getBounds(i);
335
336
								if (bounds.contains(event.x, event.y)) {
337
									columnIndex = i;
338
									break;
339
								}
340
							}
341
342
							if (columnIndex >= 0) {
343
								data.bounds = bounds;
344
								data.columnIndex = columnIndex;
345
							}
346
						}
347
348
						return data;
349
					}
350
351
				});
352
	}
353
			
354
	
303
	/**
355
	/**
304
	 * Initialize the virtual manager to manage the virtual state
356
	 * Initialize the virtual manager to manage the virtual state if the table
305
	 * if the table is VIRTUAL. If not use the default no-op
357
	 * is VIRTUAL. If not use the default no-op version.
306
	 * version.
358
	 * 
307
	 * @param style
359
	 * @param style
308
	 */
360
	 */
309
	private void initializeVirtualManager(int style) {
361
	private void initializeVirtualManager(int style) {
Lines 518-523 Link Here
518
	 * Returns the cell editors of this table viewer.
570
	 * Returns the cell editors of this table viewer.
519
	 * 
571
	 * 
520
	 * @return the list of cell editors
572
	 * @return the list of cell editors
573
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
521
	 */
574
	 */
522
	public CellEditor[] getCellEditors() {
575
	public CellEditor[] getCellEditors() {
523
		return tableViewerImpl.getCellEditors();
576
		return tableViewerImpl.getCellEditors();
Lines 527-532 Link Here
527
	 * Returns the cell modifier of this table viewer.
580
	 * Returns the cell modifier of this table viewer.
528
	 * 
581
	 * 
529
	 * @return the cell modifier
582
	 * @return the cell modifier
583
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
530
	 */
584
	 */
531
	public ICellModifier getCellModifier() {
585
	public ICellModifier getCellModifier() {
532
		return tableViewerImpl.getCellModifier();
586
		return tableViewerImpl.getCellModifier();
Lines 538-543 Link Here
538
	 * identify the column in a cell modifier.
592
	 * identify the column in a cell modifier.
539
	 * 
593
	 * 
540
	 * @return the list of column properties
594
	 * @return the list of column properties
595
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
541
	 */
596
	 */
542
	public Object[] getColumnProperties() {
597
	public Object[] getColumnProperties() {
543
		return tableViewerImpl.getColumnProperties();
598
		return tableViewerImpl.getColumnProperties();
Lines 753-758 Link Here
753
						.getSelection()));
808
						.getSelection()));
754
				fireOpen(new OpenEvent(viewer, viewer.getSelection()));
809
				fireOpen(new OpenEvent(viewer, viewer.getSelection()));
755
			}
810
			}
811
812
			TraverseListener getTabeditingListener() {
813
				return tabeditingListener;
814
			}
756
		};
815
		};
757
	}
816
	}
758
817
Lines 1034-1039 Link Here
1034
	 * 
1093
	 * 
1035
	 * @param editors
1094
	 * @param editors
1036
	 *            the list of cell editors
1095
	 *            the list of cell editors
1096
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
1037
	 */
1097
	 */
1038
	public void setCellEditors(CellEditor[] editors) {
1098
	public void setCellEditors(CellEditor[] editors) {
1039
		tableViewerImpl.setCellEditors(editors);
1099
		tableViewerImpl.setCellEditors(editors);
Lines 1044-1049 Link Here
1044
	 * 
1104
	 * 
1045
	 * @param modifier
1105
	 * @param modifier
1046
	 *            the cell modifier
1106
	 *            the cell modifier
1107
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
1047
	 */
1108
	 */
1048
	public void setCellModifier(ICellModifier modifier) {
1109
	public void setCellModifier(ICellModifier modifier) {
1049
		tableViewerImpl.setCellModifier(modifier);
1110
		tableViewerImpl.setCellModifier(modifier);
Lines 1056-1061 Link Here
1056
	 * 
1117
	 * 
1057
	 * @param columnProperties
1118
	 * @param columnProperties
1058
	 *            the list of column properties
1119
	 *            the list of column properties
1120
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
1059
	 */
1121
	 */
1060
	public void setColumnProperties(String[] columnProperties) {
1122
	public void setColumnProperties(String[] columnProperties) {
1061
		tableViewerImpl.setColumnProperties(columnProperties);
1123
		tableViewerImpl.setColumnProperties(columnProperties);
Lines 1079-1085 Link Here
1079
		} else {
1141
		} else {
1080
			tableColorAndFont = new TableColorAndFontNoOp();
1142
			tableColorAndFont = new TableColorAndFontNoOp();
1081
		}
1143
		}
1082
				
1144
		
1145
		tooltipSupport.configureSupport(labelProvider);	
1083
	}
1146
	}
1084
	
1147
	
1085
	/**
1148
	/**
Lines 1278-1284 Link Here
1278
				provider instanceof ILazyContentProvider);
1341
				provider instanceof ILazyContentProvider);
1279
	}
1342
	}
1280
	
1343
	
1344
	/**
1345
	 * @param tabediting The tabediting to set.
1346
	 */
1347
	public void setTabulatorTraversalEnabled(boolean tabediting) {
1348
		this.tabediting = tabediting;
1349
	}
1350
1351
	public boolean isTabulatorTraversalEnabled() {
1352
		return tabediting;
1353
	}
1281
	
1354
	
1355
	protected class TabeditingListener implements TraverseListener {
1356
		private TabulatorTraversingSupportWrapper wrapper = new TabulatorTraversingSupportWrapper() {
1357
1358
			public void setSelectedRow(int index) {
1359
				TableViewer.this.table.setSelection(index);
1360
			}
1361
1362
			public int getColumnCount() {
1363
				return TableViewer.this.table.getColumnCount();
1364
			}
1365
1366
			public int getCurrentColumnIndex() {
1367
				return TableViewer.this.tableEditor.getColumn();
1368
			}
1369
1370
			public int getCurrentRowIndex() {
1371
				return TableViewer.this.table.getSelectionIndex();
1372
			}
1373
1374
			public int getRowCount() {
1375
				return TableViewer.this.table.getItemCount();
1376
			}
1377
			
1378
		};
1379
		
1380
		public void keyTraversed(TraverseEvent e) {
1381
			if( TableViewer.this.tabeditingDelgate != null ) {
1382
				TableViewer.this.tabeditingDelgate.focusNewEditor(e, TableViewer.this, wrapper);
1383
			}
1384
		}
1385
	}
1386
1387
	/* (non-Javadoc)
1388
	 * @see org.eclipse.jface.viewers.editing.ITabEditingSupport#getTabeditingDelgate()
1389
	 */
1390
	public TabulatorTraversingDelegate getTabeditingDelgate() {
1391
		return this.tabeditingDelgate;
1392
	}
1393
1394
	/* (non-Javadoc)
1395
	 * @see org.eclipse.jface.viewers.editing.ITabEditingSupport#setTabeditingDelgate(org.eclipse.jface.viewers.editing.TabEditingDelegate)
1396
	 */
1397
	public void setTabeditingDelegate(TabulatorTraversingDelegate tabeditingDelgate) {
1398
		this.tabeditingDelgate = tabeditingDelgate;
1399
	}
1282
	
1400
	
1283
}
1401
}
1284
1402
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-2 / +127 lines)
Lines 15-26 Link Here
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.jface.util.Assert;
17
import org.eclipse.jface.util.Assert;
18
import org.eclipse.jface.viewers.editing.ITabulatorTraversingSupport;
19
import org.eclipse.jface.viewers.editing.TabulatorTraversingDelegate;
20
import org.eclipse.jface.viewers.editing.TabulatorTraversingSupportWrapper;
21
import org.eclipse.jface.viewers.editing.AbstractEditableTreeColumn;
18
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.TreeEditor;
23
import org.eclipse.swt.custom.TreeEditor;
20
import org.eclipse.swt.events.DisposeEvent;
24
import org.eclipse.swt.events.DisposeEvent;
21
import org.eclipse.swt.events.DisposeListener;
25
import org.eclipse.swt.events.DisposeListener;
22
import org.eclipse.swt.events.MouseAdapter;
26
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
27
import org.eclipse.swt.events.MouseEvent;
28
import org.eclipse.swt.events.TraverseEvent;
29
import org.eclipse.swt.events.TraverseListener;
24
import org.eclipse.swt.events.TreeListener;
30
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
32
import org.eclipse.swt.graphics.Point;
Lines 47-54 Link Here
47
 * <code>ITreeContentProvider</code> interface.
53
 * <code>ITreeContentProvider</code> interface.
48
 * </p>
54
 * </p>
49
 */
55
 */
50
public class TreeViewer extends AbstractTreeViewer {
56
public class TreeViewer extends AbstractTreeViewer implements ITabulatorTraversingSupport {
51
57
	
52
	/**
58
	/**
53
	 * TreeColorAndFontCollector is an helper class for color and font support
59
	 * TreeColorAndFontCollector is an helper class for color and font support
54
	 * for trees that support the ITableFontProvider and the
60
	 * for trees that support the ITableFontProvider and the
Lines 137-142 Link Here
137
	 */
143
	 */
138
	private boolean treeIsDisposed = false;
144
	private boolean treeIsDisposed = false;
139
145
146
	private boolean tabediting = false;
147
	
148
	private TabeditingListener tabeditingListener = new TabeditingListener();
149
150
	private TabulatorTraversingDelegate tabeditingDelgate = new TabulatorTraversingDelegate();
151
152
	private TooltipSupport tooltipSupport;
153
	
140
	/**
154
	/**
141
	 * Creates a tree viewer on a newly-created tree control under the given
155
	 * Creates a tree viewer on a newly-created tree control under the given
142
	 * parent. The tree control is created using the SWT style bits
156
	 * parent. The tree control is created using the SWT style bits
Lines 179-186 Link Here
179
		hookControl(tree);
193
		hookControl(tree);
180
		treeEditor = new TreeEditor(tree);
194
		treeEditor = new TreeEditor(tree);
181
		initTreeViewerImpl();
195
		initTreeViewerImpl();
196
		initTooltip();
182
	}
197
	}
183
198
199
	private void initTooltip() {
200
		tooltipSupport = new TooltipSupport(this,
201
				new TooltipSupportDataProvider() {
202
203
					public TooltipData getData(Event event) {
204
						TooltipData data = new TooltipData();
205
206
						TreeItem item = getTree().getItem(
207
								new Point(event.x, event.y));
208
209
						if (item != null) {
210
							data.modelObject = item.getData();
211
							int columnIndex = -1;
212
							Rectangle bounds = null;
213
							for (int i = 0; i < getTree().getColumnCount(); i++) {
214
								bounds = item.getBounds(i);
215
216
								if (bounds.contains(event.x, event.y)) {
217
									columnIndex = i;
218
									break;
219
								}
220
							}
221
222
							if (columnIndex >= 0) {
223
								data.bounds = bounds;
224
								data.columnIndex = columnIndex;
225
							}
226
						}
227
228
						return data;
229
					}
230
231
				});
232
	}
233
	
184
	/*
234
	/*
185
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
235
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
186
	 */
236
	 */
Lines 357-362 Link Here
357
	 * 
407
	 * 
358
	 * @return the list of cell editors
408
	 * @return the list of cell editors
359
	 * @since 3.1
409
	 * @since 3.1
410
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
360
	 */
411
	 */
361
	public CellEditor[] getCellEditors() {
412
	public CellEditor[] getCellEditors() {
362
		return treeViewerImpl.getCellEditors();
413
		return treeViewerImpl.getCellEditors();
Lines 367-372 Link Here
367
	 * 
418
	 * 
368
	 * @return the cell modifier
419
	 * @return the cell modifier
369
	 * @since 3.1
420
	 * @since 3.1
421
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
370
	 */
422
	 */
371
	public ICellModifier getCellModifier() {
423
	public ICellModifier getCellModifier() {
372
		return treeViewerImpl.getCellModifier();
424
		return treeViewerImpl.getCellModifier();
Lines 392-397 Link Here
392
	 * 
444
	 * 
393
	 * @return the list of column properties
445
	 * @return the list of column properties
394
	 * @since 3.1
446
	 * @since 3.1
447
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
395
	 */
448
	 */
396
	public Object[] getColumnProperties() {
449
	public Object[] getColumnProperties() {
397
		return treeViewerImpl.getColumnProperties();
450
		return treeViewerImpl.getColumnProperties();
Lines 558-563 Link Here
558
						.getSelection()));
611
						.getSelection()));
559
				fireOpen(new OpenEvent(viewer, viewer.getSelection()));
612
				fireOpen(new OpenEvent(viewer, viewer.getSelection()));
560
			}
613
			}
614
615
			TraverseListener getTabeditingListener() {
616
				return tabeditingListener;
617
			}
561
		};
618
		};
562
	}
619
	}
563
620
Lines 606-611 Link Here
606
	 * @param editors
663
	 * @param editors
607
	 *            the list of cell editors
664
	 *            the list of cell editors
608
	 * @since 3.1
665
	 * @since 3.1
666
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
609
	 */
667
	 */
610
	public void setCellEditors(CellEditor[] editors) {
668
	public void setCellEditors(CellEditor[] editors) {
611
		treeViewerImpl.setCellEditors(editors);
669
		treeViewerImpl.setCellEditors(editors);
Lines 617-625 Link Here
617
	 * @param modifier
675
	 * @param modifier
618
	 *            the cell modifier
676
	 *            the cell modifier
619
	 * @since 3.1
677
	 * @since 3.1
678
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
620
	 */
679
	 */
621
	public void setCellModifier(ICellModifier modifier) {
680
	public void setCellModifier(ICellModifier modifier) {
622
		treeViewerImpl.setCellModifier(modifier);
681
		treeViewerImpl.setCellModifier(modifier);
682
623
	}
683
	}
624
684
625
	/**
685
	/**
Lines 630-635 Link Here
630
	 * @param columnProperties
690
	 * @param columnProperties
631
	 *            the list of column properties
691
	 *            the list of column properties
632
	 * @since 3.1
692
	 * @since 3.1
693
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
633
	 */
694
	 */
634
	public void setColumnProperties(String[] columnProperties) {
695
	public void setColumnProperties(String[] columnProperties) {
635
		treeViewerImpl.setColumnProperties(columnProperties);
696
		treeViewerImpl.setColumnProperties(columnProperties);
Lines 656-661 Link Here
656
				|| labelProvider instanceof ILabelProvider);
717
				|| labelProvider instanceof ILabelProvider);
657
		super.setLabelProvider(labelProvider);
718
		super.setLabelProvider(labelProvider);
658
		treeColorAndFont = new TreeColorAndFontCollector(labelProvider);
719
		treeColorAndFont = new TreeColorAndFontCollector(labelProvider);
720
		tooltipSupport.configureSupport(labelProvider);
659
	}
721
	}
660
722
661
	/*
723
	/*
Lines 985-988 Link Here
985
				}});
1047
				}});
986
		}
1048
		}
987
	}
1049
	}
1050
	
1051
	/**
1052
	 * @param tabediting The tabediting to set.
1053
	 */
1054
	public void setTabulatorTraversalEnabled(boolean tabediting) {
1055
		this.tabediting = tabediting;
1056
	}
1057
1058
	/* (non-Javadoc)
1059
	 * @see org.eclipse.jface.viewers.editing.ITabEditingSupport#isTabediting()
1060
	 */
1061
	public boolean isTabulatorTraversalEnabled() {
1062
		return this.tabediting;
1063
	}
1064
	
1065
	/* (non-Javadoc)
1066
	 * @see org.eclipse.jface.viewers.editing.ITabEditingSupport#getTabeditingDelgate()
1067
	 */
1068
	public TabulatorTraversingDelegate getTabeditingDelgate() {
1069
		return tabeditingDelgate;
1070
	}
1071
1072
	/* (non-Javadoc)
1073
	 * @see org.eclipse.jface.viewers.editing.ITabEditingSupport#setTabeditingDelgate(org.eclipse.jface.viewers.editing.TabEditingDelegate)
1074
	 */
1075
	public void setTabeditingDelegate(TabulatorTraversingDelegate tabeditingDelgate) {
1076
		this.tabeditingDelgate = tabeditingDelgate;
1077
	}
1078
	
1079
	protected class TabeditingListener implements TraverseListener {
1080
		private TabulatorTraversingSupportWrapper wrapper = new TabulatorTraversingSupportWrapper() {
1081
1082
			public void setSelectedRow(int index) {
1083
				TreeItem item = TreeViewer.this.tree.getItem(index);
1084
				TreeViewer.this.tree.setSelection(item);
1085
			}
1086
1087
			public int getColumnCount() {				
1088
				return TreeViewer.this.tree.getColumnCount();
1089
			}
1090
1091
			public int getCurrentColumnIndex() {
1092
				return TreeViewer.this.treeEditor.getColumn();
1093
			}
1094
1095
			public int getCurrentRowIndex() {
1096
				// FIXME TABING FROM ROW TO ROW
1097
				return 0;
1098
			}
1099
1100
			public int getRowCount() {
1101
				// FIXME TABING FROM ROW TO ROW
1102
				return 0;
1103
			}
1104
			
1105
		};
1106
		
1107
		public void keyTraversed(TraverseEvent e) {
1108
			if( TreeViewer.this.tabeditingDelgate != null ) {
1109
				TreeViewer.this.tabeditingDelgate.focusNewEditor(e, TreeViewer.this, wrapper);
1110
			}
1111
		}
1112
	}
988
}
1113
}
(-)src/org/eclipse/jface/viewers/TreeEditorImpl.java (-298 / +415 lines)
Lines 11-26 Link Here
11
11
12
package org.eclipse.jface.viewers;
12
package org.eclipse.jface.viewers;
13
13
14
import org.eclipse.jface.viewers.editing.AbstractEditableTreeColumn;
15
import org.eclipse.jface.viewers.editing.IEditableColumn;
16
import org.eclipse.jface.viewers.editing.IEditableMultiColumn;
17
import org.eclipse.jface.viewers.editing.ITabulatorTraversingSupport;
14
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusAdapter;
15
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusEvent;
16
import org.eclipse.swt.events.FocusListener;
20
import org.eclipse.swt.events.FocusListener;
17
import org.eclipse.swt.events.MouseAdapter;
21
import org.eclipse.swt.events.MouseAdapter;
18
import org.eclipse.swt.events.MouseEvent;
22
import org.eclipse.swt.events.MouseEvent;
19
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.MouseListener;
24
import org.eclipse.swt.events.TraverseListener;
20
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Item;
28
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.TreeColumn;
24
30
25
/**
31
/**
26
 * Internal tree viewer implementation.
32
 * Internal tree viewer implementation.
Lines 29-359 Link Here
29
 */
35
 */
30
/* package */abstract class TreeEditorImpl {
36
/* package */abstract class TreeEditorImpl {
31
37
32
    private CellEditor cellEditor;
38
	private CellEditor cellEditor;
33
39
34
    private CellEditor[] cellEditors;
40
	/**
41
	 * @deprecated
42
	 */
43
	private CellEditor[] cellEditors;
35
44
36
    private ICellModifier cellModifier;
45
	/**
46
	 * @deprecated
47
	 */
48
	private ICellModifier cellModifier;
37
49
38
    private String[] columnProperties;
50
	/**
51
	 * @deprecated
52
	 */
53
	private String[] columnProperties;
39
54
40
    private Item treeItem;
55
	private Item treeItem;
41
56
42
    private int columnNumber;
57
	private int columnNumber;
43
58
44
    private ICellEditorListener cellEditorListener;
59
	private ICellEditorListener cellEditorListener;
45
60
46
    private FocusListener focusListener;
61
	private FocusListener focusListener;
47
62
48
    private MouseListener mouseListener;
63
	private MouseListener mouseListener;
49
64
50
    private int doubleClickExpirationTime;
65
	private int doubleClickExpirationTime;
51
66
52
    private StructuredViewer viewer;
67
	private StructuredViewer viewer;
53
68
54
    TreeEditorImpl(StructuredViewer viewer) {
69
	TreeEditorImpl(StructuredViewer viewer) {
55
        this.viewer = viewer;
70
		this.viewer = viewer;
56
        initCellEditorListener();
71
		initCellEditorListener();
57
    }
72
	}
58
73
59
    /**
74
	/**
60
     * Returns this <code>TreeViewerImpl</code> viewer
75
	 * Returns this <code>TreeViewerImpl</code> viewer
61
     * 
76
	 * 
62
     * @return the viewer
77
	 * @return the viewer
63
     */
78
	 */
64
    public StructuredViewer getViewer() {
79
	public StructuredViewer getViewer() {
65
        return viewer;
80
		return viewer;
66
    }
81
	}
67
82
68
    private void activateCellEditor() {
83
	private void activateCellEditor() {
69
        if (cellEditors != null) {
84
		CellEditor editor = getEditor(columnNumber);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
85
71
                Object element = treeItem.getData();
86
		if (editor != null) {
72
                String property = columnProperties[columnNumber];
87
			Object element = treeItem.getData();
73
                if (cellModifier.canModify(element, property)) {
88
74
                    cellEditor = cellEditors[columnNumber];
89
			cellEditor = editor;
75
                    //tree.showSelection();
90
76
                    cellEditor.addListener(cellEditorListener);
91
			if(viewer instanceof ITabulatorTraversingSupport && ((ITabulatorTraversingSupport) viewer).isTabulatorTraversalEnabled()) {
77
                    Object value = cellModifier.getValue(element, property);
92
				cellEditor.getControl().addTraverseListener(getTabeditingListener());
78
                    cellEditor.setValue(value);
93
			}
79
                    // Tricky flow of control here:
94
80
                    // activate() can trigger callback to cellEditorListener which will clear cellEditor
95
			// tree.showSelection();
81
                    // so must get control first, but must still call activate() even if there is no control.
96
			cellEditor.addListener(cellEditorListener);
82
                    final Control control = cellEditor.getControl();
97
			Object value = getModelValue(element, columnNumber);
83
                    cellEditor.activate();
98
			cellEditor.setValue(value);
84
                    if (control == null) {
99
			// Tricky flow of control here:
85
						return;
100
			// activate() can trigger callback to cellEditorListener which will
101
			// clear cellEditor
102
			// so must get control first, but must still call activate() even if
103
			// there is no control.
104
			final Control control = cellEditor.getControl();
105
			cellEditor.activate();
106
			if (control == null) {
107
				return;
108
			}
109
			setLayoutData(cellEditor.getLayoutData());
110
			setEditor(control, treeItem, columnNumber);
111
			cellEditor.setFocus();
112
			if (focusListener == null) {
113
				focusListener = new FocusAdapter() {
114
					public void focusLost(FocusEvent e) {
115
						applyEditorValue();
86
					}
116
					}
87
                    setLayoutData(cellEditor.getLayoutData());
117
				};
88
                    setEditor(control, treeItem, columnNumber);
118
			}
89
                    cellEditor.setFocus();
119
			control.addFocusListener(focusListener);
90
                    if (focusListener == null) {
120
			mouseListener = new MouseAdapter() {
91
                        focusListener = new FocusAdapter() {
121
				public void mouseDown(MouseEvent e) {
92
                            public void focusLost(FocusEvent e) {
122
					// time wrap?
93
                                applyEditorValue();
123
					// check for expiration of doubleClickTime
94
                            }
124
					if (e.time <= doubleClickExpirationTime) {
95
                        };
125
						control.removeMouseListener(mouseListener);
96
                    }
126
						cancelEditing();
97
                    control.addFocusListener(focusListener);
127
						handleDoubleClickEvent();
98
                    mouseListener = new MouseAdapter() {
128
					} else if (mouseListener != null) {
99
                        public void mouseDown(MouseEvent e) {
129
						control.removeMouseListener(mouseListener);
100
                            // time wrap?	
130
					}
101
                            // check for expiration of doubleClickTime
131
				}
102
                            if (e.time <= doubleClickExpirationTime) {
132
			};
103
                                control.removeMouseListener(mouseListener);
133
			control.addMouseListener(mouseListener);
104
                                cancelEditing();
134
		}
105
                                handleDoubleClickEvent();
135
	}
106
                            } else if (mouseListener != null) {
107
                                control.removeMouseListener(mouseListener);
108
                            }
109
                        }
110
                    };
111
                    control.addMouseListener(mouseListener);
112
                }
113
            }
114
        }
115
    }
116
136
117
    /**
137
	private CellEditor getEditor(int columnNumber) {
118
     * Activate a cell editor for the given mouse position.
138
		CellEditor editor = null;
119
     */
120
    private void activateCellEditor(MouseEvent event) {
121
        if (treeItem == null || treeItem.isDisposed()) {
122
            //item no longer exists
123
            return;
124
        }
125
        int columnToEdit;
126
        int columns = getColumnCount();
127
        if (columns == 0) {
128
            // If no TreeColumn, Tree acts as if it has a single column
129
            // which takes the whole width.
130
            columnToEdit = 0;
131
        } else {
132
            columnToEdit = -1;
133
            for (int i = 0; i < columns; i++) {
134
                Rectangle bounds = getBounds(treeItem, i);
135
                if (bounds.contains(event.x, event.y)) {
136
                    columnToEdit = i;
137
                    break;
138
                }
139
            }
140
            if (columnToEdit == -1) {
141
                return;
142
            }
143
        }
144
139
145
        columnNumber = columnToEdit;
140
		// Ensure compatility with old interface
146
        activateCellEditor();
141
		if (cellEditors != null) {
147
    }
142
			if (cellEditors[columnNumber] != null && cellModifier != null) {
148
143
				Object element = treeItem.getData();
149
    /**
144
				String property = columnProperties[columnNumber];
150
     * Deactivates the currently active cell editor.
145
151
     */
146
				if (cellModifier.canModify(element, property)) {
152
    public void applyEditorValue() {
147
					editor = cellEditors[columnNumber];
153
        CellEditor c = this.cellEditor;
148
				}
154
        if (c != null) {
149
			}
155
            // null out cell editor before calling save
150
		} else {
156
            // in case save results in applyEditorValue being re-entered
151
			if (viewer instanceof TreeViewer) {
157
            // see 1GAHI8Z: ITPUI:ALL - How to code event notification when using cell editor ?
152
				TreeColumn column = ((TreeViewer)viewer).getTree().getColumn(columnNumber);
158
            this.cellEditor = null;
153
				if( column.getData(IEditableColumn.EDITING_SUPPORT_KEY) != null ) {
159
            Item t = this.treeItem;
154
					IEditableColumn eColumn = (IEditableColumn)column.getData(IEditableColumn.EDITING_SUPPORT_KEY);
160
            // don't null out tree item -- same item is still selected
155
					
161
            if (t != null && !t.isDisposed()) {
156
					Object element = treeItem.getData();
162
                saveEditorValue(c, t);
157
					
163
            }
158
					if( column instanceof IEditableMultiColumn  ) {
164
            setEditor(null, null, 0);
159
						IEditableMultiColumn t = (IEditableMultiColumn)eColumn;
165
            c.removeListener(cellEditorListener);
160
						
166
            Control control = c.getControl();
161
						if( t.canEdit(element, columnNumber) ) {
167
            if (control != null) {
162
							editor = t.getCellEditor(element, columnNumber);
168
                if (mouseListener != null) {
163
						}
169
                    control.removeMouseListener(mouseListener);
164
					} else {
170
                }
165
						if( eColumn.canEdit(element)) {
171
                if (focusListener != null) {
166
							editor = eColumn.getCellEditor(element);
172
                    control.removeFocusListener(focusListener);
167
						}
173
                }
168
					}
169
		    	}
170
			}
171
		}
172
173
		return editor;
174
	}
175
176
	private Object getModelValue(Object element, int columnNumber) {
177
		Object value = null;
178
		if (cellEditors != null ) {
179
			if( cellModifier != null ) {
180
				String property = columnProperties[columnNumber];
181
				value = cellModifier.getValue(element, property);
182
			}
183
		} else {
184
			IEditableColumn column = (IEditableColumn)((TableViewer)viewer).getTable().getColumn(columnNumber).getData(IEditableColumn.EDITING_SUPPORT_KEY);
185
			
186
			if( column instanceof IEditableMultiColumn ) {
187
            	value = ((IEditableMultiColumn)column).getValue(element,columnNumber);
188
            } else {
189
            	value = column.getValue(element);
174
            }
190
            }
175
            c.deactivate();
191
		}
176
        }
192
177
    }
193
		return value;
178
194
	}
179
    /**
195
180
     * Cancels the active cell editor, without saving the value 
196
	/**
181
     * back to the domain model.
197
	 * Activate a cell editor for the given mouse position.
182
     */
198
	 */
183
    public void cancelEditing() {
199
	private void activateCellEditor(MouseEvent event) {
184
        if (cellEditor != null) {
200
		if (treeItem == null || treeItem.isDisposed()) {
185
            setEditor(null, null, 0);
201
			// item no longer exists
186
            cellEditor.removeListener(cellEditorListener);
202
			return;
187
            CellEditor oldEditor = cellEditor;
203
		}
188
            cellEditor = null;
204
		int columnToEdit;
189
            oldEditor.deactivate();
205
		int columns = getColumnCount();
190
        }
206
		if (columns == 0) {
191
    }
207
			// If no TreeColumn, Tree acts as if it has a single column
192
208
			// which takes the whole width.
193
    /**
209
			columnToEdit = 0;
194
     * Start editing the given element. 
210
		} else {
195
     * @param element
211
			columnToEdit = -1;
196
     * @param column
212
			for (int i = 0; i < columns; i++) {
197
     */
213
				Rectangle bounds = getBounds(treeItem, i);
198
    public void editElement(Object element, int column) {
214
				if (bounds.contains(event.x, event.y)) {
199
        if (cellEditor != null) {
215
					columnToEdit = i;
216
					break;
217
				}
218
			}
219
			if (columnToEdit == -1) {
220
				return;
221
			}
222
		}
223
224
		columnNumber = columnToEdit;
225
		activateCellEditor();
226
	}
227
228
	/**
229
	 * Deactivates the currently active cell editor.
230
	 */
231
	public void applyEditorValue() {
232
		CellEditor c = this.cellEditor;
233
		if (c != null) {
234
			if( viewer instanceof ITabulatorTraversingSupport ) {
235
        		c.getControl().removeTraverseListener(getTabeditingListener());
236
        	}
237
			
238
			// null out cell editor before calling save
239
			// in case save results in applyEditorValue being re-entered
240
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
241
			// using cell editor ?
242
			this.cellEditor = null;
243
			Item t = this.treeItem;
244
			// don't null out tree item -- same item is still selected
245
			if (t != null && !t.isDisposed()) {
246
				saveEditorValue(c, t);
247
			}
248
			setEditor(null, null, 0);
249
			c.removeListener(cellEditorListener);
250
			Control control = c.getControl();
251
			if (control != null) {
252
				if (mouseListener != null) {
253
					control.removeMouseListener(mouseListener);
254
				}
255
				if (focusListener != null) {
256
					control.removeFocusListener(focusListener);
257
				}
258
			}
259
			c.deactivate();
260
		}
261
	}
262
263
	/**
264
	 * Cancels the active cell editor, without saving the value back to the
265
	 * domain model.
266
	 */
267
	public void cancelEditing() {
268
		if (cellEditor != null) {
269
			
270
			if( viewer instanceof ITabulatorTraversingSupport ) {
271
        		cellEditor.getControl().removeTraverseListener(getTabeditingListener());
272
        	}
273
			
274
			setEditor(null, null, 0);
275
			cellEditor.removeListener(cellEditorListener);
276
			CellEditor oldEditor = cellEditor;
277
			cellEditor = null;
278
			oldEditor.deactivate();
279
		}
280
	}
281
282
	/**
283
	 * Start editing the given element.
284
	 * 
285
	 * @param element
286
	 * @param column
287
	 */
288
	public void editElement(Object element, int column) {
289
		if (cellEditor != null) {
200
			applyEditorValue();
290
			applyEditorValue();
201
		}
291
		}
202
292
203
        IStructuredSelection structuredSelection;
293
		IStructuredSelection structuredSelection;
204
        if(element instanceof TreePath) {
294
		if (element instanceof TreePath) {
205
        	structuredSelection = new TreeSelection((TreePath)element, viewer.getComparer());
295
			structuredSelection = new TreeSelection((TreePath) element, viewer
206
        } else {
296
					.getComparer());
207
        	structuredSelection = new StructuredSelection(element);
297
		} else {
208
        }
298
			structuredSelection = new StructuredSelection(element);
209
        setSelection(structuredSelection, true);
299
		}
210
        Item[] selection = getSelection();
300
		setSelection(structuredSelection, true);
211
        if (selection.length != 1) {
301
		Item[] selection = getSelection();
302
		if (selection.length != 1) {
212
			return;
303
			return;
213
		}
304
		}
214
305
215
        treeItem = selection[0];
306
		treeItem = selection[0];
216
307
217
        // Make sure selection is visible
308
		// Make sure selection is visible
218
        showSelection();
309
		showSelection();
219
        columnNumber = column;
310
		columnNumber = column;
220
        activateCellEditor();
311
		activateCellEditor();
221
312
222
    }
313
	}
223
314
224
    abstract Rectangle getBounds(Item item, int columnNumber);
315
	abstract Rectangle getBounds(Item item, int columnNumber);
225
316
226
    /**
317
	/**
227
     * Get the Cell Editors for the receiver.
318
	 * Get the Cell Editors for the receiver.
228
     * @return CellEditor[]
319
	 * 
229
     */
320
	 * @return CellEditor[]
230
    public CellEditor[] getCellEditors() {
321
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
231
        return cellEditors;
322
	 */
232
    }
323
	public CellEditor[] getCellEditors() {
233
324
		return cellEditors;
234
    /**
325
	}
235
     * Get the cell modifier for the receiver.
326
236
     * @return ICellModifier
327
	/**
237
     */
328
	 * Get the cell modifier for the receiver.
238
    public ICellModifier getCellModifier() {
329
	 * 
239
        return cellModifier;
330
	 * @return ICellModifier
240
    }
331
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
241
332
	 */
242
    abstract int getColumnCount();
333
	public ICellModifier getCellModifier() {
243
334
		return cellModifier;
244
    /**
335
	}
245
     * Get the column properties for the receiver.
336
246
     * @return Object[]
337
	abstract int getColumnCount();
247
     */
338
248
    public Object[] getColumnProperties() {
339
	/**
249
        return columnProperties;
340
	 * Get the column properties for the receiver.
250
    }
341
	 * 
251
342
	 * @return Object[]
252
    abstract Item[] getSelection();
343
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
253
344
	 */
254
    /**
345
	public Object[] getColumnProperties() {
255
     * Handles the mouse down event; activates the cell editor.
346
		return columnProperties;
256
     * @param event
347
	}
257
     */
348
258
    public void handleMouseDown(MouseEvent event) {
349
	abstract Item[] getSelection();
259
        if (event.button != 1) {
350
351
	/**
352
	 * Handles the mouse down event; activates the cell editor.
353
	 * 
354
	 * @param event
355
	 *            the mouse event that should be handled
356
	 */
357
	public void handleMouseDown(MouseEvent event) {
358
		if (event.button != 1) {
260
			return;
359
			return;
261
		}
360
		}
262
361
263
        if (cellEditor != null) {
362
		if (cellEditor != null) {
264
			applyEditorValue();
363
			applyEditorValue();
265
		}
364
		}
266
365
267
        // activate the cell editor immediately.  If a second mouseDown
366
		// activate the cell editor immediately. If a second mouseDown
268
        // is received prior to the expiration of the doubleClick time then
367
		// is received prior to the expiration of the doubleClick time then
269
        // the cell editor will be deactivated and a doubleClick event will
368
		// the cell editor will be deactivated and a doubleClick event will
270
        // be processed.
369
		// be processed.
271
        //
370
		//
272
        doubleClickExpirationTime = event.time
371
		doubleClickExpirationTime = event.time
273
                + Display.getCurrent().getDoubleClickTime();
372
				+ Display.getCurrent().getDoubleClickTime();
274
373
275
        Item[] items = getSelection();
374
		Item[] items = getSelection();
276
        // Do not edit if more than one row is selected.
375
		// Do not edit if more than one row is selected.
277
        if (items.length != 1) {
376
		if (items.length != 1) {
278
            treeItem = null;
377
			treeItem = null;
279
            return;
378
			return;
280
        }
379
		}
281
        treeItem = items[0];
380
		treeItem = items[0];
282
        activateCellEditor(event);
381
		activateCellEditor(event);
283
    }
382
	}
284
383
285
    private void initCellEditorListener() {
384
	private void initCellEditorListener() {
286
        cellEditorListener = new ICellEditorListener() {
385
		cellEditorListener = new ICellEditorListener() {
287
            public void editorValueChanged(boolean oldValidState,
386
			public void editorValueChanged(boolean oldValidState,
288
                    boolean newValidState) {
387
					boolean newValidState) {
289
                // Ignore.
388
				// Ignore.
290
            }
389
			}
291
390
292
            public void cancelEditor() {
391
			public void cancelEditor() {
293
                TreeEditorImpl.this.cancelEditing();
392
				TreeEditorImpl.this.cancelEditing();
294
            }
393
			}
394
395
			public void applyEditorValue() {
396
				TreeEditorImpl.this.applyEditorValue();
397
			}
398
		};
399
	}
295
400
296
            public void applyEditorValue() {
401
	/**
297
                TreeEditorImpl.this.applyEditorValue();
402
	 * Return whether or not there is an active cell editor.
403
	 * 
404
	 * @return boolean <code>true</code> if there is an active cell editor;
405
	 *         otherwise <code>false</code> is returned.
406
	 */
407
	public boolean isCellEditorActive() {
408
		return cellEditor != null;
409
	}
410
411
	/**
412
	 * Saves the value of the currently active cell editor, by delegating to the
413
	 * cell modifier.
414
	 */
415
	private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
416
		if( cellEditors != null ) {
417
			if (cellModifier != null) {
418
				String property = null;
419
				if (columnProperties != null
420
						&& columnNumber < columnProperties.length) {
421
					property = columnProperties[columnNumber];
422
				}
423
				cellModifier.modify(treeItem, property, cellEditor.getValue());
424
			}
425
		} else {
426
			IEditableColumn column = (IEditableColumn)((TreeViewer)viewer).getTree().getColumn(columnNumber).getData(IEditableColumn.EDITING_SUPPORT_KEY);
427
            if( column instanceof IEditableMultiColumn ) {
428
            	((IEditableMultiColumn)column).setValue(treeItem.getData(),cellEditor.getValue(),columnNumber);
429
            } else {
430
            	column.setValue(treeItem.getData(),cellEditor.getValue());
298
            }
431
            }
299
        };
432
		}
300
    }
433
	}
301
434
302
    /**
435
	/**
303
     * Return whether or not there is an active cell editor.
436
	 * Set the cell editors for the receiver.
304
     * @return boolean <code>true</code> if there is an active cell editor; otherwise
437
	 * 
305
     * <code>false</code> is returned.
438
	 * @param editors
306
     */
439
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
307
    public boolean isCellEditorActive() {
440
	 */
308
        return cellEditor != null;
441
	public void setCellEditors(CellEditor[] editors) {
309
    }
442
		this.cellEditors = editors;
310
443
	}
311
    /**
444
312
     * Saves the value of the currently active cell editor,
445
	/**
313
     * by delegating to the cell modifier.
446
	 * Set the cell modifier for the receiver.
314
     */
447
	 * 
315
    private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
448
	 * @param modifier
316
        if (cellModifier != null) {
449
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
317
            String property = null;
450
	 */
318
            if (columnProperties != null
451
	public void setCellModifier(ICellModifier modifier) {
319
                    && columnNumber < columnProperties.length) {
452
		this.cellModifier = modifier;
320
				property = columnProperties[columnNumber];
453
	}
321
			}
454
322
            cellModifier.modify(treeItem, property, cellEditor.getValue());
455
	/**
323
        }
456
	 * Set the column properties for the receiver.
324
    }
457
	 * 
325
458
	 * @param columnProperties
326
    /**
459
	 * @deprecated please use the new interface {@link AbstractEditableTreeColumn}
327
     * Set the cell editors for the receiver.
460
	 */
328
     * @param editors
461
	public void setColumnProperties(String[] columnProperties) {
329
     */
462
		this.columnProperties = columnProperties;
330
    public void setCellEditors(CellEditor[] editors) {
463
	}
331
        this.cellEditors = editors;
464
332
    }
465
	abstract void setEditor(Control w, Item item, int fColumnNumber);
333
466
334
    /**
467
	abstract void setLayoutData(CellEditor.LayoutData layoutData);
335
     * Set the cell modifier for the receiver.
336
     * @param modifier
337
     */
338
    public void setCellModifier(ICellModifier modifier) {
339
        this.cellModifier = modifier;
340
    }
341
342
    /**
343
     * Set the column properties for the receiver.
344
     * @param columnProperties
345
     */
346
    public void setColumnProperties(String[] columnProperties) {
347
        this.columnProperties = columnProperties;
348
    }
349
350
    abstract void setEditor(Control w, Item item, int fColumnNumber);
351
468
352
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
469
	abstract void setSelection(IStructuredSelection selection, boolean b);
353
470
354
    abstract void setSelection(IStructuredSelection selection, boolean b);
471
	abstract void showSelection();
355
472
356
    abstract void showSelection();
473
	abstract void handleDoubleClickEvent();
357
474
358
    abstract void handleDoubleClickEvent();
475
	abstract TraverseListener getTabeditingListener();
359
}
476
}
(-)src/org/eclipse/jface/viewers/TableEditorImpl.java (-296 / +411 lines)
Lines 11-26 Link Here
11
11
12
package org.eclipse.jface.viewers;
12
package org.eclipse.jface.viewers;
13
13
14
import org.eclipse.jface.viewers.editing.AbstractEditableTableColumn;
15
import org.eclipse.jface.viewers.editing.IEditableColumn;
16
import org.eclipse.jface.viewers.editing.IEditableMultiColumn;
17
import org.eclipse.jface.viewers.editing.ITabulatorTraversingSupport;
14
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusAdapter;
15
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusEvent;
16
import org.eclipse.swt.events.FocusListener;
20
import org.eclipse.swt.events.FocusListener;
17
import org.eclipse.swt.events.MouseAdapter;
21
import org.eclipse.swt.events.MouseAdapter;
18
import org.eclipse.swt.events.MouseEvent;
22
import org.eclipse.swt.events.MouseEvent;
19
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.MouseListener;
24
import org.eclipse.swt.events.TraverseListener;
20
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Item;
28
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.TableColumn;
24
30
25
/**
31
/**
26
 * Internal table viewer implementation.
32
 * Internal table viewer implementation.
Lines 29-357 Link Here
29
 */
35
 */
30
/* package */abstract class TableEditorImpl {
36
/* package */abstract class TableEditorImpl {
31
37
32
    private CellEditor cellEditor;
38
	private CellEditor cellEditor;
33
39
34
    private CellEditor[] cellEditors;
40
	/**
41
	 * @deprecated
42
	 */
43
	private CellEditor[] cellEditors;
35
44
36
    private ICellModifier cellModifier;
45
	/**
46
	 * @deprecated
47
	 */
48
	private ICellModifier cellModifier;
37
49
38
    private String[] columnProperties;
50
	/**
51
	 * @deprecated
52
	 */
53
	private String[] columnProperties;
39
54
40
    private Item tableItem;
55
	private Item tableItem;
41
56
42
    private int columnNumber;
57
	private int columnNumber;
43
58
44
    private ICellEditorListener cellEditorListener;
59
	private ICellEditorListener cellEditorListener;
45
60
46
    private FocusListener focusListener;
61
	private FocusListener focusListener;
47
62
48
    private MouseListener mouseListener;
63
	private MouseListener mouseListener;
49
64
50
    private int doubleClickExpirationTime;
65
	private int doubleClickExpirationTime;
51
66
52
    private StructuredViewer viewer;
67
	private StructuredViewer viewer;
53
68
54
    TableEditorImpl(StructuredViewer viewer) {
69
	TableEditorImpl(StructuredViewer viewer) {
55
        this.viewer = viewer;
70
		this.viewer = viewer;
56
        initCellEditorListener();
71
		initCellEditorListener();
57
    }
72
	}
58
73
59
    /**
74
	/**
60
     * Returns this <code>TableViewerImpl</code> viewer
75
	 * Returns this <code>TableViewerImpl</code> viewer
61
     * 
76
	 * 
62
     * @return the viewer
77
	 * @return the viewer
63
     */
78
	 */
64
    public StructuredViewer getViewer() {
79
	public StructuredViewer getViewer() {
65
        return viewer;
80
		return viewer;
66
    }
81
	}
67
82
68
    private void activateCellEditor() {
83
	private void activateCellEditor() {
69
        if (cellEditors != null) {
84
		CellEditor editor = getEditor(columnNumber);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
85
71
                Object element = tableItem.getData();
86
		if (editor != null) {
72
                String property = columnProperties[columnNumber];
87
			Object element = tableItem.getData();
73
                if (cellModifier.canModify(element, property)) {
88
74
                    cellEditor = cellEditors[columnNumber];
89
			cellEditor = editor;
75
                    //table.showSelection();
90
76
                    cellEditor.addListener(cellEditorListener);
91
			if(viewer instanceof ITabulatorTraversingSupport && ((ITabulatorTraversingSupport) viewer).isTabulatorTraversalEnabled()) {
77
                    Object value = cellModifier.getValue(element, property);
92
				cellEditor.getControl().addTraverseListener(getTabeditingListener());
78
                    cellEditor.setValue(value);
93
			}
79
                    // Tricky flow of control here:
94
80
                    // activate() can trigger callback to cellEditorListener which will clear cellEditor
95
			// table.showSelection();
81
                    // so must get control first, but must still call activate() even if there is no control.
96
			cellEditor.addListener(cellEditorListener);
82
                    final Control control = cellEditor.getControl();
97
			Object value = getModelValue(element, columnNumber);
83
                    cellEditor.activate();
98
			cellEditor.setValue(value);
84
                    if (control == null) {
99
			// Tricky flow of control here:
85
						return;
100
			// activate() can trigger callback to cellEditorListener which will
101
			// clear cellEditor
102
			// so must get control first, but must still call activate() even if
103
			// there is no control.
104
			final Control control = cellEditor.getControl();
105
			cellEditor.activate();
106
			if (control == null) {
107
				return;
108
			}
109
			setLayoutData(cellEditor.getLayoutData());
110
			setEditor(control, tableItem, columnNumber);
111
			cellEditor.setFocus();
112
			if (focusListener == null) {
113
				focusListener = new FocusAdapter() {
114
					public void focusLost(FocusEvent e) {
115
						applyEditorValue();
86
					}
116
					}
87
                    setLayoutData(cellEditor.getLayoutData());
117
				};
88
                    setEditor(control, tableItem, columnNumber);
118
			}
89
                    cellEditor.setFocus();
119
			control.addFocusListener(focusListener);
90
                    if (focusListener == null) {
120
			mouseListener = new MouseAdapter() {
91
                        focusListener = new FocusAdapter() {
121
				public void mouseDown(MouseEvent e) {
92
                            public void focusLost(FocusEvent e) {
122
					// time wrap?
93
                                applyEditorValue();
123
					// check for expiration of doubleClickTime
94
                            }
124
					if (e.time <= doubleClickExpirationTime) {
95
                        };
125
						control.removeMouseListener(mouseListener);
96
                    }
126
						cancelEditing();
97
                    control.addFocusListener(focusListener);
127
						handleDoubleClickEvent();
98
                    mouseListener = new MouseAdapter() {
128
					} else if (mouseListener != null) {
99
                        public void mouseDown(MouseEvent e) {
129
						control.removeMouseListener(mouseListener);
100
                            // time wrap?	
130
					}
101
                            // check for expiration of doubleClickTime
131
				}
102
                            if (e.time <= doubleClickExpirationTime) {
132
			};
103
                                control.removeMouseListener(mouseListener);
133
			control.addMouseListener(mouseListener);
104
                                cancelEditing();
134
		}
105
                                handleDoubleClickEvent();
135
	}
106
                            } else if (mouseListener != null) {
107
                                control.removeMouseListener(mouseListener);
108
                            }
109
                        }
110
                    };
111
                    control.addMouseListener(mouseListener);
112
                }
113
            }
114
        }
115
    }
116
136
117
    /**
137
	private CellEditor getEditor(int columnNumber) {
118
     * Activate a cell editor for the given mouse position.
138
		CellEditor editor = null;
119
     */
120
    private void activateCellEditor(MouseEvent event) {
121
        if (tableItem == null || tableItem.isDisposed()) {
122
            //item no longer exists
123
            return;
124
        }
125
        int columnToEdit;
126
        int columns = getColumnCount();
127
        if (columns == 0) {
128
            // If no TableColumn, Table acts as if it has a single column
129
            // which takes the whole width.
130
            columnToEdit = 0;
131
        } else {
132
            columnToEdit = -1;
133
            for (int i = 0; i < columns; i++) {
134
                Rectangle bounds = getBounds(tableItem, i);
135
                if (bounds.contains(event.x, event.y)) {
136
                    columnToEdit = i;
137
                    break;
138
                }
139
            }
140
            if (columnToEdit == -1) {
141
                return;
142
            }
143
        }
144
139
145
        columnNumber = columnToEdit;
140
		// Ensure compatility with old interface
146
        activateCellEditor();
141
		if (cellEditors != null) {
147
    }
142
			if (cellEditors[columnNumber] != null && cellModifier != null) {
148
143
				Object element = tableItem.getData();
149
    /**
144
				String property = columnProperties[columnNumber];
150
     * Deactivates the currently active cell editor.
145
151
     */
146
				if (cellModifier.canModify(element, property)) {
152
    public void applyEditorValue() {
147
					editor = cellEditors[columnNumber];
153
        CellEditor c = this.cellEditor;
148
				}
154
        if (c != null) {
149
			}
155
            // null out cell editor before calling save
150
		} else {
156
            // in case save results in applyEditorValue being re-entered
151
			if( viewer instanceof TableViewer ) {
157
            // see 1GAHI8Z: ITPUI:ALL - How to code event notification when using cell editor ?
152
				TableColumn column = ((TableViewer)viewer).getTable().getColumn(columnNumber);
158
            this.cellEditor = null;
153
				if( column.getData(IEditableColumn.EDITING_SUPPORT_KEY) != null ) {
159
            Item t = this.tableItem;
154
					IEditableColumn eColumn = (IEditableColumn)column.getData(IEditableColumn.EDITING_SUPPORT_KEY);
160
            // don't null out table item -- same item is still selected
155
					
161
            if (t != null && !t.isDisposed()) {
156
					Object element = tableItem.getData();
162
                saveEditorValue(c, t);
157
					
163
            }
158
					if( column instanceof IEditableMultiColumn  ) {
164
            setEditor(null, null, 0);
159
						IEditableMultiColumn t = (IEditableMultiColumn)eColumn;
165
            c.removeListener(cellEditorListener);
160
						
166
            Control control = c.getControl();
161
						if( t.canEdit(element, columnNumber) ) {
167
            if (control != null) {
162
							editor = t.getCellEditor(element, columnNumber);
168
                if (mouseListener != null) {
163
						}
169
                    control.removeMouseListener(mouseListener);
164
					} else {
170
                }
165
						if( eColumn.canEdit(element)) {
171
                if (focusListener != null) {
166
							editor = eColumn.getCellEditor(element);
172
                    control.removeFocusListener(focusListener);
167
						}
173
                }
168
					}
169
		    	}
170
			}
171
		}
172
173
		return editor;
174
	}
175
176
	private Object getModelValue(Object element, int columnNumber) {
177
		Object value = null;
178
		if (cellEditors != null ) {
179
			if( cellModifier != null ) {
180
				String property = columnProperties[columnNumber];
181
				value = cellModifier.getValue(element, property);
182
			}
183
		} else {
184
			IEditableColumn column = (IEditableColumn)((TableViewer)viewer).getTable().getColumn(columnNumber).getData(IEditableColumn.EDITING_SUPPORT_KEY);
185
			
186
			if( column instanceof IEditableMultiColumn ) {
187
            	value = ((IEditableMultiColumn)column).getValue(element,columnNumber);
188
            } else {
189
            	value = column.getValue(element);
174
            }
190
            }
175
            c.deactivate();
191
		}
176
        }
192
177
    }
193
		return value;
178
194
	}
179
    /**
195
180
     * Cancels the active cell editor, without saving the value 
196
	/**
181
     * back to the domain model.
197
	 * Activate a cell editor for the given mouse position.
182
     */
198
	 */
183
    public void cancelEditing() {
199
	private void activateCellEditor(MouseEvent event) {
184
        if (cellEditor != null) {
200
		if (tableItem == null || tableItem.isDisposed()) {
185
            setEditor(null, null, 0);
201
			// item no longer exists
186
            cellEditor.removeListener(cellEditorListener);
202
			return;
187
            CellEditor oldEditor = cellEditor;
203
		}
188
            cellEditor = null;
204
		int columnToEdit;
189
            oldEditor.deactivate();
205
		int columns = getColumnCount();
190
        }
206
		if (columns == 0) {
191
    }
207
			// If no TableColumn, Table acts as if it has a single column
192
208
			// which takes the whole width.
193
    /**
209
			columnToEdit = 0;
194
     * Start editing the given element. 
210
		} else {
195
     * @param element 
211
			columnToEdit = -1;
196
     * @param column 
212
			for (int i = 0; i < columns; i++) {
197
     */
213
				Rectangle bounds = getBounds(tableItem, i);
198
    public void editElement(Object element, int column) {
214
				if (bounds.contains(event.x, event.y)) {
199
        if (cellEditor != null) {
215
					columnToEdit = i;
216
					break;
217
				}
218
			}
219
			if (columnToEdit == -1) {
220
				return;
221
			}
222
		}
223
224
		columnNumber = columnToEdit;
225
		activateCellEditor();
226
	}
227
228
	/**
229
	 * Deactivates the currently active cell editor.
230
	 */
231
	public void applyEditorValue() {
232
		CellEditor c = this.cellEditor;
233
		if (c != null) {
234
			if( viewer instanceof ITabulatorTraversingSupport ) {
235
        		c.getControl().removeTraverseListener(getTabeditingListener());
236
        	}
237
			
238
			// null out cell editor before calling save
239
			// in case save results in applyEditorValue being re-entered
240
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
241
			// using cell editor ?
242
			this.cellEditor = null;
243
			Item t = this.tableItem;
244
			// don't null out table item -- same item is still selected
245
			if (t != null && !t.isDisposed()) {
246
				saveEditorValue(c, t);
247
			}
248
			setEditor(null, null, 0);
249
			c.removeListener(cellEditorListener);
250
			Control control = c.getControl();
251
			if (control != null) {
252
				if (mouseListener != null) {
253
					control.removeMouseListener(mouseListener);
254
				}
255
				if (focusListener != null) {
256
					control.removeFocusListener(focusListener);
257
				}
258
			}
259
			c.deactivate();
260
		}
261
	}
262
263
	/**
264
	 * Cancels the active cell editor, without saving the value back to the
265
	 * domain model.
266
	 */
267
	public void cancelEditing() {
268
		if (cellEditor != null) {
269
			
270
			if( viewer instanceof ITabulatorTraversingSupport ) {
271
        		cellEditor.getControl().removeTraverseListener(getTabeditingListener());
272
        	}
273
			
274
			setEditor(null, null, 0);
275
			cellEditor.removeListener(cellEditorListener);
276
			CellEditor oldEditor = cellEditor;
277
			cellEditor = null;
278
			oldEditor.deactivate();
279
		}
280
	}
281
282
	/**
283
	 * Start editing the given element.
284
	 * 
285
	 * @param element
286
	 * @param column
287
	 */
288
	public void editElement(Object element, int column) {
289
		if (cellEditor != null) {
200
			applyEditorValue();
290
			applyEditorValue();
201
		}
291
		}
202
292
203
        setSelection(new StructuredSelection(element), true);
293
		setSelection(new StructuredSelection(element), true);
204
        Item[] selection = getSelection();
294
		Item[] selection = getSelection();
205
        if (selection.length != 1) {
295
		if (selection.length != 1) {
206
			return;
296
			return;
207
		}
297
		}
208
298
209
        tableItem = selection[0];
299
		tableItem = selection[0];
210
300
211
        // Make sure selection is visible
301
		// Make sure selection is visible
212
        showSelection();
302
		showSelection();
213
        columnNumber = column;
303
		columnNumber = column;
214
        activateCellEditor();
304
		activateCellEditor();
215
305
216
    }
306
	}
217
307
218
    abstract Rectangle getBounds(Item item, int columnNumber);
308
	abstract Rectangle getBounds(Item item, int columnNumber);
219
309
220
    /**
310
	/**
221
     * Return the array of CellEditors used in the viewer
311
	 * Return the array of CellEditors used in the viewer
222
     * @return the cell editors
312
	 * 
223
     */
313
	 * @return the cell editors
224
    public CellEditor[] getCellEditors() {
314
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
225
        return cellEditors;
315
	 */
226
    }
316
	public CellEditor[] getCellEditors() {
227
317
		return cellEditors;
228
    /**
318
	}
229
     * Get the cell modifier
319
230
     * @return the cell modifier
320
	/**
231
     */
321
	 * Get the cell modifier
232
    public ICellModifier getCellModifier() {
322
	 * 
233
        return cellModifier;
323
	 * @return the cell modifier
234
    }
324
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
235
325
	 */
236
    abstract int getColumnCount();
326
	public ICellModifier getCellModifier() {
237
327
		return cellModifier;
238
    /**
328
	}
239
     * Return the properties for the column
329
240
     * @return the array of column properties
330
	abstract int getColumnCount();
241
     */
331
242
    public Object[] getColumnProperties() {
332
	/**
243
        return columnProperties;
333
	 * Return the properties for the column
244
    }
334
	 * 
245
335
	 * @return the array of column properties
246
    abstract Item[] getSelection();
336
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
247
337
	 */
248
    /**
338
	public Object[] getColumnProperties() {
249
     * Handles the mouse down event; activates the cell editor.
339
		return columnProperties;
250
     * @param event the mouse event that should be handled
340
	}
251
     */
341
252
    public void handleMouseDown(MouseEvent event) {
342
	abstract Item[] getSelection();
253
        if (event.button != 1) {
343
344
	/**
345
	 * Handles the mouse down event; activates the cell editor.
346
	 * 
347
	 * @param event
348
	 *            the mouse event that should be handled
349
	 */
350
	public void handleMouseDown(MouseEvent event) {
351
		if (event.button != 1) {
254
			return;
352
			return;
255
		}
353
		}
256
354
257
        if (cellEditor != null) {
355
		if (cellEditor != null) {
258
			applyEditorValue();
356
			applyEditorValue();
259
		}
357
		}
260
358
261
        // activate the cell editor immediately.  If a second mouseDown
359
		// activate the cell editor immediately. If a second mouseDown
262
        // is received prior to the expiration of the doubleClick time then
360
		// is received prior to the expiration of the doubleClick time then
263
        // the cell editor will be deactivated and a doubleClick event will
361
		// the cell editor will be deactivated and a doubleClick event will
264
        // be processed.
362
		// be processed.
265
        //
363
		//
266
        doubleClickExpirationTime = event.time
364
		doubleClickExpirationTime = event.time
267
                + Display.getCurrent().getDoubleClickTime();
365
				+ Display.getCurrent().getDoubleClickTime();
268
366
269
        Item[] items = getSelection();
367
		Item[] items = getSelection();
270
        // Do not edit if more than one row is selected.
368
		// Do not edit if more than one row is selected.
271
        if (items.length != 1) {
369
		if (items.length != 1) {
272
            tableItem = null;
370
			tableItem = null;
273
            return;
371
			return;
274
        }
372
		}
275
        tableItem = items[0];
373
		tableItem = items[0];
276
        activateCellEditor(event);
374
		activateCellEditor(event);
277
    }
375
	}
278
376
279
    private void initCellEditorListener() {
377
	private void initCellEditorListener() {
280
        cellEditorListener = new ICellEditorListener() {
378
		cellEditorListener = new ICellEditorListener() {
281
            public void editorValueChanged(boolean oldValidState,
379
			public void editorValueChanged(boolean oldValidState,
282
                    boolean newValidState) {
380
					boolean newValidState) {
283
                // Ignore.
381
				// Ignore.
284
            }
382
			}
285
383
286
            public void cancelEditor() {
384
			public void cancelEditor() {
287
                TableEditorImpl.this.cancelEditing();
385
				TableEditorImpl.this.cancelEditing();
288
            }
386
			}
289
387
290
            public void applyEditorValue() {
388
			public void applyEditorValue() {
291
                TableEditorImpl.this.applyEditorValue();
389
				TableEditorImpl.this.applyEditorValue();
292
            }
390
			}
293
        };
391
		};
294
    }
392
	}
295
393
296
    /**
394
	/**
297
     * Return whether there is an active cell editor.
395
	 * Return whether there is an active cell editor.
298
     * 
396
	 * 
299
     * @return <code>true</code> if there is an active cell editor; otherwise
397
	 * @return <code>true</code> if there is an active cell editor; otherwise
300
     * <code>false</code> is returned.
398
	 *         <code>false</code> is returned.
301
     */
399
	 */
302
    public boolean isCellEditorActive() {
400
	public boolean isCellEditorActive() {
303
        return cellEditor != null;
401
		return cellEditor != null;
304
    }
402
	}
305
403
306
    /**
404
	/**
307
     * Saves the value of the currently active cell editor,
405
	 * Saves the value of the currently active cell editor, by delegating to the
308
     * by delegating to the cell modifier.
406
	 * cell modifier.
309
     */
407
	 */
310
    private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
408
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
311
        if (cellModifier != null) {
409
		if( cellEditors != null ) {
312
            if (!cellEditor.isValueValid()) {
410
			if (cellModifier != null) {
313
                ///Do what ???
411
				if (!cellEditor.isValueValid()) {
412
					// /Do what ???
413
				}
414
				String property = null;
415
				if (columnProperties != null
416
						&& columnNumber < columnProperties.length) {
417
					property = columnProperties[columnNumber];
418
				}
419
				cellModifier.modify(tableItem, property, cellEditor.getValue());
420
			}
421
		} else {
422
			IEditableColumn column = (IEditableColumn)((TableViewer)viewer).getTable().getColumn(columnNumber).getData(IEditableColumn.EDITING_SUPPORT_KEY);
423
            if( column instanceof IEditableMultiColumn ) {
424
            	((IEditableMultiColumn)column).setValue(tableItem.getData(),cellEditor.getValue(),columnNumber);
425
            } else {
426
            	column.setValue(tableItem.getData(),cellEditor.getValue());
314
            }
427
            }
315
            String property = null;
428
		}
316
            if (columnProperties != null
429
	}
317
                    && columnNumber < columnProperties.length) {
430
318
				property = columnProperties[columnNumber];
431
	/**
319
			}
432
	 * Set the cell editors
320
            cellModifier.modify(tableItem, property, cellEditor.getValue());
433
	 * 
321
        }
434
	 * @param editors
322
    }
435
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
323
436
	 */
324
    /**
437
	public void setCellEditors(CellEditor[] editors) {
325
     * Set the cell editors
438
		this.cellEditors = editors;
326
     * @param editors
439
	}
327
     */
440
328
    public void setCellEditors(CellEditor[] editors) {
441
	/**
329
        this.cellEditors = editors;
442
	 * Set the cell modifier
330
    }
443
	 * 
331
444
	 * @param modifier
332
    /**
445
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
333
     * Set the cell modifier
446
	 */
334
     * @param modifier
447
	public void setCellModifier(ICellModifier modifier) {
335
     */
448
		this.cellModifier = modifier;
336
    public void setCellModifier(ICellModifier modifier) {
449
	}
337
        this.cellModifier = modifier;
450
338
    }
451
	/**
339
452
	 * Set the column properties
340
    /**
453
	 * 
341
     * Set the column properties
454
	 * @param columnProperties
342
     * @param columnProperties
455
	 * @deprecated please use the new interface {@link AbstractEditableTableColumn}
343
     */
456
	 */
344
    public void setColumnProperties(String[] columnProperties) {
457
	public void setColumnProperties(String[] columnProperties) {
345
        this.columnProperties = columnProperties;
458
		this.columnProperties = columnProperties;
346
    }
459
	}
347
460
348
    abstract void setEditor(Control w, Item item, int fColumnNumber);
461
	abstract void setEditor(Control w, Item item, int fColumnNumber);
462
463
	abstract void setLayoutData(CellEditor.LayoutData layoutData);
349
464
350
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
465
	abstract void setSelection(StructuredSelection selection, boolean b);
351
466
352
    abstract void setSelection(StructuredSelection selection, boolean b);
467
	abstract void showSelection();
353
468
354
    abstract void showSelection();
469
	abstract void handleDoubleClickEvent();
355
470
356
    abstract void handleDoubleClickEvent();
471
	abstract TraverseListener getTabeditingListener();
357
}
472
}
(-)src/org/eclipse/jface/viewers/TableTreeViewer.java (+9 lines)
Lines 20-25 Link Here
20
import org.eclipse.swt.custom.TableTreeItem;
20
import org.eclipse.swt.custom.TableTreeItem;
21
import org.eclipse.swt.events.MouseAdapter;
21
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseEvent;
22
import org.eclipse.swt.events.MouseEvent;
23
import org.eclipse.swt.events.TraverseListener;
23
import org.eclipse.swt.events.TreeListener;
24
import org.eclipse.swt.events.TreeListener;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Point;
26
import org.eclipse.swt.graphics.Point;
Lines 107-112 Link Here
107
            fireDoubleClick(new DoubleClickEvent(viewer, viewer.getSelection()));
108
            fireDoubleClick(new DoubleClickEvent(viewer, viewer.getSelection()));
108
            fireOpen(new OpenEvent(viewer, viewer.getSelection()));
109
            fireOpen(new OpenEvent(viewer, viewer.getSelection()));
109
        }
110
        }
111
112
		/* (non-Javadoc)
113
		 * @see org.eclipse.jface.viewers.TableEditorImpl#getTabeditingListener()
114
		 */
115
        TraverseListener getTabeditingListener() {
116
			// TODO Auto-generated method stub
117
			return null;
118
		}
110
    }
119
    }
111
120
112
    /**
121
    /**
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 29-34 Link Here
29
 org.eclipse.jface.util,
29
 org.eclipse.jface.util,
30
 org.eclipse.jface.viewers,
30
 org.eclipse.jface.viewers,
31
 org.eclipse.jface.viewers.deferred,
31
 org.eclipse.jface.viewers.deferred,
32
 org.eclipse.jface.viewers.editing,
32
 org.eclipse.jface.window,
33
 org.eclipse.jface.window,
33
 org.eclipse.jface.wizard,
34
 org.eclipse.jface.wizard,
34
 org.eclipse.jface.wizard.images
35
 org.eclipse.jface.wizard.images
(-)src/org/eclipse/jface/viewers/TooltipSupport.java (+133 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
import org.eclipse.jface.viewers.TooltipSupportDataProvider.TooltipData;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Event;
17
import org.eclipse.swt.widgets.Listener;
18
import org.eclipse.swt.widgets.ToolTip;
19
20
/**
21
 * This class adds tooltip support to viewers whose LabelProvider implement the
22
 * none manadory interface {@link ITooltipProvider}. This class is not
23
 * dependent on any Viewer but uses TooltipSupportDataProvider to fetch all data
24
 * important to display the Tooltip
25
 * 
26
 * @since 3.3
27
 * @author Tom Schindl <tom.schindl@bestsolution.at>
28
 */
29
class TooltipSupport {
30
	private TooltipSupportDataProvider dataProvider;
31
32
	private ITooltipProvider tooltipPv;
33
34
	private Viewer viewer;
35
36
	private ToolTip tip;
37
38
	private TooltipListener tooltipListener;
39
40
	/**
41
	 * Create a new tooltip supported who displays tooltips when the mouse
42
	 * hovers an item in the viewer
43
	 * 
44
	 * @param viewer
45
	 *            the viewer
46
	 * @param dataProvider
47
	 *            class who provides information used to create the tooltip
48
	 */
49
	TooltipSupport(Viewer viewer, TooltipSupportDataProvider dataProvider) {
50
		this.viewer = viewer;
51
		this.dataProvider = dataProvider;
52
		this.tooltipListener = new TooltipListener();
53
	}
54
55
	/**
56
	 * Show up the tooltip to the user if possible
57
	 * 
58
	 * @param event
59
	 *            the mouse event occurred when the hovering the item
60
	 */
61
	private void showTooltip(Event event) {
62
		switch (event.type) {
63
		case SWT.MouseHover:
64
			TooltipData data = dataProvider.getData(event);
65
66
			if (data.columnIndex >= 0) {
67
				String content = tooltipPv.getTooltipText(data.modelObject,
68
						data.columnIndex);
69
70
				if (tip == null) {
71
					tip = new ToolTip(viewer.getControl().getShell(), SWT.NONE);
72
				} else {
73
					tip.setVisible(false);
74
				}
75
76
				if (content != null) {
77
					tip.setMessage(content);
78
					tip.setLocation(viewer.getControl().toDisplay(
79
							data.bounds.x, data.bounds.y));
80
					tip.setVisible(true);
81
				}
82
			}
83
			break;
84
		}
85
	}
86
87
	/**
88
	 * Configure the support for tooltips. If the label-provider passed is an
89
	 * instance of ITooltipProvider custom tooltips are turned for the
90
	 * underlying SWT-Widget if a normal LabelProvider is passed the
91
	 * TooltipSupport is turned off
92
	 * 
93
	 * @param labelProvider
94
	 *            the label provider
95
	 */
96
	void configureSupport(IBaseLabelProvider labelProvider) {
97
		if (labelProvider instanceof ITooltipProvider) {
98
			if (tooltipPv == null) {
99
				viewer.getControl().addListener(SWT.Dispose, tooltipListener);
100
				viewer.getControl().addListener(SWT.KeyDown, tooltipListener);
101
				viewer.getControl().addListener(SWT.MouseMove, tooltipListener);
102
				viewer.getControl()
103
						.addListener(SWT.MouseHover, tooltipListener);
104
			}
105
			tooltipPv = (ITooltipProvider) labelProvider;
106
		} else {
107
			if (tooltipPv != null) {
108
				viewer.getControl()
109
						.removeListener(SWT.Dispose, tooltipListener);
110
				viewer.getControl()
111
						.removeListener(SWT.KeyDown, tooltipListener);
112
				viewer.getControl().removeListener(SWT.MouseMove,
113
						tooltipListener);
114
				viewer.getControl().removeListener(SWT.MouseHover,
115
						tooltipListener);
116
				tooltipListener = null;
117
			}
118
			tooltipPv = null;
119
		}
120
	}
121
122
	/**
123
	 * Table Listener used to inform for widget events
124
	 * 
125
	 * @since 3.3
126
	 */
127
	private class TooltipListener implements Listener {
128
129
		public void handleEvent(Event event) {
130
			showTooltip(event);
131
		}
132
	}
133
}
(-)src/org/eclipse/jface/viewers/TooltipSupportDataProvider.java (+55 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
import org.eclipse.swt.graphics.Rectangle;
15
import org.eclipse.swt.widgets.Event;
16
17
/**
18
 * This class is responsible for providing the data used by the
19
 * {@link TooltipSupport}. This class gives TooltipSupport the possibility to
20
 * be completely independent from the viewer it is working for
21
 * 
22
 * @since 3.3
23
 * @author Tom Schindl <tom.schindl@bestsolution.at>
24
 */
25
public abstract class TooltipSupportDataProvider {
26
	/**
27
	 * @param event
28
	 *            the event that occurred
29
	 * @return the data needed by TooltipSupport
30
	 */
31
	public abstract TooltipData getData(Event event);
32
33
	/**
34
	 * Wrapps up all data needed so they can be returned by one function call
35
	 * 
36
	 * @since 3.3
37
	 * @author Tom Schindl <tom.schindl@bestsolution.at>
38
	 */
39
	protected class TooltipData {
40
		/**
41
		 * 
42
		 */
43
		public int columnIndex = -1;
44
45
		/**
46
		 * 
47
		 */
48
		public Rectangle bounds = null;
49
50
		/**
51
		 * 
52
		 */
53
		public Object modelObject = null;
54
	}
55
}
(-)src/org/eclipse/jface/viewers/ITooltipProvider.java (+33 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
 * 
16
 * If you want to provide custom tooltips your LabelProvider should implement
17
 * this interface
18
 * 
19
 * @since 3.3
20
 * 
21
 */
22
public interface ITooltipProvider {
23
	/**
24
	 * Get the tooltip for the selected item
25
	 * 
26
	 * @param object
27
	 *            the model object
28
	 * @param columnIndex
29
	 *            the index of the column
30
	 * @return the tooltip displayed
31
	 */
32
	public String getTooltipText(Object object, int columnIndex);
33
}
(-)src/org/eclipse/jface/viewers/editing/TabulatorTraversingDelegate.java (+205 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.editing;
13
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.TraverseEvent;
17
18
/**
19
 * TableViewer delegates tabulator traversing to the class which implements how
20
 * elements are the next column in the table is selected. You may sub-class this
21
 * class and implement your own selection algorithm.
22
 * 
23
 * @author Tom Schindl <tom.schindl@bestsolution.at>
24
 * 
25
 * @since 3.3
26
 * @see TableViewer#setTabeditingDelegate(TabEditingDelegate)
27
 * @see TableViewer#setTabulatorTraversalEnabled(boolean)
28
 * 
29
 */
30
public class TabulatorTraversingDelegate {
31
	private boolean moveToRowNeighbor = false;
32
33
	private boolean cycleInRow = false;
34
35
	private boolean rowTabing = true;
36
37
	private boolean columnTabing = true;
38
39
	/**
40
	 * This method is called when in the actually active cell-editor a traversal
41
	 * event is kicked of by the user. Subclasses may override this method to
42
	 * implement their own selection mechanism.
43
	 * 
44
	 * @param e
45
	 *            the traversal event
46
	 * 
47
	 * @param activeColumn
48
	 *            the currently active column
49
	 * @param totalColumns
50
	 *            the totla number of columns
51
	 * @param activeRow
52
	 *            the active row
53
	 * @param totalRows
54
	 *            the total number of rows
55
	 * @param viewer
56
	 *            the viewer which support tabing
57
	 * @param widgetWrapper
58
	 *            the swt wigdet wrapped in a helper class
59
	 * @return true of a new column is activated
60
	 * @since 3.3
61
	 */
62
	public boolean focusNewEditor(TraverseEvent e, ITabulatorTraversingSupport viewer,
63
			TabulatorTraversingSupportWrapper widgetWrapper) {
64
		// FIXME WHAT TO DO WHEN THE NEXT COLUMN IS NOT EDITABLE/HAS NO FOCUS
65
		
66
		int activeColumn = widgetWrapper.getCurrentColumnIndex();
67
		int totalColumns = widgetWrapper.getColumnCount();
68
		int activeRow = widgetWrapper.getCurrentRowIndex(); 
69
		int totalRows = widgetWrapper.getRowCount();
70
		
71
		int editColumn = -1;
72
73
		if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
74
			e.doit = false;
75
76
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
77
				if (activeRow > 0) {
78
					widgetWrapper.setSelectedRow(--activeRow);
79
					editColumn = activeColumn;
80
				}
81
			} else if (columnTabing) {
82
				if (activeColumn > 0) {
83
					editColumn = --activeColumn;
84
				} else if (cycleInRow) {
85
					editColumn = totalColumns - 1;
86
				} else if (moveToRowNeighbor) {
87
					if (activeRow > 0) {
88
						widgetWrapper.setSelectedRow(--activeRow);
89
						editColumn = totalColumns - 1;
90
					}
91
				}
92
			}
93
		} else if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
94
			e.doit = false;
95
96
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
97
				if (activeRow < totalRows - 1) {
98
					widgetWrapper.setSelectedRow(++activeRow);
99
					editColumn = activeColumn;
100
				}
101
			} else if (columnTabing) {
102
				if (activeColumn < totalColumns - 1) {
103
					editColumn = ++activeColumn;
104
				} else if (cycleInRow) {
105
					editColumn = 0;
106
				} else if (moveToRowNeighbor) {
107
					if (activeRow < totalRows - 1) {
108
						widgetWrapper.setSelectedRow(++activeRow);
109
						editColumn = 0;
110
					}
111
				}
112
			}
113
		}
114
115
		if (editColumn >= 0) {
116
			viewer.editElement(((IStructuredSelection) viewer.getSelection())
117
					.getFirstElement(), editColumn);
118
			return true;
119
		}
120
121
		return false;
122
	}
123
124
	/**
125
	 * @return Returns the columnTabing.
126
	 * @since 3.3
127
	 */
128
	public boolean isColumnTabing() {
129
		return columnTabing;
130
	}
131
132
	/**
133
	 * Setting this to true the user can move from column to column pressing TAB
134
	 * and SHIFT+TAB. This is turned on by default.
135
	 * 
136
	 * @param columnTabing
137
	 *            The columnTabing to set.
138
	 * @since 3.3
139
	 */
140
	public void setColumnTabing(boolean columnTabing) {
141
		this.columnTabing = columnTabing;
142
	}
143
144
	/**
145
	 * @return Returns the cycleInRow.
146
	 * @since 3.3
147
	 */
148
	public boolean isCycleInRow() {
149
		return cycleInRow;
150
	}
151
152
	/**
153
	 * Setting this to true results in the fact that when the end of the row is
154
	 * reached the cursor is moved to the first column in the row. This is
155
	 * turned of by default.
156
	 * 
157
	 * @param cycleInRow
158
	 *            The cycleInRow to set.
159
	 * @since 3.3
160
	 */
161
	public void setCycleInRow(boolean cycleInRow) {
162
		this.cycleInRow = cycleInRow;
163
	}
164
165
	/**
166
	 * Setting this to true results in the fact that when the end of the current
167
	 * row is reached the cursor is moved to first/last column in the
168
	 * successor/predecessor. This is turned of by default.
169
	 * 
170
	 * @return Returns the moveToRowNeighbor.
171
	 * @since 3.3
172
	 */
173
	public boolean isMoveToRowNeighbor() {
174
		return moveToRowNeighbor;
175
	}
176
177
	/**
178
	 * @param moveToRowNeighbor
179
	 *            The moveToRowNeighbor to set.
180
	 * @since 3.3
181
	 */
182
	public void setMoveToRowNeighbor(boolean moveToRowNeighbor) {
183
		this.moveToRowNeighbor = moveToRowNeighbor;
184
	}
185
186
	/**
187
	 * @return Returns the rowTabing.
188
	 * @since 3.3
189
	 */
190
	public boolean isRowTabing() {
191
		return rowTabing;
192
	}
193
194
	/**
195
	 * Setting this to true results in the fact that you user can jump from row
196
	 * to row using CTRL+TAB/CTRL+SHIFT+TAB. This is turned on by default.
197
	 * 
198
	 * @param rowTabing
199
	 *            The rowTabing to set.
200
	 * @since 3.3
201
	 */
202
	public void setRowTabing(boolean rowTabing) {
203
		this.rowTabing = rowTabing;
204
	}
205
}
(-)src/org/eclipse/jface/viewers/editing/AbstractEditableTableColumn.java (+61 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.editing;
13
14
import org.eclipse.jface.viewers.TableViewer;
15
import org.eclipse.swt.widgets.TableColumn;
16
17
/**
18
 * This class represents an editable column in a table. It holds a Mapping
19
 * between Object types from your model and CellEditors used to edit the element
20
 * and is responsible for providing the cell-editor values to the editor and
21
 * restoring the values after editing has finished
22
 * 
23
 * @author Tom Schindl <tom.schindl@bestsolution.at>
24
 * @since 3.3
25
 */
26
public abstract class AbstractEditableTableColumn extends AbstractEditingColumn {
27
28
	private TableColumn tableColumn;
29
30
	/**
31
	 * Creates a new TableColumn which supports editing
32
	 * 
33
	 * @param viewer
34
	 *            the viewer the column is child of
35
	 * @param style
36
	 *            the style used for the column
37
	 * @since 3.3
38
	 */
39
	public AbstractEditableTableColumn(TableViewer viewer, int style) {
40
		this(new TableColumn(viewer.getTable(), style));
41
	}
42
43
	/**
44
	 * Add support for editing to the tablecolumn
45
	 * 
46
	 * @param tableColumn
47
	 *            column which should provide editing support
48
	 */
49
	public AbstractEditableTableColumn(TableColumn tableColumn) {
50
		super(tableColumn);
51
		this.tableColumn = tableColumn;
52
	}
53
54
	protected void doSetText(String text) {
55
		this.tableColumn.setText(text);
56
	}
57
58
	protected void doSetWidth(int width) {
59
		this.tableColumn.setWidth(width);
60
	}
61
}
(-)src/org/eclipse/jface/viewers/editing/TabulatorTraversingSupportWrapper.java (+55 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.editing;
13
14
/**
15
 * This class wraps calls to really objects because they are not accessible
16
 * through an interface because they are done on the concrete SWT-Classes e.g.
17
 * Tree/Table/...
18
 * 
19
 * @author Tom Schindl <tom.schindl@bestsolution.at>
20
 * @since 3.3
21
 */
22
public abstract class TabulatorTraversingSupportWrapper {
23
	/**
24
	 * Set the current selected row
25
	 * 
26
	 * @param index
27
	 *            the new row index
28
	 * @since 3.3
29
	 */
30
	public abstract void setSelectedRow(int index);
31
32
	/**
33
	 * @return the total number of columns
34
	 * @since 3.3
35
	 */
36
	public abstract int getColumnCount();
37
38
	/**
39
	 * @return the total number of rows
40
	 * @since 3.3
41
	 */
42
	public abstract int getRowCount();
43
44
	/**
45
	 * @return the current column index
46
	 * @since 3.3
47
	 */
48
	public abstract int getCurrentColumnIndex();
49
50
	/**
51
	 * @return the current row index
52
	 * @since 3.3
53
	 */
54
	public abstract int getCurrentRowIndex();
55
}
(-)src/org/eclipse/jface/viewers/editing/AbstractEditingColumn.java (+74 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.editing;
13
14
import java.util.HashMap;
15
16
import org.eclipse.jface.viewers.CellEditor;
17
import org.eclipse.swt.widgets.Item;
18
19
/**
20
 * 
21
 * @since 3.3
22
 */
23
public abstract class AbstractEditingColumn implements IEditableColumn {
24
25
	/**
26
	 * The map between object types and cell-editors
27
	 */
28
	private HashMap cellEditors = new HashMap();
29
30
	protected AbstractEditingColumn(Item swtColumn) {
31
		swtColumn.setData(EDITING_SUPPORT_KEY, this);
32
	}
33
34
	public CellEditor getCellEditor(Object element) {
35
		return (CellEditor) this.cellEditors.get(element.getClass());
36
	}
37
38
	/**
39
	 * Add a mapping for the model element class type to your own type
40
	 * 
41
	 * @param elementType
42
	 *            the element type used
43
	 * @param cellEditor
44
	 *            the cell-editor used to edit this model element
45
	 * @since 3.3
46
	 */
47
	public void addCellEditorMapping(Class elementType, CellEditor cellEditor) {
48
		this.cellEditors.put(elementType, cellEditor);
49
	}
50
51
	/**
52
	 * Sets the column's text.
53
	 * 
54
	 * @param text
55
	 *            displayed in the column header
56
	 */
57
	public void setText(String text) {
58
		doSetText(text);
59
	}
60
61
	/**
62
	 * Set the column's width
63
	 * 
64
	 * @param width
65
	 *            the width of the column
66
	 */
67
	public void setWidth(int width) {
68
		doSetWidth(width);
69
	}
70
71
	protected abstract void doSetText(String text);
72
73
	protected abstract void doSetWidth(int width);
74
}
(-)src/org/eclipse/jface/viewers/editing/ITabulatorTraversingSupport.java (+78 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.editing;
13
14
import org.eclipse.jface.viewers.ISelection;
15
16
/**
17
 * Viewers who want to provide tabulator traversal features have to implement
18
 * this interface.
19
 * 
20
 * @author Tom Schindl <tom.schindl@bestsolution.at>
21
 * @since 3.3
22
 */
23
public interface ITabulatorTraversingSupport {
24
25
	/**
26
	 * @param tabulatorTraversalEnabled
27
	 *            Turn on/off tab-editing support
28
	 * @since 3.3
29
	 */
30
	public void setTabulatorTraversalEnabled(boolean tabulatorTraversalEnabled);
31
32
	/**
33
	 * @return is tab-editing turned on
34
	 * @since 3.3
35
	 */
36
	public boolean isTabulatorTraversalEnabled();
37
38
	/**
39
	 * Set your own tab-editing delegate
40
	 * 
41
	 * @param tabeditingDelgate
42
	 *            the new delegate
43
	 * @since 3.3
44
	 */
45
	public void setTabeditingDelegate(
46
			TabulatorTraversingDelegate tabeditingDelgate);
47
48
	/**
49
	 * @return the tabediting delegate
50
	 * @since 3.3
51
	 */
52
	public TabulatorTraversingDelegate getTabeditingDelgate();
53
54
	/**
55
	 * Starts editing the given element.
56
	 * 
57
	 * @param element
58
	 *            the element
59
	 * @param column
60
	 *            the column number
61
	 * @see TableViewer#editElement(Object, int)
62
	 * @see AdvancedTreeViewer#editElement(Object, int)
63
	 */
64
	public void editElement(Object element, int column);
65
66
	/**
67
	 * The <code>StructuredViewer</code> implementation of this method returns
68
	 * the result as an <code>IStructuredSelection</code>.
69
	 * <p>
70
	 * Subclasses do not typically override this method, but implement
71
	 * <code>getSelectionFromWidget(List)</code> instead.
72
	 * <p>
73
	 * 
74
	 * @return ISelection
75
	 * @see ISelectionProvider#getSelection()
76
	 */
77
	public ISelection getSelection();
78
}
(-)src/org/eclipse/jface/viewers/editing/IEditableMultiColumn.java (+80 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.editing;
13
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.ICellModifier;
16
17
/**
18
 * This interface can be used if there are multiple columns using the same
19
 * editor. The resulting code is very similar to the one found in:
20
 * <ul>
21
 * <li>{@link ICellModifier#modify(Object, String, Object)}</li>
22
 * <li>{@link ICellModifier#getValue(Object, String)} </li>
23
 * </ul>
24
 * 
25
 * @author Tom Schindl <tom.schindl@bestsolution.at>
26
 * @since 3.3
27
 */
28
public interface IEditableMultiColumn extends IEditableColumn {
29
30
	/**
31
	 * Fetch the cell editor for this model element
32
	 * 
33
	 * @param element
34
	 *            the model element
35
	 * @param columnIndex
36
	 *            the current column index
37
	 * @return the celleditor or null if none is known for this object type
38
	 * @since 3.3
39
	 */
40
	public CellEditor getCellEditor(Object element, int columnIndex);
41
	
42
	/**
43
	 * enable/disable editing
44
	 * 
45
	 * @param element
46
	 *            the model element which should be edited
47
	 * @param columnIndex
48
	 *            the current column index
49
	 * @return true if a editor should be displayed
50
	 * @since 3.3
51
	 */
52
	public boolean canEdit(Object element, int columnIndex);
53
54
	/**
55
	 * fetch the value for the desired column index passed on to the CellEditor
56
	 * 
57
	 * @param element
58
	 *            the model element
59
	 * @param columnIndex
60
	 *            the column-index
61
	 * @return the value for editing
62
	 * @see AbstractEditableTableColumn#getValue(Object)
63
	 * @see AbstractEditableTreeColumn#getValue(Object)
64
	 * @since 3.3
65
	 */
66
	public abstract Object getValue(Object element, int columnIndex);
67
68
	/**
69
	 * restore the value from the editor in the model object
70
	 * 
71
	 * @param element
72
	 *            the model element
73
	 * @param value
74
	 *            the value entered into the cell-editor
75
	 * @param columnIndex
76
	 *            the current column index
77
	 * @since 3.3
78
	 */
79
	public abstract void setValue(Object element, Object value, int columnIndex);
80
}
(-)src/org/eclipse/jface/viewers/editing/IEditableColumn.java (+69 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.editing;
13
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.swt.widgets.Item;
16
17
/**
18
 * This interface has to be implemented by any editable Column which is added to
19
 * a TreeViewer or a TableViewer
20
 * 
21
 * @author Tom Schindl <tom.schindl@bestsolution.at>
22
 * @since 3.3
23
 */
24
public interface IEditableColumn {
25
	
26
	/**
27
	 * Key used to restore editing support into {@link Item#setData(String, Object)}
28
	 */
29
	public static final String EDITING_SUPPORT_KEY = "editingSupport"; //$NON-NLS-1$
30
	
31
	/**
32
	 * Fetch the cell editor for this model element
33
	 * 
34
	 * @param element
35
	 *            the model element
36
	 * @return the celleditor or null if none is known for this object type
37
	 * @since 3.3
38
	 */
39
	public CellEditor getCellEditor(Object element);
40
41
	/**
42
	 * enable/disable editing
43
	 * 
44
	 * @param element
45
	 *            the model element which should be edited
46
	 * @return true if a editor should be displayed
47
	 * @since 3.3
48
	 */
49
	public boolean canEdit(Object element);
50
51
	/**
52
	 * @param element
53
	 *            the model element
54
	 * @return the value which is put in the cell-editor when it pops up
55
	 * @since 3.3
56
	 */
57
	public Object getValue(Object element);
58
59
	/**
60
	 * Restore the value in the model element
61
	 * 
62
	 * @param element
63
	 *            the model element
64
	 * @param value
65
	 *            the new value from the cell-editor
66
	 * @since 3.3
67
	 */
68
	public void setValue(Object element, Object value);
69
}
(-)src/org/eclipse/jface/viewers/editing/AbstractEditableTreeColumn.java (+60 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.editing;
13
14
import org.eclipse.jface.viewers.TreeViewer;
15
import org.eclipse.swt.widgets.TreeColumn;
16
17
/**
18
 * This class represents an editable column in a tree. It holds a Mapping
19
 * between Object types from your model and CellEditors used to edit the element
20
 * and is responsible for providing the cell-editor values to the editor and
21
 * restoring the values after editing has finished
22
 * 
23
 * @author Tom Schindl <tom.schindl@bestsolution.at>
24
 * @since 3.3
25
 */
26
public abstract class AbstractEditableTreeColumn extends AbstractEditingColumn {
27
	private TreeColumn treeColumn;
28
29
	/**
30
	 * Creates a new TreeColumn which supports editing
31
	 * 
32
	 * @param parent
33
	 *            the viewer the column is child of
34
	 * @param style
35
	 *            the style used for the column
36
	 * @since 3.3
37
	 */
38
	public AbstractEditableTreeColumn(TreeViewer parent, int style) {
39
		this(new TreeColumn(parent.getTree(), style));
40
	}
41
42
	/**
43
	 * Add support for editing to the treecolumn
44
	 * 
45
	 * @param treeColumn
46
	 *            column which should provide editing support
47
	 */
48
	public AbstractEditableTreeColumn(TreeColumn treeColumn) {
49
		super(treeColumn);
50
		this.treeColumn = treeColumn;
51
	}
52
53
	protected void doSetText(String text) {
54
		this.treeColumn.setText(text);
55
	}
56
57
	protected void doSetWidth(int width) {
58
		this.treeColumn.setWidth(width);
59
	}
60
}

Return to bug 142655