|
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 |
} |