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

Collapse All | Expand All

(-)Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java (-1 / +4 lines)
Lines 12-21 Link Here
12
package org.eclipse.jface.snippets.viewers;
12
package org.eclipse.jface.snippets.viewers;
13
13
14
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.ColumnViewerEditor;
16
import org.eclipse.jface.viewers.ColumnViewerKeyboardSupport;
15
import org.eclipse.jface.viewers.EditingSupport;
17
import org.eclipse.jface.viewers.EditingSupport;
16
import org.eclipse.jface.viewers.ICellModifier;
18
import org.eclipse.jface.viewers.ICellModifier;
17
import org.eclipse.jface.viewers.IStructuredContentProvider;
19
import org.eclipse.jface.viewers.IStructuredContentProvider;
18
import org.eclipse.jface.viewers.LabelProvider;
20
import org.eclipse.jface.viewers.LabelProvider;
21
import org.eclipse.jface.viewers.TableColumnViewerEditor;
19
import org.eclipse.jface.viewers.TableViewer;
22
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.jface.viewers.TextCellEditor;
23
import org.eclipse.jface.viewers.TextCellEditor;
21
import org.eclipse.jface.viewers.Viewer;
24
import org.eclipse.jface.viewers.Viewer;
Lines 111-117 Link Here
111
		
114
		
112
		v.setColumnProperties(new String[] { "column1", "column2" });
115
		v.setColumnProperties(new String[] { "column1", "column2" });
113
		v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
116
		v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
114
		v.setTabEditingStyle(EditingSupport.TABBING_HORIZONTAL|EditingSupport.TABBING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABBING_VERTICAL);
117
		v.setColumnViewerEditor(new TableColumnViewerEditor(v,new ColumnViewerKeyboardSupport(v),ColumnViewerEditor.TABBING_HORIZONTAL|ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|ColumnViewerEditor.TABBING_VERTICAL));
115
		
118
		
116
		
119
		
117
		MyModel[] model = createModel();
120
		MyModel[] model = createModel();
(-)Eclipse (+203 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Tom Schindl and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tom Schindl - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jface.snippets.viewers;
13
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.viewers.CellEditor;
17
import org.eclipse.jface.viewers.CellEditorActivationEvent;
18
import org.eclipse.jface.viewers.ColumnLabelProvider;
19
import org.eclipse.jface.viewers.ColumnViewerEditorActivationSupport;
20
import org.eclipse.jface.viewers.EditingSupport;
21
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
22
import org.eclipse.jface.viewers.ITreeContentProvider;
23
import org.eclipse.jface.viewers.SWTCellFocusManager;
24
import org.eclipse.jface.viewers.TextCellEditor;
25
import org.eclipse.jface.viewers.TreeFocusCellManager;
26
import org.eclipse.jface.viewers.TreeViewer;
27
import org.eclipse.jface.viewers.TreeViewerColumn;
28
import org.eclipse.jface.viewers.Viewer;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.layout.FillLayout;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Shell;
33
34
/**
35
 * A simple TreeViewer to demonstrate usage
36
 * 
37
 * @author Tom Schindl <tom.schindl@bestsolution.at>
38
 * 
39
 */
40
public class Snippet026TreeViewerTabEditing {
41
	public Snippet026TreeViewerTabEditing(final Shell shell) {
42
		final TreeViewer v = new TreeViewer(shell, SWT.BORDER
43
				| SWT.FULL_SELECTION);
44
		v.getTree().setLinesVisible(true);
45
		v.getTree().setHeaderVisible(true);
46
47
		TreeFocusCellManager focusCellManager = new TreeFocusCellManager(new FocusCellOwnerDrawHighlighter(v), new ColumnViewerCellNavigationStrategy());
48
		ColumnViewerEditorActivationSupport actSupport = new ColumnViewerEditorActivationSupport(
49
				v, cellSupport) {
50
51
			protected boolean isEditorActivationEvent(
52
					CellEditorActivationEvent event) {
53
				return event.eventType == CellEditorActivationEvent.TRAVERSAL
54
						|| event.eventType == CellEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
55
						|| (event.eventType == CellEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
56
						|| event.eventType == CellEditorActivationEvent.PROGRAMATIC;
57
			}
58
59
		};
60
		
61
		TreeColumnViewerEditor treeViewerEditor = new TreeColumnViewerEditor (v, focusCellManager /*oder null fuer keine focus cell*/, actSupport, TreeColumnViewerEditor.TABBING_HORIZONTAL);
62
		v.setEditor(treeViewerEditor);
63
		
64
		final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
65
66
		TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
67
		column.getColumn().setWidth(200);
68
		column.getColumn().setText("Column 1");
69
		column.setLabelProvider(new ColumnLabelProvider() {
70
71
			public String getText(Object element) {
72
				return "Column 1 => " + element.toString();
73
			}
74
75
		});
76
		column.setEditingSupport(new EditingSupport(v) {
77
			protected boolean canEdit(Object element) {
78
				return true;
79
			}
80
81
			protected CellEditor getCellEditor(Object element) {
82
				return textCellEditor;
83
			}
84
85
			protected Object getValue(Object element) {
86
				return ((MyModel) element).counter + "";
87
			}
88
89
			protected void setValue(Object element, Object value) {
90
				((MyModel) element).counter = Integer
91
						.parseInt(value.toString());
92
				v.update(element, null);
93
			}
94
		});
95
		v.setTabEditingStyle(EditingSupport.TABBING_HORIZONTAL
96
				| EditingSupport.TABBING_MOVE_TO_ROW_NEIGHBOR
97
				| EditingSupport.TABBING_VERTICAL);
98
99
		column = new TreeViewerColumn(v, SWT.NONE);
100
		column.getColumn().setWidth(200);
101
		column.getColumn().setText("Column 2");
102
		column.setLabelProvider(new ColumnLabelProvider() {
103
104
			public String getText(Object element) {
105
				return "Column 2 => " + element.toString();
106
			}
107
108
		});
109
		
110
		v.setContentProvider(new MyContentProvider());
111
112
		v.setInput(createModel());
113
	}
114
115
	private MyModel createModel() {
116
117
		MyModel root = new MyModel(0, null);
118
		root.counter = 0;
119
120
		MyModel tmp;
121
		MyModel subItem;
122
		for (int i = 1; i < 10; i++) {
123
			tmp = new MyModel(i, root);
124
			root.child.add(tmp);
125
			for (int j = 1; j < i; j++) {
126
				subItem = new MyModel(j, tmp);
127
				subItem.child.add(new MyModel(j * 100, subItem));
128
				tmp.child.add(subItem);
129
			}
130
		}
131
132
		return root;
133
	}
134
135
	public static void main(String[] args) {
136
		Display display = new Display();
137
		Shell shell = new Shell(display);
138
		shell.setLayout(new FillLayout());
139
		new Snippet026TreeViewerTabEditing(shell);
140
		shell.open();
141
142
		while (!shell.isDisposed()) {
143
			if (!display.readAndDispatch())
144
				display.sleep();
145
		}
146
147
		display.dispose();
148
	}
149
150
	private class MyContentProvider implements ITreeContentProvider {
151
152
		public Object[] getElements(Object inputElement) {
153
			return ((MyModel) inputElement).child.toArray();
154
		}
155
156
		public void dispose() {
157
		}
158
159
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
160
		}
161
162
		public Object[] getChildren(Object parentElement) {
163
			return getElements(parentElement);
164
		}
165
166
		public Object getParent(Object element) {
167
			if (element == null) {
168
				return null;
169
			}
170
			return ((MyModel) element).parent;
171
		}
172
173
		public boolean hasChildren(Object element) {
174
			return ((MyModel) element).child.size() > 0;
175
		}
176
177
	}
178
179
	public class MyModel {
180
		public MyModel parent;
181
182
		public ArrayList child = new ArrayList();
183
184
		public int counter;
185
186
		public MyModel(int counter, MyModel parent) {
187
			this.parent = parent;
188
			this.counter = counter;
189
		}
190
191
		public String toString() {
192
			String rv = "Item ";
193
			if (parent != null) {
194
				rv = parent.toString() + ".";
195
			}
196
197
			rv += counter;
198
199
			return rv;
200
		}
201
	}
202
203
}
(-)src/org/eclipse/jface/viewers/TableViewer.java (-33 / +1 lines)
Lines 16-24 Link Here
16
16
17
17
18
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.jface.viewers.CellEditor.LayoutData;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.TableEditor;
22
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
Lines 67-77 Link Here
67
	private Table table;
65
	private Table table;
68
66
69
	/**
67
	/**
70
	 * This viewer's table editor.
71
	 */
72
	private TableEditor tableEditor;
73
74
	/**
75
	 * Creates a table viewer on a newly-created table control under the given
68
	 * Creates a table viewer on a newly-created table control under the given
76
	 * parent. The table control is created using the SWT style bits
69
	 * parent. The table control is created using the SWT style bits
77
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
70
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
Lines 110-116 Link Here
110
	 */
103
	 */
111
	public TableViewer(Table table) {
104
	public TableViewer(Table table) {
112
		this.table = table;
105
		this.table = table;
113
		tableEditor = new TableEditor(table);
114
		hookControl(table);
106
		hookControl(table);
115
	}
107
	}
116
108
Lines 128-158 Link Here
128
	}
120
	}
129
	
121
	
130
	protected ColumnViewerEditor createViewerEditor() {
122
	protected ColumnViewerEditor createViewerEditor() {
131
		return new ColumnViewerEditor(this) {
123
		return new TableColumnViewerEditor(this,new ColumnViewerKeyboardSupport(this),ColumnViewerEditor.DEFAULT);
132
133
			protected StructuredSelection createSelection(Object element) {
134
				return new StructuredSelection(element);
135
			}
136
137
			protected Item[] getSelection() {
138
				return table.getSelection();
139
			}
140
141
			protected void setEditor(Control w, Item item, int fColumnNumber) {
142
				tableEditor.setEditor(w, (TableItem) item, fColumnNumber);
143
			}
144
145
			protected void setLayoutData(LayoutData layoutData) {
146
				tableEditor.grabHorizontal = layoutData.grabHorizontal;
147
				tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
148
				tableEditor.minimumWidth = layoutData.minimumWidth;
149
			}
150
151
			protected void showSelection() {
152
				table.showSelection();
153
			}
154
155
		};
156
	}
124
	}
157
	
125
	
158
	/**
126
	/**
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-37 / +1 lines)
Lines 16-24 Link Here
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.jface.util.Policy;
18
import org.eclipse.jface.util.Policy;
19
import org.eclipse.jface.viewers.CellEditor.LayoutData;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.TreeEditor;
22
import org.eclipse.swt.events.DisposeEvent;
20
import org.eclipse.swt.events.DisposeEvent;
23
import org.eclipse.swt.events.DisposeListener;
21
import org.eclipse.swt.events.DisposeListener;
24
import org.eclipse.swt.events.TreeEvent;
22
import org.eclipse.swt.events.TreeEvent;
Lines 63-73 Link Here
63
	private Tree tree;
61
	private Tree tree;
64
62
65
	/**
63
	/**
66
	 * This viewer's tree editor.
67
	 */
68
	private TreeEditor treeEditor;
69
70
	/**
71
	 * Flag for whether the tree has been disposed of.
64
	 * Flag for whether the tree has been disposed of.
72
	 */
65
	 */
73
	private boolean treeIsDisposed = false;
66
	private boolean treeIsDisposed = false;
Lines 116-122 Link Here
116
		super();
109
		super();
117
		this.tree = tree;
110
		this.tree = tree;
118
		hookControl(tree);
111
		hookControl(tree);
119
		treeEditor = new TreeEditor(tree);
120
	}
112
	}
121
113
122
	/*
114
	/*
Lines 274-308 Link Here
274
	}
266
	}
275
267
276
	protected ColumnViewerEditor createViewerEditor() {
268
	protected ColumnViewerEditor createViewerEditor() {
277
		return new ColumnViewerEditor(this) {
269
		return new TreeColumnViewerEditor(this,new ColumnViewerKeyboardSupport(this),ColumnViewerEditor.DEFAULT);
278
279
			protected StructuredSelection createSelection(Object element) {
280
				if (element instanceof TreePath) {
281
					return new TreeSelection((TreePath) element, getComparer());
282
				}
283
284
				return new StructuredSelection(element);
285
			}
286
287
			protected Item[] getSelection() {
288
				return tree.getSelection();
289
			}
290
291
			protected void setEditor(Control w, Item item, int fColumnNumber) {
292
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
293
			}
294
295
			protected void setLayoutData(LayoutData layoutData) {
296
				treeEditor.grabHorizontal = layoutData.grabHorizontal;
297
				treeEditor.horizontalAlignment = layoutData.horizontalAlignment;
298
				treeEditor.minimumWidth = layoutData.minimumWidth;
299
			}
300
301
			protected void showSelection() {
302
				getTree().showSelection();
303
			}
304
305
		};
306
	}
270
	}
307
271
308
	/*
272
	/*
(-)src/org/eclipse/jface/viewers/EditingSupport.java (-193 / +1 lines)
Lines 13-21 Link Here
13
13
14
package org.eclipse.jface.viewers;
14
package org.eclipse.jface.viewers;
15
15
16
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.TraverseEvent;
19
18
20
/**
19
/**
21
 * EditingSupport is the abstract superclass of the support for cell editing.
20
 * EditingSupport is the abstract superclass of the support for cell editing.
Lines 27-58 Link Here
27
 * 
26
 * 
28
 */
27
 */
29
public abstract class EditingSupport {
28
public abstract class EditingSupport {
30
	/**
31
	 * Tabing from cell to cell is turned off
32
	 */
33
	public static final int TABBING_NONE = 1;
34
35
	/**
36
	 * Should if the end of the row is reach started from the start/end of the
37
	 * row below/above
38
	 */
39
	public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1;
40
41
	/**
42
	 * Should if the end of the row is reach started from the beginning in the
43
	 * same row
44
	 */
45
	public static final int TABBING_CYCLE_IN_ROW = 1 << 2;
46
47
	/**
48
	 * Support tabing to Cell above/below the current cell
49
	 */
50
	public static final int TABBING_VERTICAL = 1 << 3;
51
52
	/**
53
	 * Should tabing from column to column with in one row be supported
54
	 */
55
	public static final int TABBING_HORIZONTAL = 1 << 4;
56
29
57
	private ColumnViewer viewer;
30
	private ColumnViewer viewer;
58
31
Lines 103-273 Link Here
103
	 *            the new value
76
	 *            the new value
104
	 */
77
	 */
105
	protected abstract void setValue(Object element, Object value);
78
	protected abstract void setValue(Object element, Object value);
106
107
	/**
108
	 * @return <code>true</code> if tabing supported
109
	 */
110
	protected boolean isTabingSupported() {
111
		return (TABBING_NONE & getTabingStyle()) != TABBING_NONE;
112
	}
113
114
	/**
115
	 * @return the bit mask representing the tabing style
116
	 */
117
	int getTabingStyle() {
118
		return viewer.getTabEditingStyle();
119
	}
120
121
	/**
122
	 * Process the travers event and opens the next available editor depending
123
	 * of the implemented strategy. The default implementation uses the style
124
	 * constants
125
	 * <ul>
126
	 * <li>{@link #TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
127
	 * <li>{@link #TABBING_CYCLE_IN_ROW}</li>
128
	 * <li>{@link #TABBING_VERTICAL}</li>
129
	 * <li>{@link #TABBING_HORIZONTAL}</li>
130
	 * </ul>
131
	 * 
132
	 * <p>
133
	 * Subclasses may overwrite to implement their custom logic to edit the next
134
	 * cell
135
	 * </p>
136
	 * 
137
	 * @param columnIndex
138
	 *            the index of the current column
139
	 * @param row
140
	 *            the current row
141
	 * @param event
142
	 *            the travers event
143
	 */
144
	protected void processTraversEvent(int columnIndex,
145
			ViewerRow row, TraverseEvent event) {
146
		
147
		ViewerCell cell2edit = null;
148
149
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
150
			event.doit = false;
151
152
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
153
					&& (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) {
154
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true);
155
			} else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
156
				cell2edit = searchPreviousCell(row, viewer, columnIndex,
157
						columnIndex);
158
			}
159
		} else if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
160
			event.doit = false;
161
162
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
163
					&& (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) {
164
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex,
165
						false);
166
			} else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
167
				cell2edit = searchNextCell(row, viewer, columnIndex,
168
						columnIndex);
169
			}
170
		}
171
172
		if (cell2edit != null) {
173
			viewer.editElement(cell2edit.getElement(), cell2edit
174
					.getColumnIndex());
175
		}
176
	}
177
178
	private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer,
179
			int columnIndex, boolean above) {
180
		ViewerCell rv = null;
181
182
		ViewerRow newRow = null;
183
184
		if (above) {
185
			newRow = row.getNeighbor(ViewerRow.ABOVE, false);
186
		} else {
187
			newRow = row.getNeighbor(ViewerRow.BELOW,false);
188
		}
189
190
		if (newRow != null) {
191
			ViewerColumn column = viewer.getViewerColumn(columnIndex);
192
			if (column != null
193
					&& column.getEditingSupport().canEdit(
194
							newRow.getItem().getData())) {
195
				rv = newRow.getCell(columnIndex);
196
			} else {
197
				rv = searchCellAboveBelow(newRow, viewer, columnIndex, above);
198
			}
199
		}
200
201
		return rv;
202
	}
203
204
	private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer,
205
			int columnIndex, int startIndex) {
206
		ViewerCell rv = null;
207
208
		if (columnIndex - 1 >= 0) {
209
			ViewerColumn column = viewer.getViewerColumn(columnIndex - 1);
210
			if (column != null
211
					&& column.getEditingSupport().canEdit(
212
							row.getItem().getData())) {
213
				rv = row.getCell(columnIndex - 1);
214
			} else {
215
				rv = searchPreviousCell(row, viewer, columnIndex - 1,
216
						startIndex);
217
			}
218
		} else {
219
			if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
220
				// Check that we don't get into endless loop
221
				if (columnIndex - 1 != startIndex) {
222
					// Don't subtract -1 from getColumnCount() we need to
223
					// start in the virtual column
224
					// next to it
225
					rv = searchPreviousCell(row, viewer, row.getColumnCount(),
226
							startIndex);
227
				}
228
			} else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
229
				ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE,false);
230
				if (rowAbove != null) {
231
					rv = searchPreviousCell(rowAbove, viewer, rowAbove
232
							.getColumnCount(), startIndex);
233
				}
234
			}
235
		}
236
237
		return rv;
238
	}
239
240
	private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer,
241
			int columnIndex, int startIndex) {
242
		ViewerCell rv = null;
243
244
		if (columnIndex + 1 < row.getColumnCount()) {
245
			ViewerColumn column = viewer.getViewerColumn(columnIndex + 1);
246
			if (column != null
247
					&& column.getEditingSupport().canEdit(
248
							row.getItem().getData())) {
249
				rv = row.getCell(columnIndex + 1);
250
			} else {
251
				rv = searchNextCell(row, viewer, columnIndex + 1, startIndex);
252
			}
253
		} else {
254
			if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
255
				// Check that we don't get into endless loop
256
				if (columnIndex + 1 != startIndex) {
257
					// Start from -1 from the virtual column before the
258
					// first one
259
					rv = searchNextCell(row, viewer, -1, startIndex);
260
				}
261
			} else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
262
				ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW,false);
263
				if (rowBelow != null) {
264
					rv = searchNextCell(rowBelow, viewer, -1, startIndex);
265
				}
266
			}
267
		}
268
269
		return rv;
270
	}
271
	
79
	
272
	/**
80
	/**
273
	 * @return the viewer this editing support works for
81
	 * @return the viewer this editing support works for
(-)src/org/eclipse/jface/viewers/ColumnViewer.java (-75 / +130 lines)
Lines 14-19 Link Here
14
14
15
package org.eclipse.jface.viewers;
15
package org.eclipse.jface.viewers;
16
16
17
import java.util.List;
18
17
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.swt.events.MouseAdapter;
20
import org.eclipse.swt.events.MouseAdapter;
19
import org.eclipse.swt.events.MouseEvent;
21
import org.eclipse.swt.events.MouseEvent;
Lines 38-43 Link Here
38
 * 
40
 * 
39
 */
41
 */
40
public abstract class ColumnViewer extends StructuredViewer {
42
public abstract class ColumnViewer extends StructuredViewer {
43
	private CellEditor[] cellEditors;
44
45
	private ICellModifier cellModifier;
46
47
	private String[] columnProperties;
41
48
42
	private ToolTipSupport tooltipSupport;
49
	private ToolTipSupport tooltipSupport;
43
50
Lines 48-64 Link Here
48
55
49
	private ColumnViewerEditor viewerEditor;
56
	private ColumnViewerEditor viewerEditor;
50
57
51
	private int tabEditingStyle = EditingSupport.TABBING_NONE;
52
	
53
	/**
58
	/**
54
	 * Create a new instance of the receiver.
59
	 * Create a new instance of the receiver.
55
	 */
60
	 */
56
	public ColumnViewer() {
61
	public ColumnViewer() {
57
		viewerEditor = createViewerEditor();
62
		
58
	}
63
	}
59
64
60
	protected void hookControl(Control control) {
65
	protected void hookControl(Control control) {
61
		super.hookControl(control);
66
		super.hookControl(control);
67
		viewerEditor = createViewerEditor();
62
		hookEditingSupport(control);
68
		hookEditingSupport(control);
63
	}
69
	}
64
70
Lines 76-91 Link Here
76
		if (viewerEditor != null) {
82
		if (viewerEditor != null) {
77
			control.addMouseListener(new MouseAdapter() {
83
			control.addMouseListener(new MouseAdapter() {
78
				public void mouseDown(MouseEvent e) {
84
				public void mouseDown(MouseEvent e) {
79
					viewerEditor.handleMouseDown(e);
85
					handleMouseDown(e);
80
				}
86
				}
81
			});
87
			});
82
		}
88
		}
83
	}
89
	}
84
90
85
	/**
91
	/**
86
	 * Creates the viewer editor used for editing cell contents. To be implemented by subclasses.
92
	 * Creates the viewer editor used for editing cell contents. To be
93
	 * implemented by subclasses.
87
	 * 
94
	 * 
88
	 * @return the editor, or <code>null</code> if this viewer does not support editing cell contents.
95
	 * @return the editor, or <code>null</code> if this viewer does not
96
	 *         support editing cell contents.
89
	 */
97
	 */
90
	protected abstract ColumnViewerEditor createViewerEditor();
98
	protected abstract ColumnViewerEditor createViewerEditor();
91
99
Lines 95-101 Link Here
95
	 * 
103
	 * 
96
	 * @param point
104
	 * @param point
97
	 *            the widget-relative coordinates
105
	 *            the widget-relative coordinates
98
	 * @return the cell or <code>null</code> if no cell is found at the given point
106
	 * @return the cell or <code>null</code> if no cell is found at the given
107
	 *         point
99
	 */
108
	 */
100
	ViewerCell getCell(Point point) {
109
	ViewerCell getCell(Point point) {
101
		ViewerRow row = getViewerRow(point);
110
		ViewerRow row = getViewerRow(point);
Lines 127-133 Link Here
127
	/**
136
	/**
128
	 * Returns the viewer row associated with the given row widget.
137
	 * Returns the viewer row associated with the given row widget.
129
	 * 
138
	 * 
130
	 * @param item the row widget
139
	 * @param item
140
	 *            the row widget
131
	 * @return ViewerRow the associated viewer row
141
	 * @return ViewerRow the associated viewer row
132
	 */
142
	 */
133
	protected ViewerRow getViewerRowFromItem(Widget item) {
143
	protected ViewerRow getViewerRowFromItem(Widget item) {
Lines 137-143 Link Here
137
	/**
147
	/**
138
	 * Returns the column widget at the given column index.
148
	 * Returns the column widget at the given column index.
139
	 * 
149
	 * 
140
	 * @param columnIndex the column index
150
	 * @param columnIndex
151
	 *            the column index
141
	 * @return Widget the column widget
152
	 * @return Widget the column widget
142
	 */
153
	 */
143
	protected abstract Widget getColumnViewerOwner(int columnIndex);
154
	protected abstract Widget getColumnViewerOwner(int columnIndex);
Lines 150-156 Link Here
150
	 * @return the viewer column at the given index, or <code>null</code> if
161
	 * @return the viewer column at the given index, or <code>null</code> if
151
	 *         there is none for the given index
162
	 *         there is none for the given index
152
	 */
163
	 */
153
	/* package */ ViewerColumn getViewerColumn(final int columnIndex) {
164
	/* package */ViewerColumn getViewerColumn(final int columnIndex) {
154
165
155
		ViewerColumn viewer;
166
		ViewerColumn viewer;
156
		Widget columnOwner = getColumnViewerOwner(columnIndex);
167
		Widget columnOwner = getColumnViewerOwner(columnIndex);
Lines 176-182 Link Here
176
	}
187
	}
177
188
178
	/**
189
	/**
179
	 * Sets up editing support for the given column based on the "old" cell editor API.
190
	 * Sets up editing support for the given column based on the "old" cell
191
	 * editor API.
180
	 * 
192
	 * 
181
	 * @param columnIndex
193
	 * @param columnIndex
182
	 * @param viewer
194
	 * @param viewer
Lines 229-243 Link Here
229
	}
241
	}
230
242
231
	/**
243
	/**
232
	 * Creates a generic viewer column for the given column widget, based on the given label provider.
244
	 * Creates a generic viewer column for the given column widget, based on the
245
	 * given label provider.
233
	 * 
246
	 * 
234
	 * @param columnOwner the column widget
247
	 * @param columnOwner
235
	 * @param labelProvider the label provider to use for the column
248
	 *            the column widget
249
	 * @param labelProvider
250
	 *            the label provider to use for the column
236
	 * @return ViewerColumn the viewer column
251
	 * @return ViewerColumn the viewer column
237
	 */
252
	 */
238
	private ViewerColumn createViewerColumn(Widget columnOwner,
253
	private ViewerColumn createViewerColumn(Widget columnOwner,
239
			CellLabelProvider labelProvider) {
254
			CellLabelProvider labelProvider) {
240
		ViewerColumn column = new ViewerColumn(this,columnOwner) {};
255
		ViewerColumn column = new ViewerColumn(this, columnOwner) {
256
		};
241
		column.setLabelProvider(labelProvider, false);
257
		column.setLabelProvider(labelProvider, false);
242
		return column;
258
		return column;
243
	}
259
	}
Lines 269-287 Link Here
269
	 * @param column
285
	 * @param column
270
	 * @return ViewerCell
286
	 * @return ViewerCell
271
	 */
287
	 */
272
	/* package */ ViewerCell updateCell(ViewerRow rowItem, int column) {
288
	/* package */ViewerCell updateCell(ViewerRow rowItem, int column) {
273
		cell.update(rowItem, column);
289
		cell.update(rowItem, column);
274
		return cell;
290
		return cell;
275
	}
291
	}
276
292
277
	/**
293
	/**
278
	 * Returns the {@link Item} at the given widget-relative coordinates, or
294
	 * Returns the {@link Item} at the given widget-relative coordinates, or
279
     * <code>null</code> if there is no item at the given coordinates.
295
	 * <code>null</code> if there is no item at the given coordinates.
280
	 * 
296
	 * 
281
	 * @param point
297
	 * @param point
282
	 *            the widget-relative coordinates
298
	 *            the widget-relative coordinates
283
	 * @return the {@link Item} at the coordinates or <code>null</code> if there
299
	 * @return the {@link Item} at the coordinates or <code>null</code> if
284
	 *         is no item at the given coordinates
300
	 *         there is no item at the given coordinates
285
	 */
301
	 */
286
	protected abstract Item getItemAt(Point point);
302
	protected abstract Item getItemAt(Point point);
287
303
Lines 339-345 Link Here
339
355
340
	/**
356
	/**
341
	 * Cancels a currently active cell editor if one is active. All changes
357
	 * Cancels a currently active cell editor if one is active. All changes
342
     * already done in the cell editor are lost.
358
	 * already done in the cell editor are lost.
343
	 * 
359
	 * 
344
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
360
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
345
	 */
361
	 */
Lines 371-387 Link Here
371
	 */
387
	 */
372
	public void editElement(Object element, int column) {
388
	public void editElement(Object element, int column) {
373
		if (viewerEditor != null) {
389
		if (viewerEditor != null) {
374
			viewerEditor.editElement(element, column);
390
			Widget item = findItem(element);
391
			if (item != null) {
392
				ViewerRow row = getViewerRowFromItem(item);
393
				if (row != null) {
394
					ViewerCell cell = row.getCell(column);
395
					if (cell != null) {
396
						getControl().setRedraw(false);
397
398
						List l = getSelectionFromWidget();
399
400
						if (l.size() > 1 || !l.contains(cell.getElement())) {
401
							setSelection(new StructuredSelection(cell
402
									.getElement()));
403
						}
404
405
						triggerEditorActivationEvent(new EditorActivationEvent(
406
								cell));
407
						getControl().setRedraw(true);
408
					}
409
				}
410
			}
375
		}
411
		}
376
	}
412
	}
377
413
378
	/**
414
	/**
379
	 * Return the CellEditors for the receiver, or <code>null</code> if no
415
	 * Return the CellEditors for the receiver, or <code>null</code> if no
380
     * cell editors are set.
416
	 * cell editors are set.
381
	 * <p>
417
	 * <p>
382
	 * Since 3.3, an alternative API is available, see
418
	 * Since 3.3, an alternative API is available, see
383
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
419
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
384
	 * way of editing values in a column viewer.
420
	 * flexible way of editing values in a column viewer.
385
	 * </p>
421
	 * </p>
386
	 * 
422
	 * 
387
	 * @return CellEditor[]
423
	 * @return CellEditor[]
Lines 390-409 Link Here
390
	 * @see EditingSupport
426
	 * @see EditingSupport
391
	 */
427
	 */
392
	public CellEditor[] getCellEditors() {
428
	public CellEditor[] getCellEditors() {
393
		if (viewerEditor != null) {
429
		return cellEditors;
394
			return viewerEditor.getCellEditors();
395
		}
396
		return null;
397
	}
430
	}
398
431
399
	/**
432
	/**
400
	 * Returns the cell modifier of this viewer, or <code>null</code> if none
433
	 * Returns the cell modifier of this viewer, or <code>null</code> if none
401
     * has been set.
434
	 * has been set.
402
	 * 
435
	 * 
403
	 * <p>
436
	 * <p>
404
	 * Since 3.3, an alternative API is available, see
437
	 * Since 3.3, an alternative API is available, see
405
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
438
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
406
	 * way of editing values in a column viewer.
439
	 * flexible way of editing values in a column viewer.
407
	 * </p>
440
	 * </p>
408
	 * 
441
	 * 
409
	 * @return the cell modifier, or <code>null</code>
442
	 * @return the cell modifier, or <code>null</code>
Lines 412-421 Link Here
412
	 * @see EditingSupport
445
	 * @see EditingSupport
413
	 */
446
	 */
414
	public ICellModifier getCellModifier() {
447
	public ICellModifier getCellModifier() {
415
		if (viewerEditor != null) {
448
		return cellModifier;
416
			return viewerEditor.getCellModifier();
417
		}
418
		return null;
419
	}
449
	}
420
450
421
	/**
451
	/**
Lines 425-432 Link Here
425
	 * 
455
	 * 
426
	 * <p>
456
	 * <p>
427
	 * Since 3.3, an alternative API is available, see
457
	 * Since 3.3, an alternative API is available, see
428
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
458
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
429
	 * way of editing values in a column viewer.
459
	 * flexible way of editing values in a column viewer.
430
	 * </p>
460
	 * </p>
431
	 * 
461
	 * 
432
	 * @return the list of column properties
462
	 * @return the list of column properties
Lines 435-444 Link Here
435
	 * @see EditingSupport
465
	 * @see EditingSupport
436
	 */
466
	 */
437
	public Object[] getColumnProperties() {
467
	public Object[] getColumnProperties() {
438
		if (viewerEditor != null) {
468
		return columnProperties;
439
			return viewerEditor.getColumnProperties();
440
		}
441
		return null;
442
	}
469
	}
443
470
444
	/**
471
	/**
Lines 446-453 Link Here
446
	 * 
473
	 * 
447
	 * <p>
474
	 * <p>
448
	 * Since 3.3, an alternative API is available, see
475
	 * Since 3.3, an alternative API is available, see
449
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
476
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
450
	 * way of editing values in a column viewer.
477
	 * flexible way of editing values in a column viewer.
451
	 * </p>
478
	 * </p>
452
	 * 
479
	 * 
453
	 * @return <code>true</code> if there is an active cell editor, and
480
	 * @return <code>true</code> if there is an active cell editor, and
Lines 469-476 Link Here
469
	 * 
496
	 * 
470
	 * <p>
497
	 * <p>
471
	 * Since 3.3, an alternative API is available, see
498
	 * Since 3.3, an alternative API is available, see
472
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
499
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
473
	 * way of editing values in a column viewer.
500
	 * flexible way of editing values in a column viewer.
474
	 * </p>
501
	 * </p>
475
	 * 
502
	 * 
476
	 * @param editors
503
	 * @param editors
Lines 480-498 Link Here
480
	 * @see EditingSupport
507
	 * @see EditingSupport
481
	 */
508
	 */
482
	public void setCellEditors(CellEditor[] editors) {
509
	public void setCellEditors(CellEditor[] editors) {
483
		if (viewerEditor != null) {
510
		this.cellEditors = editors;
484
			viewerEditor.setCellEditors(editors);
485
		}
486
	}
511
	}
487
512
488
	/**
513
	/**
489
	 * Sets the cell modifier for this column viewer. This method does nothing if editing
514
	 * Sets the cell modifier for this column viewer. This method does nothing
490
	 * is not supported by this viewer.
515
	 * if editing is not supported by this viewer.
491
	 * 
516
	 * 
492
	 * <p>
517
	 * <p>
493
	 * Since 3.3, an alternative API is available, see
518
	 * Since 3.3, an alternative API is available, see
494
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
519
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
495
	 * way of editing values in a column viewer.
520
	 * flexible way of editing values in a column viewer.
496
	 * </p>
521
	 * </p>
497
	 * 
522
	 * 
498
	 * @param modifier
523
	 * @param modifier
Lines 502-510 Link Here
502
	 * @see EditingSupport
527
	 * @see EditingSupport
503
	 */
528
	 */
504
	public void setCellModifier(ICellModifier modifier) {
529
	public void setCellModifier(ICellModifier modifier) {
505
		if (viewerEditor != null) {
530
		this.cellModifier = modifier;
506
			viewerEditor.setCellModifier(modifier);
507
		}
508
	}
531
	}
509
532
510
	/**
533
	/**
Lines 515-522 Link Here
515
	 * 
538
	 * 
516
	 * <p>
539
	 * <p>
517
	 * Since 3.3, an alternative API is available, see
540
	 * Since 3.3, an alternative API is available, see
518
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
541
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
519
	 * way of editing values in a column viewer.
542
	 * flexible way of editing values in a column viewer.
520
	 * </p>
543
	 * </p>
521
	 * 
544
	 * 
522
	 * @param columnProperties
545
	 * @param columnProperties
Lines 526-550 Link Here
526
	 * @see EditingSupport
549
	 * @see EditingSupport
527
	 */
550
	 */
528
	public void setColumnProperties(String[] columnProperties) {
551
	public void setColumnProperties(String[] columnProperties) {
529
		if (viewerEditor != null) {
552
		this.columnProperties = columnProperties;
530
			viewerEditor.setColumnProperties(columnProperties);
531
		}
532
	}
533
	
534
	/**
535
	 * The tab-editing style used if the default implementation is used
536
	 * 
537
	 * @param tabEditingStyle
538
	 *            bit mask for the tab editing style
539
	 */
540
	public void setTabEditingStyle(int tabEditingStyle) {
541
		this.tabEditingStyle = tabEditingStyle;
542
	}
553
	}
543
554
544
	int getTabEditingStyle() {
545
		return this.tabEditingStyle;
546
	}
547
	
548
	/**
555
	/**
549
	 * Returns the number of columns contained in the receiver. If no columns
556
	 * Returns the number of columns contained in the receiver. If no columns
550
	 * were created by the programmer, this value is zero, despite the fact that
557
	 * were created by the programmer, this value is zero, despite the fact that
Lines 576-579 Link Here
576
		}
583
		}
577
		return null;
584
		return null;
578
	}
585
	}
579
}
586
587
	private void handleMouseDown(MouseEvent e) {
588
		ViewerCell cell = getCell(new Point(e.x, e.y));
589
590
		if (cell != null) {
591
			triggerEditorActivationEvent(new EditorActivationEvent(cell, e));
592
		}
593
	}
594
595
	/**
596
	 * Invoking this method fires an editor activation event which tries to
597
	 * enable the editor but before this event is passed to
598
	 * {@link ColumnViewerKeyboardSupport} to see if this event should really
599
	 * trigger editor activation
600
	 * 
601
	 * @param event
602
	 *            the activation event
603
	 */
604
	protected void triggerEditorActivationEvent(EditorActivationEvent event) {
605
		viewerEditor.handleEditorActivationEvent(event);
606
	}
607
608
	/**
609
	 * To fully control the strategy used to control on which cell-selection
610
	 * events the editor has to be activated you can pass your customized
611
	 * strategy using this method.
612
	 * 
613
	 * @param editorActivationStrategy
614
	 *            the strategy used to activate an editor
615
	 */
616
	public void setEditorActivationSupport(
617
			ColumnViewerKeyboardSupport editorActivationStrategy) {
618
		if (viewerEditor != null) {
619
			viewerEditor.setEditorActivationStrategy(editorActivationStrategy);
620
		} else {
621
			throw new IllegalStateException(
622
					"This feature is not supported by the widget"); //$NON-NLS-1$
623
		}
624
	}
625
626
	/**
627
	 * @param columnViewerEditor
628
	 *            the new column viewer editor
629
	 */
630
	public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) {
631
		Assert.isNotNull(viewerEditor);
632
		this.viewerEditor = columnViewerEditor;
633
	}
634
}
(-)src/org/eclipse/jface/viewers/CellEditor.java (+10 lines)
Lines 853-856 Link Here
853
        dirty = true;
853
        dirty = true;
854
        fireEditorValueChanged(oldValidState, newValidState);
854
        fireEditorValueChanged(oldValidState, newValidState);
855
    }
855
    }
856
    
857
    /**
858
     * Activate the editor but also inform the editor which event triggered its activation.
859
     * <b>The default implementation simply calls {@link #activate()}</b>
860
     * 
861
     * @param activationEvent the editor activation event
862
     */
863
    public void activate(EditorActivationEvent activationEvent) {
864
    	activate();
865
    }
856
}
866
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditor.java (-174 / +312 lines)
Lines 14-19 Link Here
14
14
15
package org.eclipse.jface.viewers;
15
package org.eclipse.jface.viewers;
16
16
17
18
import java.util.List;
19
20
import org.eclipse.core.runtime.ListenerList;
21
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.FocusAdapter;
22
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusEvent;
23
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusListener;
24
import org.eclipse.swt.events.FocusListener;
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseListener;
27
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.TraverseEvent;
28
import org.eclipse.swt.events.TraverseEvent;
24
import org.eclipse.swt.events.TraverseListener;
29
import org.eclipse.swt.events.TraverseListener;
25
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Item;
32
import org.eclipse.swt.widgets.Item;
Lines 40-78 Link Here
40
public abstract class ColumnViewerEditor {
44
public abstract class ColumnViewerEditor {
41
	private CellEditor cellEditor;
45
	private CellEditor cellEditor;
42
46
43
	private CellEditor[] cellEditors;
44
45
	private ICellModifier cellModifier;
46
47
	private String[] columnProperties;
48
49
	private int columnNumber;
50
51
	private ICellEditorListener cellEditorListener;
47
	private ICellEditorListener cellEditorListener;
52
48
53
	private FocusListener focusListener;
49
	private FocusListener focusListener;
54
50
55
	private MouseListener mouseListener;
51
	private MouseListener mouseListener;
56
52
57
	private int doubleClickExpirationTime;
58
59
	private ColumnViewer viewer;
53
	private ColumnViewer viewer;
60
54
61
	private Item item;
62
63
	private TraverseListener tabeditingListener;
55
	private TraverseListener tabeditingListener;
64
56
57
	private int activationTime;
58
		
59
	private ViewerCell cell;
60
	
61
	private EditorActivationEvent activationEvent;
62
	
63
	private ListenerList editorActivationListener;
64
	
65
	private ColumnViewerKeyboardSupport editorActivationStrategy;
66
67
	/**
68
	 * Tabing from cell to cell is turned off
69
	 */
70
	public static final int DEFAULT = 1;
71
72
	/**
73
	 * Should if the end of the row is reach started from the start/end of the
74
	 * row below/above
75
	 */
76
	public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1;
77
78
	/**
79
	 * Should if the end of the row is reach started from the beginning in the
80
	 * same row
81
	 */
82
	public static final int TABBING_CYCLE_IN_ROW = 1 << 2;
83
84
	/**
85
	 * Support tabing to Cell above/below the current cell
86
	 */
87
	public static final int TABBING_VERTICAL = 1 << 3;
88
89
	/**
90
	 * Should tabing from column to column with in one row be supported
91
	 */
92
	public static final int TABBING_HORIZONTAL = 1 << 4;
93
	
94
	private int feature;
95
	
65
	/**
96
	/**
66
	 * Create a new editor implementation for the viewer
67
	 * 
68
	 * @param viewer
97
	 * @param viewer
69
	 *            the column viewer
98
	 * @param editorActivationStrategy
99
	 * @param feature
70
	 */
100
	 */
71
	public ColumnViewerEditor(ColumnViewer viewer) {
101
	protected ColumnViewerEditor(ColumnViewer viewer, ColumnViewerKeyboardSupport editorActivationStrategy, int feature) {
72
		this.viewer = viewer;
102
		this.viewer = viewer;
103
		this.editorActivationStrategy = editorActivationStrategy;
104
		this.feature = feature;
73
		initCellEditorListener();
105
		initCellEditorListener();
74
	}
106
	}
75
107
	
76
	private void initCellEditorListener() {
108
	private void initCellEditorListener() {
77
		cellEditorListener = new ICellEditorListener() {
109
		cellEditorListener = new ICellEditorListener() {
78
			public void editorValueChanged(boolean oldValidState,
110
			public void editorValueChanged(boolean oldValidState,
Lines 92-104 Link Here
92
124
93
	void activateCellEditor() {
125
	void activateCellEditor() {
94
126
95
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
127
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
96
		Object element = item.getData();
128
		Object element = cell.getElement();
97
129
		
98
		if (part != null && part.getEditingSupport() != null
130
		if (part != null && part.getEditingSupport() != null
99
				&& part.getEditingSupport().canEdit(element)) {
131
				&& part.getEditingSupport().canEdit(element)) {
132
			
100
			cellEditor = part.getEditingSupport().getCellEditor(element);
133
			cellEditor = part.getEditingSupport().getCellEditor(element);
101
			if (cellEditor != null) {
134
			if (cellEditor != null) {
135
				if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
136
					Object[] ls = editorActivationListener.getListeners();
137
					for( int i = 0; i < ls.length; i++ ) {
138
						
139
						if( activationEvent.cancle ) {
140
							return;
141
						}
142
						
143
						((ColumnViewerEditorActivationListener)ls[i]).beforeEditorActivated(activationEvent);
144
					}
145
				}
146
				
102
				cellEditor.addListener(cellEditorListener);
147
				cellEditor.addListener(cellEditorListener);
103
				Object value = part.getEditingSupport().getValue(element);
148
				Object value = part.getEditingSupport().getValue(element);
104
				cellEditor.setValue(value);
149
				cellEditor.setValue(value);
Lines 108-119 Link Here
108
				// so must get control first, but must still call activate()
153
				// so must get control first, but must still call activate()
109
				// even if there is no control.
154
				// even if there is no control.
110
				final Control control = cellEditor.getControl();
155
				final Control control = cellEditor.getControl();
111
				cellEditor.activate();
156
				cellEditor.activate(activationEvent);
112
				if (control == null) {
157
				if (control == null) {
113
					return;
158
					return;
114
				}
159
				}
115
				setLayoutData(cellEditor.getLayoutData());
160
				setLayoutData(cellEditor.getLayoutData());
116
				setEditor(control, item, columnNumber);
161
				setEditor(control, cell.getItem(), cell.getColumnIndex());
117
				cellEditor.setFocus();
162
				cellEditor.setFocus();
118
				if (focusListener == null) {
163
				if (focusListener == null) {
119
					focusListener = new FocusAdapter() {
164
					focusListener = new FocusAdapter() {
Lines 128-134 Link Here
128
					public void mouseDown(MouseEvent e) {
173
					public void mouseDown(MouseEvent e) {
129
						// time wrap?
174
						// time wrap?
130
						// check for expiration of doubleClickTime
175
						// check for expiration of doubleClickTime
131
						if (e.time <= doubleClickExpirationTime) {
176
						if (e.time <= activationTime) {
132
							control.removeMouseListener(mouseListener);
177
							control.removeMouseListener(mouseListener);
133
							cancelEditing();
178
							cancelEditing();
134
							handleDoubleClickEvent();
179
							handleDoubleClickEvent();
Lines 143-195 Link Here
143
					tabeditingListener = new TraverseListener() {
188
					tabeditingListener = new TraverseListener() {
144
189
145
						public void keyTraversed(TraverseEvent e) {
190
						public void keyTraversed(TraverseEvent e) {
146
							ViewerColumn col = viewer.getViewerColumn(columnNumber);
191
							if( (feature & DEFAULT) != DEFAULT ) {
147
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
192
								processTraversEvent(
148
								col.getEditingSupport().processTraversEvent(
193
										cell.getColumnIndex(),
149
										columnNumber,
194
										viewer.getViewerRowFromItem(cell.getItem()), e);
150
										viewer.getViewerRowFromItem(item), e);
151
							}
195
							}
152
						}
196
						}
153
					};
197
					};
154
				}
198
				}
155
				
199
				
156
				control.addTraverseListener(tabeditingListener);
200
				control.addTraverseListener(tabeditingListener);
157
201
				
158
			}
202
				if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
159
		}
203
					Object[] ls = editorActivationListener.getListeners();
160
	}
204
					for( int i = 0; i < ls.length; i++ ) {
161
205
						((ColumnViewerEditorActivationListener)ls[i]).afterEditorActivated(activationEvent);
162
	/**
206
					}
163
	 * Activate a cell editor for the given mouse position.
164
	 */
165
	private void activateCellEditor(MouseEvent event) {
166
		if (item == null || item.isDisposed()) {
167
			// item no longer exists
168
			return;
169
		}
170
		int columnToEdit;
171
		ViewerRow row = viewer.getViewerRowFromItem(item);
172
		int columns = row.getColumnCount();
173
		if (columns == 0) {
174
			// If no TableColumn, Table acts as if it has a single column
175
			// which takes the whole width.
176
			columnToEdit = 0;
177
		} else {
178
			columnToEdit = -1;
179
			for (int i = 0; i < columns; i++) {
180
				Rectangle bounds = row.getBounds(i);
181
				if (bounds.contains(event.x, event.y)) {
182
					columnToEdit = i;
183
					break;
184
				}
207
				}
185
			}
208
			}
186
			if (columnToEdit == -1) {
187
				return;
188
			}
189
		}
209
		}
190
191
		columnNumber = columnToEdit;
192
		activateCellEditor();
193
	}
210
	}
194
211
195
	/**
212
	/**
Lines 203-210 Link Here
203
			// in case save results in applyEditorValue being re-entered
220
			// in case save results in applyEditorValue being re-entered
204
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
221
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
205
			// using cell editor ?
222
			// using cell editor ?
223
			EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell);
224
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
225
				Object[] ls = editorActivationListener.getListeners();
226
				for( int i = 0; i < ls.length; i++ ) {
227
					
228
					if( tmp.cancle ) {
229
						return;
230
					}
231
					
232
					((ColumnViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp);
233
				}
234
			}
235
			
206
			this.cellEditor = null;
236
			this.cellEditor = null;
207
			Item t = this.item;
237
			this.activationEvent = null;
238
			Item t = this.cell.getItem();
208
			// don't null out table item -- same item is still selected
239
			// don't null out table item -- same item is still selected
209
			if (t != null && !t.isDisposed()) {
240
			if (t != null && !t.isDisposed()) {
210
				saveEditorValue(c, t);
241
				saveEditorValue(c, t);
Lines 227-232 Link Here
227
				}
258
				}
228
			}
259
			}
229
			c.deactivate();
260
			c.deactivate();
261
			
262
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
263
				Object[] ls = editorActivationListener.getListeners();
264
				for( int i = 0; i < ls.length; i++ ) {
265
					((ColumnViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp);
266
				}
267
			}
230
		}
268
		}
231
	}
269
	}
232
270
Lines 235-240 Link Here
235
	 */
273
	 */
236
	void cancelEditing() {
274
	void cancelEditing() {
237
		if (cellEditor != null) {
275
		if (cellEditor != null) {
276
			EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell);
277
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
278
				Object[] ls = editorActivationListener.getListeners();
279
				for( int i = 0; i < ls.length; i++ ) {
280
					if( tmp.cancle ) {
281
						return;
282
					}
283
					
284
					((ColumnViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp);
285
				}
286
			}
287
238
			setEditor(null, null, 0);
288
			setEditor(null, null, 0);
239
			cellEditor.removeListener(cellEditorListener);
289
			cellEditor.removeListener(cellEditorListener);
240
290
Lines 256-325 Link Here
256
306
257
			CellEditor oldEditor = cellEditor;
307
			CellEditor oldEditor = cellEditor;
258
			cellEditor = null;
308
			cellEditor = null;
309
			activationEvent=null;
259
			oldEditor.deactivate();
310
			oldEditor.deactivate();
311
			
312
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
313
				Object[] ls = editorActivationListener.getListeners();
314
				for( int i = 0; i < ls.length; i++ ) {
315
					((ColumnViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp);
316
				}
317
			}
260
		}
318
		}
261
	}
319
	}
262
320
	
263
	/**
321
	/**
264
	 * Enable the editor by mouse down
322
	 * Enable the editor by mouse down
265
	 * 
323
	 * 
266
	 * @param event
324
	 * @param event
267
	 */
325
	 */
268
	void handleMouseDown(MouseEvent event) {
326
	void handleEditorActivationEvent(EditorActivationEvent event) {
269
		if (event.button != 1) {
327
		if( editorActivationStrategy.isEditorActivationEvent(event) ) {
270
			return;
328
			if (cellEditor != null) {
271
		}
329
				applyEditorValue();
272
330
			}
273
		if (cellEditor != null) {
274
			applyEditorValue();
275
		}
276
277
		// activate the cell editor immediately. If a second mouseDown
278
		// is received prior to the expiration of the doubleClick time then
279
		// the cell editor will be deactivated and a doubleClick event will
280
		// be processed.
281
		//
282
		doubleClickExpirationTime = event.time
283
				+ Display.getCurrent().getDoubleClickTime();
284
285
		Item[] items = getSelection();
286
		// Do not edit if more than one row is selected.
287
		if (items.length != 1) {
288
			item = null;
289
			return;
290
		}
291
		item = items[0];
292
		activateCellEditor(event);
293
	}
294
295
	/**
296
	 * Start editing the given element.
297
	 * 
298
	 * @param element
299
	 * @param column
300
	 */
301
	void editElement(Object element, int column) {
302
		if (cellEditor != null) {
303
			applyEditorValue();
304
		}
305
331
306
		setSelection(createSelection(element), true);
332
			this.cell = (ViewerCell)event.getSource();			
307
		Item[] selection = getSelection();
333
			activationEvent = event;
308
		if (selection.length != 1) {
334
			activationTime = event.time + Display.getCurrent().getDoubleClickTime();
309
			return;
335
			
336
			activateCellEditor();
310
		}
337
		}
311
312
		item = selection[0];
313
314
		// Make sure selection is visible
315
		showSelection();
316
		columnNumber = column;
317
		activateCellEditor();
318
319
	}
338
	}
320
339
321
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
340
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
322
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
341
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
323
342
324
		if (part != null && part.getEditingSupport() != null) {
343
		if (part != null && part.getEditingSupport() != null) {
325
			part.getEditingSupport().setValue(tableItem.getData(),
344
			part.getEditingSupport().setValue(tableItem.getData(),
Lines 337-406 Link Here
337
		return cellEditor != null;
356
		return cellEditor != null;
338
	}
357
	}
339
358
340
	/**
341
	 * Set the cell editors
342
	 * 
343
	 * @param editors
344
	 */
345
	void setCellEditors(CellEditor[] editors) {
346
		this.cellEditors = editors;
347
	}
348
359
349
	/**
360
	void handleDoubleClickEvent() {
350
	 * Set the cell modifier
361
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
351
	 * 
362
				.getSelection()));
352
	 * @param modifier
363
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
353
	 */
354
	void setCellModifier(ICellModifier modifier) {
355
		this.cellModifier = modifier;
356
	}
364
	}
357
365
358
	/**
366
	void addEditorActivationListener(ColumnViewerEditorActivationListener listener) {
359
	 * Set the column properties
367
		if( editorActivationListener == null ) {
360
	 * 
368
			editorActivationListener = new ListenerList();
361
	 * @param columnProperties
369
		}
370
		editorActivationListener.add(listener);
371
	}
372
	
373
	void removeEditorActivationListener(ColumnViewerEditorActivationListener listener) {
374
		if( editorActivationListener != null ) {
375
			editorActivationListener.remove(listener);
376
		}
377
	}
378
	
379
	void setEditorActivationStrategy(
380
			ColumnViewerKeyboardSupport editorActivationStrategy) {
381
		this.editorActivationStrategy = editorActivationStrategy;
382
	}
383
	
384
	/**
385
	 * Process the travers event and opens the next available editor depending
386
	 * of the implemented strategy. The default implementation uses the style
387
	 * constants
388
	 * <ul>
389
	 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
390
	 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
391
	 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
392
	 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
393
	 * </ul>
394
	 * 
395
	 * <p>
396
	 * Subclasses may overwrite to implement their custom logic to edit the next
397
	 * cell
398
	 * </p>
399
	 * 
400
	 * @param columnIndex
401
	 *            the index of the current column
402
	 * @param row
403
	 *            the current row
404
	 * @param event
405
	 *            the travers event
362
	 */
406
	 */
363
	void setColumnProperties(String[] columnProperties) {
407
	protected void processTraversEvent(int columnIndex,
364
		this.columnProperties = columnProperties;
408
			ViewerRow row, TraverseEvent event) {
365
	}
409
		
410
		ViewerCell cell2edit = null;
411
412
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
413
			event.doit = false;
414
415
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
416
					&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
417
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true);
418
			} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
419
				cell2edit = searchPreviousCell(row, viewer, columnIndex,
420
						columnIndex);
421
			}
422
		} else if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
423
			event.doit = false;
366
424
367
	/**
425
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
368
	 * Return the properties for the column
426
					&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
369
	 * 
427
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex,
370
	 * @return the array of column properties
428
						false);
371
	 */
429
			} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
372
	Object[] getColumnProperties() {
430
				cell2edit = searchNextCell(row, viewer, columnIndex,
373
		return columnProperties;
431
						columnIndex);
374
	}
432
			}
433
		}
375
434
376
	/**
435
		if (cell2edit != null) {
377
	 * Get the cell modifier
436
			List l = viewer.getSelectionFromWidget();
378
	 * 
437
						
379
	 * @return the cell modifier
438
			viewer.getControl().setRedraw(false);
380
	 */
439
			
381
	ICellModifier getCellModifier() {
440
			//TODO Is this correct in terms of other controls e.g. grid
382
		return cellModifier;
441
			if( ! l.contains(cell2edit.getElement()) ) {
442
				viewer.setSelection(new StructuredSelection(cell2edit.getElement()));
443
			}
444
						
445
			EditorActivationEvent acEvent = new EditorActivationEvent(cell2edit,event);
446
			viewer.triggerEditorActivationEvent(acEvent);
447
			viewer.getControl().setRedraw(true);
448
		}
383
	}
449
	}
384
450
385
	/**
451
	private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer,
386
	 * Return the array of CellEditors used in the viewer
452
			int columnIndex, boolean above) {
387
	 * 
453
		ViewerCell rv = null;
388
	 * @return the cell editors
389
	 */
390
	CellEditor[] getCellEditors() {
391
		return cellEditors;
392
	}
393
454
394
	void setSelection(StructuredSelection selection, boolean b) {
455
		ViewerRow newRow = null;
395
		viewer.setSelection(selection, b);
456
457
		if (above) {
458
			newRow = row.getNeighbor(ViewerRow.ABOVE, false);
459
		} else {
460
			newRow = row.getNeighbor(ViewerRow.BELOW,false);
461
		}
462
463
		if (newRow != null) {
464
			ViewerColumn column = viewer.getViewerColumn(columnIndex);
465
			if (column != null
466
					&& column.getEditingSupport().canEdit(
467
							newRow.getItem().getData())) {
468
				rv = newRow.getCell(columnIndex);
469
			} else {
470
				rv = searchCellAboveBelow(newRow, viewer, columnIndex, above);
471
			}
472
		}
473
474
		return rv;
396
	}
475
	}
397
476
398
	void handleDoubleClickEvent() {
477
	private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer,
399
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
478
			int columnIndex, int startIndex) {
400
				.getSelection()));
479
		ViewerCell rv = null;
401
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
480
481
		if (columnIndex - 1 >= 0) {
482
			ViewerColumn column = viewer.getViewerColumn(columnIndex - 1);
483
			if (column != null
484
					&& column.getEditingSupport().canEdit(
485
							row.getItem().getData())) {
486
				rv = row.getCell(columnIndex - 1);
487
			} else {
488
				rv = searchPreviousCell(row, viewer, columnIndex - 1,
489
						startIndex);
490
			}
491
		} else {
492
			if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
493
				// Check that we don't get into endless loop
494
				if (columnIndex - 1 != startIndex) {
495
					// Don't subtract -1 from getColumnCount() we need to
496
					// start in the virtual column
497
					// next to it
498
					rv = searchPreviousCell(row, viewer, row.getColumnCount(),
499
							startIndex);
500
				}
501
			} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
502
				ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE,false);
503
				if (rowAbove != null) {
504
					rv = searchPreviousCell(rowAbove, viewer, rowAbove
505
							.getColumnCount(), startIndex);
506
				}
507
			}
508
		}
509
510
		return rv;
402
	}
511
	}
403
512
513
	private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer,
514
			int columnIndex, int startIndex) {
515
		ViewerCell rv = null;
516
517
		if (columnIndex + 1 < row.getColumnCount()) {
518
			ViewerColumn column = viewer.getViewerColumn(columnIndex + 1);
519
			if (column != null
520
					&& column.getEditingSupport().canEdit(
521
							row.getItem().getData())) {
522
				rv = row.getCell(columnIndex + 1);
523
			} else {
524
				rv = searchNextCell(row, viewer, columnIndex + 1, startIndex);
525
			}
526
		} else {
527
			if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
528
				// Check that we don't get into endless loop
529
				if (columnIndex + 1 != startIndex) {
530
					// Start from -1 from the virtual column before the
531
					// first one
532
					rv = searchNextCell(row, viewer, -1, startIndex);
533
				}
534
			} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
535
				ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW,false);
536
				if (rowBelow != null) {
537
					rv = searchNextCell(rowBelow, viewer, -1, startIndex);
538
				}
539
			}
540
		}
541
542
		return rv;
543
	}
544
	
404
	/**
545
	/**
405
	 * Create a selection for this model element
546
	 * Create a selection for this model element
406
	 * 
547
	 * 
Lines 429-442 Link Here
429
	 *            the layout data used when editor is displayed
570
	 *            the layout data used when editor is displayed
430
	 */
571
	 */
431
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
572
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
432
573
	
433
	/**
574
	/**
434
	 * Show up the current selection (scroll the selection into view)
575
	 * @return the viewer working for
435
	 */
576
	 */
436
	protected abstract void showSelection();
577
	protected ColumnViewer getViewer() {
437
578
		return viewer;
438
	/**
579
	}
439
	 * @return the current selection
580
}
440
	 */
441
	protected abstract Item[] getSelection();
442
}
(-)src/org/eclipse/jface/viewers/ColumnViewerKeyboardSupport.java (+91 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.events.KeyEvent;
15
import org.eclipse.swt.events.KeyListener;
16
17
/**
18
 * This class is responsible to determin if a cell selection event is triggers
19
 * an editor activation
20
 * 
21
 * @since 3.3
22
 */
23
public class ColumnViewerKeyboardSupport {
24
	private ColumnViewer viewer;
25
	
26
	private KeyListener keyboardActivationListener;
27
	
28
	/**
29
	 * @param viewer the viewer the editor support is attached to
30
	 */
31
	public ColumnViewerKeyboardSupport(ColumnViewer viewer) {
32
		this.viewer = viewer;
33
	}
34
	
35
	/**
36
	 * @param event
37
	 * @return bla bl
38
	 */
39
	protected boolean isEditorActivationEvent(EditorActivationEvent event) {
40
		return event.eventType == EditorActivationEvent.MOUSE_CLICK_SELECTION
41
			|| event.eventType == EditorActivationEvent.PROGRAMATIC
42
			|| event.eventType == EditorActivationEvent.TRAVERSAL;
43
		}
44
45
	/**
46
	 * @return the cell holding the current focus
47
	 */
48
	protected ViewerCell getFocusCell() {
49
		return null;
50
	}
51
	
52
	/**
53
	 * @return the viewer
54
	 */
55
	public ColumnViewer getViewer() {
56
		return viewer;
57
	}
58
	
59
	/**
60
	 * Enable activation of cell editors by keyboard
61
	 * @param enable <code>true</code> to enable
62
	 */
63
	public void setEnableEditorActivationWithKeyboard(boolean enable) {
64
		if( enable ) {
65
			if( keyboardActivationListener == null ) {
66
				keyboardActivationListener = new KeyListener() {
67
68
					public void keyPressed(KeyEvent e) {
69
						ViewerCell cell = getFocusCell();
70
						
71
						if( cell != null ) {
72
							viewer.triggerEditorActivationEvent(new EditorActivationEvent(cell,e));
73
						}
74
					}
75
76
					public void keyReleased(KeyEvent e) {
77
						
78
					}
79
					
80
				};
81
				viewer.getControl().addKeyListener(keyboardActivationListener);
82
			}
83
		} else {
84
			if( keyboardActivationListener != null ) {
85
				viewer.getControl().removeKeyListener(keyboardActivationListener);
86
				keyboardActivationListener = null;
87
			}
88
		}
89
	}
90
91
}
(-)src/org/eclipse/jface/viewers/EditorDeactivationEvent.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
/**
17
 * This event is fired when an editor deactivated
18
 * 
19
 * @since 3.3
20
 * 
21
 */
22
public class EditorDeactivationEvent extends EventObject {
23
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = 1L;
28
29
	/**
30
	 * Cancle the event
31
	 */
32
	public boolean cancle = false;
33
	
34
	/**
35
	 * @param source
36
	 */
37
	public EditorDeactivationEvent(Object source) {
38
		super(source);
39
	}
40
41
}
(-)src/org/eclipse/jface/viewers/EditorActivationEvent.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
import org.eclipse.swt.events.KeyEvent;
17
import org.eclipse.swt.events.MouseEvent;
18
import org.eclipse.swt.events.TraverseEvent;
19
20
/**
21
 * This event is passed on when a cell-editor is going to be activated
22
 * 
23
 * @since 3.3
24
 * 
25
 */
26
public class EditorActivationEvent extends EventObject {
27
	/**
28
	 * 
29
	 */
30
	private static final long serialVersionUID = 1L;
31
32
	/**
33
	 * if a key is pressed on a selected cell
34
	 */
35
	public static final int KEY_PRESSED = 1;
36
37
	/**
38
	 * if a cell is selected using a single click of the mouse
39
	 */
40
	public static final int MOUSE_CLICK_SELECTION = 2;
41
42
	/**
43
	 * if a cell is selected using double clicking of the mouse
44
	 */
45
	public static final int MOUSE_DOUBLE_CLICK_SELECTION = 3;
46
47
	/**
48
	 * if a cell is activated using code like e.g
49
	 * {@link ColumnViewer#editElement(Object, int)}
50
	 */
51
	public static final int PROGRAMATIC = 4;
52
53
	/**
54
	 * is a cell is activated by traversing
55
	 */
56
	public static final int TRAVERSAL = 5;
57
58
	/**
59
	 * the original event triggered
60
	 */
61
	public EventObject sourceEvent;
62
63
	/**
64
	 * The time the event is triggered
65
	 */
66
	public int time;
67
68
	/**
69
	 * The event type triggered:
70
	 * <ul>
71
	 * <li>{@link #KEY_PRESSED} if a key is pressed on a selected cell</li>
72
	 * <li>{@link #MOUSE_CLICK_SELECTION} if a cell is selected using a single
73
	 * click of the mouse</li>
74
	 * <li>{@link #MOUSE_DOUBLE_CLICK_SELECTION} if a cell is selected using
75
	 * double clicking of the mouse</li>
76
	 * </ul>
77
	 */
78
	public int eventType;
79
80
	/**
81
	 * <b>Only set for {@link #KEY_PRESSED}</b>
82
	 */
83
	public int keyCode;
84
85
	/**
86
	 * <b>Only set for {@link #KEY_PRESSED}</b>
87
	 */
88
	public char character;
89
90
	/**
91
	 * The statemask
92
	 */
93
	public int stateMask;
94
95
	/**
96
	 * Cancle the event (=> editor is not activated)
97
	 */
98
	public boolean cancle = false;
99
	
100
	/**
101
	 * This constructor can be used when no event exists. The type set is
102
	 * {@link #PROGRAMATIC}
103
	 * 
104
	 * @param cell
105
	 *            the cell
106
	 */
107
	public EditorActivationEvent(ViewerCell cell) {
108
		super(cell);
109
		eventType = PROGRAMATIC;
110
	}
111
112
	/**
113
	 * This constructor is used for all types of mouse events. Currently the
114
	 * type is can be {@link #MOUSE_CLICK_SELECTION} and
115
	 * {@link #MOUSE_DOUBLE_CLICK_SELECTION}
116
	 * 
117
	 * @param cell
118
	 *            the cell source of the event
119
	 * @param event
120
	 *            the event
121
	 */
122
	public EditorActivationEvent(ViewerCell cell, MouseEvent event) {
123
		super(cell);
124
125
		if (event.count >= 2) {
126
			eventType = MOUSE_DOUBLE_CLICK_SELECTION;
127
		} else {
128
			eventType = MOUSE_CLICK_SELECTION;
129
		}
130
131
		this.sourceEvent = event;
132
		this.time = event.time;
133
	}
134
135
	/**
136
	 * @param cell
137
	 *            the cell source of the event
138
	 * @param event
139
	 *            the event
140
	 */
141
	public EditorActivationEvent(ViewerCell cell, KeyEvent event) {
142
		super(cell);
143
		this.eventType = KEY_PRESSED;
144
		this.sourceEvent = event;
145
		this.time = 0;
146
		this.keyCode = event.keyCode;
147
		this.character = event.character;
148
		this.stateMask = event.stateMask;
149
	}
150
151
	/**
152
	 * This constructur is used to mark the activation triggered by a traversal
153
	 * 
154
	 * @param cell
155
	 *            the cell source of the event
156
	 * @param event
157
	 *            the event
158
	 */
159
	public EditorActivationEvent(ViewerCell cell, TraverseEvent event) {
160
		super(cell);
161
		this.eventType = TRAVERSAL;
162
		this.sourceEvent = event;
163
	}
164
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditorActivationListener.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * Parties interested in activation and deactivation of editors extend this
16
 * class and implement any or all of the methods
17
 * 
18
 * @since 3.3
19
 * 
20
 */
21
public abstract class ColumnViewerEditorActivationListener {
22
	/**
23
	 * Called before an editor is activated
24
	 * 
25
	 * @param event
26
	 *            the event
27
	 */
28
	public abstract void beforeEditorActivated(EditorActivationEvent event);
29
30
	/**
31
	 * Called after an editor has been activated
32
	 * 
33
	 * @param event the event
34
	 */
35
	public abstract void afterEditorActivated(EditorActivationEvent event);
36
37
	/**
38
	 * Called before an editor is deactivated
39
	 * 
40
	 * @param event
41
	 *            the event
42
	 */
43
	public abstract void beforeEditorDeactivated(EditorDeactivationEvent event);
44
45
	
46
	/**
47
	 * Called after an editor is deactivated
48
	 * 
49
	 * @param event the event
50
	 */
51
	public abstract void afterEditorDeactivated(EditorDeactivationEvent event);
52
}
(-)src/org/eclipse/jface/viewers/TreeColumnViewerEditor.java (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.jface.viewers.CellEditor.LayoutData;
15
import org.eclipse.swt.custom.TreeEditor;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Item;
18
import org.eclipse.swt.widgets.TreeItem;
19
20
/**
21
 * @since 3.3
22
 *
23
 */
24
public class TreeColumnViewerEditor extends ColumnViewerEditor {
25
	/**
26
	 * This viewer's tree editor.
27
	 */
28
	private TreeEditor treeEditor;
29
	
30
	/**
31
	 * @param viewer
32
	 * @param editorActivationStrategy
33
	 * @param feature
34
	 */
35
	public TreeColumnViewerEditor(TreeViewer viewer, ColumnViewerKeyboardSupport editorActivationStrategy, int feature) {
36
		super(viewer,editorActivationStrategy,feature);
37
		treeEditor = new TreeEditor(viewer.getTree());
38
	}
39
	
40
	protected StructuredSelection createSelection(Object element) {
41
		if (element instanceof TreePath) {
42
			return new TreeSelection((TreePath) element, getViewer().getComparer());
43
		}
44
45
		return new StructuredSelection(element);
46
	}
47
48
	protected void setEditor(Control w, Item item, int fColumnNumber) {
49
		treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
50
	}
51
52
	protected void setLayoutData(LayoutData layoutData) {
53
		treeEditor.grabHorizontal = layoutData.grabHorizontal;
54
		treeEditor.horizontalAlignment = layoutData.horizontalAlignment;
55
		treeEditor.minimumWidth = layoutData.minimumWidth;
56
	}
57
}
(-)src/org/eclipse/jface/viewers/TableColumnViewerEditor.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.jface.viewers.CellEditor.LayoutData;
15
import org.eclipse.swt.custom.TableEditor;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Item;
18
import org.eclipse.swt.widgets.TableItem;
19
20
/**
21
 * @since 3.3
22
 *
23
 */
24
public class TableColumnViewerEditor extends ColumnViewerEditor {
25
	/**
26
	 * This viewer's table editor.
27
	 */
28
	private TableEditor tableEditor;
29
	
30
	/**
31
	 * @param viewer
32
	 * @param editorActivationStrategy
33
	 * @param feature
34
	 */
35
	public TableColumnViewerEditor(TableViewer viewer, ColumnViewerKeyboardSupport editorActivationStrategy, int feature) {
36
		super(viewer,editorActivationStrategy,feature);
37
		tableEditor = new TableEditor(viewer.getTable());
38
	}
39
	
40
	protected StructuredSelection createSelection(Object element) {
41
		return new StructuredSelection(element);
42
	}
43
44
	protected void setEditor(Control w, Item item, int columnNumber) {
45
		tableEditor.setEditor(w, (TableItem) item, columnNumber);
46
	}
47
48
	protected void setLayoutData(LayoutData layoutData) {
49
		tableEditor.grabHorizontal = layoutData.grabHorizontal;
50
		tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
51
		tableEditor.minimumWidth = layoutData.minimumWidth;
52
	}
53
}

Return to bug 172646