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