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 75114 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-1 / +69 lines)
Lines 20-25 Link Here
20
import org.eclipse.swt.custom.TableEditor;
20
import org.eclipse.swt.custom.TableEditor;
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.TraverseEvent;
24
import org.eclipse.swt.events.TraverseListener;
23
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Composite;
Lines 64-70 Link Here
64
 * @see #internalRefresh(Object, boolean)
66
 * @see #internalRefresh(Object, boolean)
65
 */
67
 */
66
public class TableViewer extends StructuredViewer {
68
public class TableViewer extends StructuredViewer {
67
		
69
	private boolean tabediting = false;
70
	
71
	private TabeditingListener tabeditingListener;
72
73
	private TabEditingDelegate tabeditingDelgate;
74
	
68
	private class VirtualManager{
75
	private class VirtualManager{
69
76
70
		/**
77
		/**
Lines 1037-1042 Link Here
1037
	 */
1044
	 */
1038
	public void setCellEditors(CellEditor[] editors) {
1045
	public void setCellEditors(CellEditor[] editors) {
1039
		tableViewerImpl.setCellEditors(editors);
1046
		tableViewerImpl.setCellEditors(editors);
1047
		
1048
		if( tabediting ) {
1049
			applyCellEditing(tabediting);
1050
		}
1040
	}
1051
	}
1041
1052
1042
	/**
1053
	/**
Lines 1278-1284 Link Here
1278
				provider instanceof ILazyContentProvider);
1289
				provider instanceof ILazyContentProvider);
1279
	}
1290
	}
1280
	
1291
	
1292
	private void applyCellEditing(boolean tabediting) {
1293
		CellEditor[] editors = getCellEditors();
1294
		
1295
		// There's already a listener known we need remove it from the cell-editors because every
1296
		// cell-editor should only hold one reference
1297
		if( this.tabeditingListener != null ) {
1298
			addRemoveEditingListeners(editors,this.tabeditingListener,false);
1299
		}
1300
		
1301
		if( tabediting ) {
1302
			if( this.tabeditingListener == null ) {
1303
				if( this.tabeditingDelgate == null ) {
1304
					this.tabeditingDelgate = new TabEditingDelegate();
1305
				}
1306
				this.tabeditingListener = new TabeditingListener();
1307
			}
1308
			
1309
			addRemoveEditingListeners(editors,this.tabeditingListener,true);
1310
		}
1311
	}
1312
	
1313
	private void addRemoveEditingListeners(CellEditor[] editors, TraverseListener listener, boolean add) {
1314
		if( editors != null ) {
1315
			for( int i = 0; i < editors.length; i++ ) {
1316
				if( editors[i] != null ) {
1317
					if( add ) {
1318
						editors[i].getControl().addTraverseListener(listener);
1319
					} else {
1320
						editors[i].getControl().addTraverseListener(listener);
1321
					}
1322
				}
1323
			}
1324
		}
1325
	}
1281
	
1326
	
1327
	/**
1328
	 * @param tabediting The tabediting to set.
1329
	 */
1330
	public void setTabediting(boolean tabediting) {
1331
		this.tabediting = tabediting;
1332
		if( tabediting && getCellEditors() != null ) {
1333
			applyCellEditing(true);
1334
		} else if( ! tabediting && getCellEditors() != null ) {
1335
			applyCellEditing(false);
1336
		}
1337
	}
1338
1339
	/**
1340
	 * @param tabeditingDelgate The tabeditingDelgate to set.
1341
	 */
1342
	public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate) {
1343
		this.tabeditingDelgate = tabeditingDelgate;
1344
	}
1282
	
1345
	
1346
	private class TabeditingListener implements TraverseListener {
1347
		public void keyTraversed(TraverseEvent e) {
1348
			TableViewer.this.tabeditingDelgate.focusNewEditor(e, TableViewer.this.tableEditor, TableViewer.this, table);
1349
		}
1350
	}
1283
}
1351
}
1284
1352
(-)src/org/eclipse/jface/viewers/TabEditingDelegate.java (+186 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.SWT;
15
import org.eclipse.swt.custom.TableEditor;
16
import org.eclipse.swt.events.TraverseEvent;
17
import org.eclipse.swt.widgets.Table;
18
19
/**
20
 * TableViewer delegates tabulator traversing to the class which implements how
21
 * elements are the next column in the table is selected. You may sub-class this
22
 * class and implement your own selection algorithm.
23
 * 
24
 * @since 3.2
25
 * @see TableViewer#setTabeditingDelgate(TabEditingDelegate)
26
 * @see TableViewer#setTabediting(boolean)
27
 */
28
public class TabEditingDelegate {
29
	private boolean moveToRowNeighbor = false;
30
31
	private boolean cycleInRow = false;
32
33
	private boolean rowTabing = true;
34
35
	private boolean columnTabing = true;
36
37
	/**
38
	 * This method is called when in the actually active cell-editor a traversal
39
	 * event is kicked of by the user. Subclasses may override this method to
40
	 * implement their own selection mechanism.
41
	 * 
42
	 * @param e
43
	 *            the traversal event
44
	 * @param tableEditor
45
	 *            the editor
46
	 * @param tableViewer
47
	 *            the table viewer the column belongs to
48
	 * @param table
49
	 *            the physical SWT-table
50
	 * @return true if a new column is activated
51
	 */
52
	public boolean focusNewEditor(TraverseEvent e, TableEditor tableEditor,
53
			TableViewer tableViewer, Table table) {
54
		// FIXME WHAT TO DO WHEN THE NEXT COLUMN IS NOT EDITABLE/HAS NO FOCUS
55
		int activeColumn = tableEditor.getColumn();
56
		int editColumn = -1;
57
58
		if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
59
			e.doit = false;
60
61
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
62
				int row = table.getSelectionIndex();
63
				if (row > 0) {
64
					table.setSelection(--row);
65
					editColumn = activeColumn;
66
				}
67
			} else if (columnTabing) {
68
				if (activeColumn > 0) {
69
					editColumn = --activeColumn;
70
				} else if (cycleInRow) {
71
					editColumn = table.getColumnCount() - 1;
72
				} else if (!moveToRowNeighbor) {
73
					int row = table.getSelectionIndex();
74
					if (row > 0) {
75
						table.setSelection(--row);
76
						editColumn = table.getColumnCount() - 1;
77
					}
78
				}
79
			}
80
		} else if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
81
			e.doit = false;
82
83
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
84
				int row = table.getSelectionIndex();
85
				if (row < table.getItemCount() - 1) {
86
					table.setSelection(++row);
87
					editColumn = activeColumn;
88
				}
89
			} else if (columnTabing) {
90
				if (activeColumn < table.getColumnCount() - 1) {
91
					editColumn = ++activeColumn;
92
				} else if (cycleInRow) {
93
					editColumn = 0;
94
				} else if (!moveToRowNeighbor) {
95
					int row = table.getSelectionIndex();
96
					if (row < table.getItemCount() - 1) {
97
						table.setSelection(++row);
98
						editColumn = 0;
99
					}
100
				}
101
			}
102
		}
103
104
		if (editColumn >= 0) {
105
			tableViewer.editElement(((IStructuredSelection) tableViewer
106
					.getSelection()).getFirstElement(), editColumn);
107
			return true;
108
		}
109
110
		return false;
111
	}
112
	
113
	/**
114
	 * @return Returns the columnTabing.
115
	 */
116
	public boolean isColumnTabing() {
117
		return columnTabing;
118
	}
119
120
	/**
121
	 * Setting this to true the user can move from column to column pressing TAB
122
	 * and SHIFT+TAB. This is turned on by default.
123
	 * 
124
	 * @param columnTabing
125
	 *            The columnTabing to set.
126
	 */
127
	public void setColumnTabing(boolean columnTabing) {
128
		this.columnTabing = columnTabing;
129
	}
130
131
	/**
132
	 * @return Returns the cycleInRow.
133
	 */
134
	public boolean isCycleInRow() {
135
		return cycleInRow;
136
	}
137
138
	/**
139
	 * Setting this to true results in the fact that when the end of the row is
140
	 * reached the cursor is moved to the first column in the row. This is
141
	 * turned of by default.
142
	 * 
143
	 * @param cycleInRow
144
	 *            The cycleInRow to set.
145
	 */
146
	public void setCycleInRow(boolean cycleInRow) {
147
		this.cycleInRow = cycleInRow;
148
	}
149
150
	/**
151
	 * Setting this to true results in the fact that when the end of the current
152
	 * row is reached the cursor is moved to first/last column in the
153
	 * successor/predecessor. This is turned of by default.
154
	 * 
155
	 * @return Returns the moveToRowNeighbor.
156
	 */
157
	public boolean isMoveToRowNeighbor() {
158
		return moveToRowNeighbor;
159
	}
160
161
	/**
162
	 * @param moveToRowNeighbor
163
	 *            The moveToRowNeighbor to set.
164
	 */
165
	public void setMoveToRowNeighbor(boolean moveToRowNeighbor) {
166
		this.moveToRowNeighbor = moveToRowNeighbor;
167
	}
168
169
	/**
170
	 * @return Returns the rowTabing.
171
	 */
172
	public boolean isRowTabing() {
173
		return rowTabing;
174
	}
175
176
	/**
177
	 * Setting this to true results in the fact that you user can jump from row
178
	 * to row using CTRL+TAB/CTRL+SHIFT+TAB. This is turned on by default.
179
	 * 
180
	 * @param rowTabing
181
	 *            The rowTabing to set.
182
	 */
183
	public void setRowTabing(boolean rowTabing) {
184
		this.rowTabing = rowTabing;
185
	}
186
}

Return to bug 75114