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 (-2 / +96 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 63-70 Link Here
63
 * @see #doFindItem(Object)
65
 * @see #doFindItem(Object)
64
 * @see #internalRefresh(Object, boolean)
66
 * @see #internalRefresh(Object, boolean)
65
 */
67
 */
66
public class TableViewer extends StructuredViewer {
68
public class TableViewer extends StructuredViewer implements ITabEditingSupport {
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
		private TabEditingSupportWrapper wrapper = new TabEditingSupportWrapper() {
1348
1349
			public void setSelectedRow(int index) {
1350
				TableViewer.this.table.setSelection(index);
1351
			}
1352
1353
			public int getColumnCount() {
1354
				return TableViewer.this.table.getColumnCount();
1355
			}
1356
1357
			public int getCurrentColumnIndex() {
1358
				return TableViewer.this.tableEditor.getColumn();
1359
			}
1360
1361
			public int getCurrentRowIndex() {
1362
				return TableViewer.this.table.getSelectionIndex();
1363
			}
1364
1365
			public int getRowCount() {
1366
				return TableViewer.this.table.getItemCount();
1367
			}
1368
			
1369
		};
1370
		
1371
		public void keyTraversed(TraverseEvent e) {
1372
			if( TableViewer.this.tabeditingDelgate != null ) {
1373
				TableViewer.this.tabeditingDelgate.focusNewEditor(e, TableViewer.this, wrapper);
1374
			}
1375
		}
1376
	}
1283
}
1377
}
1284
1378
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-1 / +103 lines)
Lines 21-26 Link Here
21
import org.eclipse.swt.events.DisposeListener;
21
import org.eclipse.swt.events.DisposeListener;
22
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.TraverseEvent;
25
import org.eclipse.swt.events.TraverseListener;
24
import org.eclipse.swt.events.TreeListener;
26
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
28
import org.eclipse.swt.graphics.Point;
Lines 47-54 Link Here
47
 * <code>ITreeContentProvider</code> interface.
49
 * <code>ITreeContentProvider</code> interface.
48
 * </p>
50
 * </p>
49
 */
51
 */
50
public class TreeViewer extends AbstractTreeViewer {
52
public class TreeViewer extends AbstractTreeViewer implements ITabEditingSupport {
51
53
54
	private boolean tabediting = false;
55
	
56
	private TabeditingListener tabeditingListener;
57
58
	private TabEditingDelegate tabeditingDelgate;
59
60
	
52
	/**
61
	/**
53
	 * TreeColorAndFontCollector is an helper class for color and font support
62
	 * TreeColorAndFontCollector is an helper class for color and font support
54
	 * for trees that support the ITableFontProvider and the
63
	 * for trees that support the ITableFontProvider and the
Lines 609-614 Link Here
609
	 */
618
	 */
610
	public void setCellEditors(CellEditor[] editors) {
619
	public void setCellEditors(CellEditor[] editors) {
611
		treeViewerImpl.setCellEditors(editors);
620
		treeViewerImpl.setCellEditors(editors);
621
		
622
		if( tabediting ) {
623
			applyCellEditing(tabediting);
624
		}
612
	}
625
	}
613
626
614
	/**
627
	/**
Lines 985-988 Link Here
985
				}});
998
				}});
986
		}
999
		}
987
	}
1000
	}
1001
	
1002
	private void applyCellEditing(boolean tabediting) {
1003
		CellEditor[] editors = getCellEditors();
1004
		
1005
		// There's already a listener known we need remove it from the cell-editors because every
1006
		// cell-editor should only hold one reference
1007
		if( this.tabeditingListener != null ) {
1008
			addRemoveEditingListeners(editors,this.tabeditingListener,false);
1009
		}
1010
		
1011
		if( tabediting ) {
1012
			if( this.tabeditingListener == null ) {
1013
				if( this.tabeditingDelgate == null ) {
1014
					this.tabeditingDelgate = new TabEditingDelegate();
1015
				}
1016
				this.tabeditingListener = new TabeditingListener();
1017
			}
1018
			
1019
			addRemoveEditingListeners(editors,this.tabeditingListener,true);
1020
		}
1021
	}
1022
	
1023
	private void addRemoveEditingListeners(CellEditor[] editors, TraverseListener listener, boolean add) {
1024
		if( editors != null ) {
1025
			for( int i = 0; i < editors.length; i++ ) {
1026
				if( editors[i] != null ) {
1027
					if( add ) {
1028
						editors[i].getControl().addTraverseListener(listener);
1029
					} else {
1030
						editors[i].getControl().addTraverseListener(listener);
1031
					}
1032
				}
1033
			}
1034
		}
1035
	}
1036
	
1037
	/**
1038
	 * @param tabediting The tabediting to set.
1039
	 */
1040
	public void setTabediting(boolean tabediting) {
1041
		this.tabediting = tabediting;
1042
		if( tabediting && getCellEditors() != null ) {
1043
			applyCellEditing(true);
1044
		} else if( ! tabediting && getCellEditors() != null ) {
1045
			applyCellEditing(false);
1046
		}
1047
	}
1048
1049
	/**
1050
	 * @param tabeditingDelgate The tabeditingDelgate to set.
1051
	 */
1052
	public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate) {
1053
		this.tabeditingDelgate = tabeditingDelgate;
1054
	}
1055
	
1056
	private class TabeditingListener implements TraverseListener {
1057
		private TabEditingSupportWrapper wrapper = new TabEditingSupportWrapper() {
1058
1059
			public void setSelectedRow(int index) {
1060
				TreeItem item = TreeViewer.this.tree.getItem(index);
1061
				TreeViewer.this.tree.setSelection(item);
1062
			}
1063
1064
			public int getColumnCount() {				
1065
				return TreeViewer.this.tree.getColumnCount();
1066
			}
1067
1068
			public int getCurrentColumnIndex() {
1069
				return TreeViewer.this.treeEditor.getColumn();
1070
			}
1071
1072
			public int getCurrentRowIndex() {
1073
				// FIXME TABING FROM ROW TO ROW
1074
				return 0;
1075
			}
1076
1077
			public int getRowCount() {
1078
				// FIXME TABING FROM ROW TO ROW
1079
				return 0;
1080
			}
1081
			
1082
		};
1083
		
1084
		public void keyTraversed(TraverseEvent e) {
1085
			if( TreeViewer.this.tabeditingDelgate != null ) {
1086
				TreeViewer.this.tabeditingDelgate.focusNewEditor(e, TreeViewer.this, wrapper);
1087
			}
1088
		}
1089
	}
988
}
1090
}
(-)src/org/eclipse/jface/viewers/ITabEditingSupport.java (+59 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
 * Viewers who want to provide tabulator editing features have to implement this
16
 * interface.
17
 * 
18
 * @since 3.2
19
 * 
20
 */
21
public interface ITabEditingSupport {
22
23
	/**
24
	 * @param tabediting
25
	 *            Turn on/off tab-editing support
26
	 */
27
	public void setTabediting(boolean tabediting);
28
29
	/**
30
	 * Set your own tab-editing delegate
31
	 * 
32
	 * @param tabeditingDelgate the new delegate
33
	 */
34
	public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate);
35
36
	/**
37
	 * Starts editing the given element.
38
	 * 
39
	 * @param element
40
	 *            the element
41
	 * @param column
42
	 *            the column number
43
	 * @see TableViewer#editElement(Object, int)
44
	 * @see TreeViewer#editElement(Object, int)
45
	 */
46
	public void editElement(Object element, int column);
47
48
	/**
49
	 * The <code>StructuredViewer</code> implementation of this method returns
50
	 * the result as an <code>IStructuredSelection</code>.
51
	 * <p>
52
	 * Subclasses do not typically override this method, but implement
53
	 * <code>getSelectionFromWidget(List)</code> instead.
54
	 * <p>
55
	 * @return ISelection
56
	 * @see ISelectionProvider#getSelection()
57
	 */
58
	public ISelection getSelection();
59
}
(-)src/org/eclipse/jface/viewers/TabEditingDelegate.java (+192 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.events.TraverseEvent;
16
17
/**
18
 * TableViewer delegates tabulator traversing to the class which implements how
19
 * elements are the next column in the table is selected. You may sub-class this
20
 * class and implement your own selection algorithm.
21
 * 
22
 * @since 3.2
23
 * @see TableViewer#setTabeditingDelgate(TabEditingDelegate)
24
 * @see TableViewer#setTabediting(boolean)
25
 */
26
public class TabEditingDelegate {
27
	private boolean moveToRowNeighbor = false;
28
29
	private boolean cycleInRow = false;
30
31
	private boolean rowTabing = true;
32
33
	private boolean columnTabing = true;
34
35
	/**
36
	 * This method is called when in the actually active cell-editor a traversal
37
	 * event is kicked of by the user. Subclasses may override this method to
38
	 * implement their own selection mechanism.
39
	 * 
40
	 * @param e
41
	 *            the traversal event
42
	 * 
43
	 * @param activeColumn
44
	 *            the currently active column
45
	 * @param totalColumns
46
	 *            the totla number of columns
47
	 * @param activeRow
48
	 *            the active row
49
	 * @param totalRows
50
	 *            the total number of rows
51
	 * @param viewer
52
	 *            the viewer which support tabing
53
	 * @param widgetWrapper
54
	 *            the swt wigdet wrapped in a helper class
55
	 * @return true of a new column is activated
56
	 */
57
	public boolean focusNewEditor(TraverseEvent e, ITabEditingSupport viewer,
58
			TabEditingSupportWrapper widgetWrapper) {
59
		// FIXME WHAT TO DO WHEN THE NEXT COLUMN IS NOT EDITABLE/HAS NO FOCUS
60
		
61
		int activeColumn = widgetWrapper.getCurrentColumnIndex();
62
		int totalColumns = widgetWrapper.getColumnCount();
63
		int activeRow = widgetWrapper.getCurrentRowIndex(); 
64
		int totalRows = widgetWrapper.getRowCount();
65
		
66
		int editColumn = -1;
67
68
		if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
69
			e.doit = false;
70
71
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
72
				if (activeRow > 0) {
73
					widgetWrapper.setSelectedRow(--activeRow);
74
					editColumn = activeColumn;
75
				}
76
			} else if (columnTabing) {
77
				if (activeColumn > 0) {
78
					editColumn = --activeColumn;
79
				} else if (cycleInRow) {
80
					editColumn = totalColumns - 1;
81
				} else if (moveToRowNeighbor) {
82
					if (activeRow > 0) {
83
						widgetWrapper.setSelectedRow(--activeRow);
84
						editColumn = totalColumns - 1;
85
					}
86
				}
87
			}
88
		} else if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
89
			e.doit = false;
90
91
			if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) {
92
				if (activeRow < totalRows - 1) {
93
					widgetWrapper.setSelectedRow(++activeRow);
94
					editColumn = activeColumn;
95
				}
96
			} else if (columnTabing) {
97
				if (activeColumn < totalColumns - 1) {
98
					editColumn = ++activeColumn;
99
				} else if (cycleInRow) {
100
					editColumn = 0;
101
				} else if (moveToRowNeighbor) {
102
					if (activeRow < totalRows - 1) {
103
						widgetWrapper.setSelectedRow(++activeRow);
104
						editColumn = 0;
105
					}
106
				}
107
			}
108
		}
109
110
		if (editColumn >= 0) {
111
			viewer.editElement(((IStructuredSelection) viewer.getSelection())
112
					.getFirstElement(), editColumn);
113
			return true;
114
		}
115
116
		return false;
117
	}
118
119
	/**
120
	 * @return Returns the columnTabing.
121
	 */
122
	public boolean isColumnTabing() {
123
		return columnTabing;
124
	}
125
126
	/**
127
	 * Setting this to true the user can move from column to column pressing TAB
128
	 * and SHIFT+TAB. This is turned on by default.
129
	 * 
130
	 * @param columnTabing
131
	 *            The columnTabing to set.
132
	 */
133
	public void setColumnTabing(boolean columnTabing) {
134
		this.columnTabing = columnTabing;
135
	}
136
137
	/**
138
	 * @return Returns the cycleInRow.
139
	 */
140
	public boolean isCycleInRow() {
141
		return cycleInRow;
142
	}
143
144
	/**
145
	 * Setting this to true results in the fact that when the end of the row is
146
	 * reached the cursor is moved to the first column in the row. This is
147
	 * turned of by default.
148
	 * 
149
	 * @param cycleInRow
150
	 *            The cycleInRow to set.
151
	 */
152
	public void setCycleInRow(boolean cycleInRow) {
153
		this.cycleInRow = cycleInRow;
154
	}
155
156
	/**
157
	 * Setting this to true results in the fact that when the end of the current
158
	 * row is reached the cursor is moved to first/last column in the
159
	 * successor/predecessor. This is turned of by default.
160
	 * 
161
	 * @return Returns the moveToRowNeighbor.
162
	 */
163
	public boolean isMoveToRowNeighbor() {
164
		return moveToRowNeighbor;
165
	}
166
167
	/**
168
	 * @param moveToRowNeighbor
169
	 *            The moveToRowNeighbor to set.
170
	 */
171
	public void setMoveToRowNeighbor(boolean moveToRowNeighbor) {
172
		this.moveToRowNeighbor = moveToRowNeighbor;
173
	}
174
175
	/**
176
	 * @return Returns the rowTabing.
177
	 */
178
	public boolean isRowTabing() {
179
		return rowTabing;
180
	}
181
182
	/**
183
	 * Setting this to true results in the fact that you user can jump from row
184
	 * to row using CTRL+TAB/CTRL+SHIFT+TAB. This is turned on by default.
185
	 * 
186
	 * @param rowTabing
187
	 *            The rowTabing to set.
188
	 */
189
	public void setRowTabing(boolean rowTabing) {
190
		this.rowTabing = rowTabing;
191
	}
192
}
(-)src/org/eclipse/jface/viewers/TabEditingSupportWrapper.java (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * This class 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
 * @since 3.2
20
 * 
21
 */
22
public abstract class TabEditingSupportWrapper {
23
	/**
24
	 * Set the current selected row
25
	 * 
26
	 * @param index
27
	 *            the new row index
28
	 */
29
	public abstract void setSelectedRow(int index);
30
31
	/**
32
	 * @return the total number of columns
33
	 */
34
	public abstract int getColumnCount();
35
36
	/**
37
	 * @return the total number of rows
38
	 */
39
	public abstract int getRowCount();
40
41
	/**
42
	 * @return the current column indexF
43
	 */
44
	public abstract int getCurrentColumnIndex();
45
46
	/**
47
	 * @return the current row index
48
	 */
49
	public abstract int getCurrentRowIndex();
50
}

Return to bug 75114