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