|
Lines 14-19
Link Here
|
| 14 |
|
14 |
|
| 15 |
package org.eclipse.jface.viewers; |
15 |
package org.eclipse.jface.viewers; |
| 16 |
|
16 |
|
|
|
17 |
import java.util.List; |
| 18 |
|
| 19 |
import org.eclipse.core.runtime.ListenerList; |
| 20 |
import org.eclipse.swt.SWT; |
| 17 |
import org.eclipse.swt.events.FocusAdapter; |
21 |
import org.eclipse.swt.events.FocusAdapter; |
| 18 |
import org.eclipse.swt.events.FocusEvent; |
22 |
import org.eclipse.swt.events.FocusEvent; |
| 19 |
import org.eclipse.swt.events.FocusListener; |
23 |
import org.eclipse.swt.events.FocusListener; |
|
Lines 22-28
Link Here
|
| 22 |
import org.eclipse.swt.events.MouseListener; |
26 |
import org.eclipse.swt.events.MouseListener; |
| 23 |
import org.eclipse.swt.events.TraverseEvent; |
27 |
import org.eclipse.swt.events.TraverseEvent; |
| 24 |
import org.eclipse.swt.events.TraverseListener; |
28 |
import org.eclipse.swt.events.TraverseListener; |
| 25 |
import org.eclipse.swt.graphics.Rectangle; |
|
|
| 26 |
import org.eclipse.swt.widgets.Control; |
29 |
import org.eclipse.swt.widgets.Control; |
| 27 |
import org.eclipse.swt.widgets.Display; |
30 |
import org.eclipse.swt.widgets.Display; |
| 28 |
import org.eclipse.swt.widgets.Item; |
31 |
import org.eclipse.swt.widgets.Item; |
|
Lines 40-75
Link Here
|
| 40 |
public abstract class ColumnViewerEditor { |
43 |
public abstract class ColumnViewerEditor { |
| 41 |
private CellEditor cellEditor; |
44 |
private CellEditor cellEditor; |
| 42 |
|
45 |
|
| 43 |
private CellEditor[] cellEditors; |
46 |
private ICellEditorListener cellEditorListener; |
| 44 |
|
47 |
|
| 45 |
private ICellModifier cellModifier; |
48 |
private FocusListener focusListener; |
| 46 |
|
49 |
|
| 47 |
private String[] columnProperties; |
50 |
private MouseListener mouseListener; |
| 48 |
|
51 |
|
| 49 |
private int columnNumber; |
52 |
private ColumnViewer viewer; |
| 50 |
|
53 |
|
| 51 |
private ICellEditorListener cellEditorListener; |
54 |
private TraverseListener tabeditingListener; |
| 52 |
|
55 |
|
| 53 |
private FocusListener focusListener; |
56 |
private int activationTime; |
| 54 |
|
57 |
|
| 55 |
private MouseListener mouseListener; |
58 |
private ViewerCell cell; |
| 56 |
|
59 |
|
| 57 |
private int doubleClickExpirationTime; |
60 |
private ColumnViewerEditorActivationEvent activationEvent; |
| 58 |
|
61 |
|
| 59 |
private ColumnViewer viewer; |
62 |
private ListenerList editorActivationListener; |
| 60 |
|
63 |
|
| 61 |
private Item item; |
64 |
private ColumnViewerEditorActivationStrategy editorActivationStrategy; |
| 62 |
|
65 |
|
| 63 |
private TraverseListener tabeditingListener; |
66 |
/** |
|
|
67 |
* Tabing from cell to cell is turned off |
| 68 |
*/ |
| 69 |
public static final int DEFAULT = 1; |
| 70 |
|
| 71 |
/** |
| 72 |
* Should if the end of the row is reach started from the start/end of the |
| 73 |
* row below/above |
| 74 |
*/ |
| 75 |
public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1; |
| 76 |
|
| 77 |
/** |
| 78 |
* Should if the end of the row is reach started from the beginning in the |
| 79 |
* same row |
| 80 |
*/ |
| 81 |
public static final int TABBING_CYCLE_IN_ROW = 1 << 2; |
| 82 |
|
| 83 |
/** |
| 84 |
* Support tabing to Cell above/below the current cell |
| 85 |
*/ |
| 86 |
public static final int TABBING_VERTICAL = 1 << 3; |
| 87 |
|
| 88 |
/** |
| 89 |
* Should tabing from column to column with in one row be supported |
| 90 |
*/ |
| 91 |
public static final int TABBING_HORIZONTAL = 1 << 4; |
| 64 |
|
92 |
|
| 65 |
/** |
93 |
/** |
| 66 |
* Create a new editor implementation for the viewer |
|
|
| 67 |
* |
94 |
* |
|
|
95 |
*/ |
| 96 |
public static final int KEYBOARD_ACTIVATION = 1 << 5; |
| 97 |
|
| 98 |
private int feature; |
| 99 |
|
| 100 |
/** |
| 68 |
* @param viewer |
101 |
* @param viewer |
| 69 |
* the column viewer |
102 |
* @param editorActivationStrategy |
|
|
103 |
* @param feature |
| 70 |
*/ |
104 |
*/ |
| 71 |
public ColumnViewerEditor(ColumnViewer viewer) { |
105 |
protected ColumnViewerEditor(ColumnViewer viewer, |
|
|
106 |
ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { |
| 72 |
this.viewer = viewer; |
107 |
this.viewer = viewer; |
|
|
108 |
this.editorActivationStrategy = editorActivationStrategy; |
| 109 |
if( (feature & KEYBOARD_ACTIVATION) == KEYBOARD_ACTIVATION ) { |
| 110 |
this.editorActivationStrategy.setEnableEditorActivationWithKeyboard(true); |
| 111 |
} |
| 112 |
this.feature = feature; |
| 73 |
initCellEditorListener(); |
113 |
initCellEditorListener(); |
| 74 |
} |
114 |
} |
| 75 |
|
115 |
|
|
Lines 92-119
Link Here
|
| 92 |
|
132 |
|
| 93 |
void activateCellEditor() { |
133 |
void activateCellEditor() { |
| 94 |
|
134 |
|
| 95 |
ViewerColumn part = viewer.getViewerColumn(columnNumber); |
135 |
ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex()); |
| 96 |
Object element = item.getData(); |
136 |
Object element = cell.getElement(); |
| 97 |
|
137 |
|
| 98 |
if (part != null && part.getEditingSupport() != null |
138 |
if (part != null && part.getEditingSupport() != null |
| 99 |
&& part.getEditingSupport().canEdit(element)) { |
139 |
&& part.getEditingSupport().canEdit(element)) { |
|
|
140 |
|
| 100 |
cellEditor = part.getEditingSupport().getCellEditor(element); |
141 |
cellEditor = part.getEditingSupport().getCellEditor(element); |
| 101 |
if (cellEditor != null) { |
142 |
if (cellEditor != null) { |
|
|
143 |
if (editorActivationListener != null |
| 144 |
&& !editorActivationListener.isEmpty()) { |
| 145 |
Object[] ls = editorActivationListener.getListeners(); |
| 146 |
for (int i = 0; i < ls.length; i++) { |
| 147 |
|
| 148 |
if (activationEvent.cancle) { |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 153 |
.beforeEditorActivated(activationEvent); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 102 |
cellEditor.addListener(cellEditorListener); |
157 |
cellEditor.addListener(cellEditorListener); |
| 103 |
Object value = part.getEditingSupport().getValue(element); |
158 |
Object value = part.getEditingSupport().getValue(element); |
| 104 |
cellEditor.setValue(value); |
159 |
part.getEditingSupport().setCellEditorValue(cellEditor, value); |
|
|
160 |
|
| 105 |
// Tricky flow of control here: |
161 |
// Tricky flow of control here: |
| 106 |
// activate() can trigger callback to cellEditorListener which |
162 |
// activate() can trigger callback to cellEditorListener which |
| 107 |
// will clear cellEditor |
163 |
// will clear cellEditor |
| 108 |
// so must get control first, but must still call activate() |
164 |
// so must get control first, but must still call activate() |
| 109 |
// even if there is no control. |
165 |
// even if there is no control. |
| 110 |
final Control control = cellEditor.getControl(); |
166 |
final Control control = cellEditor.getControl(); |
| 111 |
cellEditor.activate(); |
167 |
cellEditor.activate(activationEvent); |
| 112 |
if (control == null) { |
168 |
if (control == null) { |
| 113 |
return; |
169 |
return; |
| 114 |
} |
170 |
} |
| 115 |
setLayoutData(cellEditor.getLayoutData()); |
171 |
setLayoutData(cellEditor.getLayoutData()); |
| 116 |
setEditor(control, item, columnNumber); |
172 |
setEditor(control, cell.getItem(), cell.getColumnIndex()); |
| 117 |
cellEditor.setFocus(); |
173 |
cellEditor.setFocus(); |
| 118 |
if (focusListener == null) { |
174 |
if (focusListener == null) { |
| 119 |
focusListener = new FocusAdapter() { |
175 |
focusListener = new FocusAdapter() { |
|
Lines 128-134
Link Here
|
| 128 |
public void mouseDown(MouseEvent e) { |
184 |
public void mouseDown(MouseEvent e) { |
| 129 |
// time wrap? |
185 |
// time wrap? |
| 130 |
// check for expiration of doubleClickTime |
186 |
// check for expiration of doubleClickTime |
| 131 |
if (e.time <= doubleClickExpirationTime) { |
187 |
if (e.time <= activationTime) { |
| 132 |
control.removeMouseListener(mouseListener); |
188 |
control.removeMouseListener(mouseListener); |
| 133 |
cancelEditing(); |
189 |
cancelEditing(); |
| 134 |
handleDoubleClickEvent(); |
190 |
handleDoubleClickEvent(); |
|
Lines 139-195
Link Here
|
| 139 |
}; |
195 |
}; |
| 140 |
control.addMouseListener(mouseListener); |
196 |
control.addMouseListener(mouseListener); |
| 141 |
|
197 |
|
| 142 |
if( tabeditingListener == null ) { |
198 |
if (tabeditingListener == null) { |
| 143 |
tabeditingListener = new TraverseListener() { |
199 |
tabeditingListener = new TraverseListener() { |
| 144 |
|
200 |
|
| 145 |
public void keyTraversed(TraverseEvent e) { |
201 |
public void keyTraversed(TraverseEvent e) { |
| 146 |
ViewerColumn col = viewer.getViewerColumn(columnNumber); |
202 |
if ((feature & DEFAULT) != DEFAULT) { |
| 147 |
if ( col != null && col.getEditingSupport().isTabingSupported() ) { |
203 |
processTraversEvent(cell.getColumnIndex(), |
| 148 |
col.getEditingSupport().processTraversEvent( |
204 |
viewer.getViewerRowFromItem(cell |
| 149 |
columnNumber, |
205 |
.getItem()), e); |
| 150 |
viewer.getViewerRowFromItem(item), e); |
|
|
| 151 |
} |
206 |
} |
| 152 |
} |
207 |
} |
| 153 |
}; |
208 |
}; |
| 154 |
} |
209 |
} |
| 155 |
|
|
|
| 156 |
control.addTraverseListener(tabeditingListener); |
| 157 |
|
210 |
|
| 158 |
} |
211 |
control.addTraverseListener(tabeditingListener); |
| 159 |
} |
|
|
| 160 |
} |
| 161 |
|
212 |
|
| 162 |
/** |
213 |
if (editorActivationListener != null |
| 163 |
* Activate a cell editor for the given mouse position. |
214 |
&& !editorActivationListener.isEmpty()) { |
| 164 |
*/ |
215 |
Object[] ls = editorActivationListener.getListeners(); |
| 165 |
private void activateCellEditor(MouseEvent event) { |
216 |
for (int i = 0; i < ls.length; i++) { |
| 166 |
if (item == null || item.isDisposed()) { |
217 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 167 |
// item no longer exists |
218 |
.afterEditorActivated(activationEvent); |
| 168 |
return; |
219 |
} |
| 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 |
} |
220 |
} |
| 185 |
} |
221 |
} |
| 186 |
if (columnToEdit == -1) { |
|
|
| 187 |
return; |
| 188 |
} |
| 189 |
} |
222 |
} |
| 190 |
|
|
|
| 191 |
columnNumber = columnToEdit; |
| 192 |
activateCellEditor(); |
| 193 |
} |
223 |
} |
| 194 |
|
224 |
|
| 195 |
/** |
225 |
/** |
|
Lines 203-210
Link Here
|
| 203 |
// in case save results in applyEditorValue being re-entered |
233 |
// in case save results in applyEditorValue being re-entered |
| 204 |
// see 1GAHI8Z: ITPUI:ALL - How to code event notification when |
234 |
// see 1GAHI8Z: ITPUI:ALL - How to code event notification when |
| 205 |
// using cell editor ? |
235 |
// using cell editor ? |
|
|
236 |
ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell); |
| 237 |
if (editorActivationListener != null |
| 238 |
&& !editorActivationListener.isEmpty()) { |
| 239 |
Object[] ls = editorActivationListener.getListeners(); |
| 240 |
for (int i = 0; i < ls.length; i++) { |
| 241 |
|
| 242 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 243 |
.beforeEditorDeactivated(tmp); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 206 |
this.cellEditor = null; |
247 |
this.cellEditor = null; |
| 207 |
Item t = this.item; |
248 |
this.activationEvent = null; |
|
|
249 |
Item t = this.cell.getItem(); |
| 208 |
// don't null out table item -- same item is still selected |
250 |
// don't null out table item -- same item is still selected |
| 209 |
if (t != null && !t.isDisposed()) { |
251 |
if (t != null && !t.isDisposed()) { |
| 210 |
saveEditorValue(c, t); |
252 |
saveEditorValue(c, t); |
|
Lines 227-232
Link Here
|
| 227 |
} |
269 |
} |
| 228 |
} |
270 |
} |
| 229 |
c.deactivate(); |
271 |
c.deactivate(); |
|
|
272 |
|
| 273 |
if (editorActivationListener != null |
| 274 |
&& !editorActivationListener.isEmpty()) { |
| 275 |
Object[] ls = editorActivationListener.getListeners(); |
| 276 |
for (int i = 0; i < ls.length; i++) { |
| 277 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 278 |
.afterEditorDeactivated(tmp); |
| 279 |
} |
| 280 |
} |
| 230 |
} |
281 |
} |
| 231 |
} |
282 |
} |
| 232 |
|
283 |
|
|
Lines 235-240
Link Here
|
| 235 |
*/ |
286 |
*/ |
| 236 |
void cancelEditing() { |
287 |
void cancelEditing() { |
| 237 |
if (cellEditor != null) { |
288 |
if (cellEditor != null) { |
|
|
289 |
ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell); |
| 290 |
if (editorActivationListener != null |
| 291 |
&& !editorActivationListener.isEmpty()) { |
| 292 |
Object[] ls = editorActivationListener.getListeners(); |
| 293 |
for (int i = 0; i < ls.length; i++) { |
| 294 |
|
| 295 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 296 |
.beforeEditorDeactivated(tmp); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 238 |
setEditor(null, null, 0); |
300 |
setEditor(null, null, 0); |
| 239 |
cellEditor.removeListener(cellEditorListener); |
301 |
cellEditor.removeListener(cellEditorListener); |
| 240 |
|
302 |
|
|
Lines 256-262
Link Here
|
| 256 |
|
318 |
|
| 257 |
CellEditor oldEditor = cellEditor; |
319 |
CellEditor oldEditor = cellEditor; |
| 258 |
cellEditor = null; |
320 |
cellEditor = null; |
|
|
321 |
activationEvent = null; |
| 259 |
oldEditor.deactivate(); |
322 |
oldEditor.deactivate(); |
|
|
323 |
|
| 324 |
if (editorActivationListener != null |
| 325 |
&& !editorActivationListener.isEmpty()) { |
| 326 |
Object[] ls = editorActivationListener.getListeners(); |
| 327 |
for (int i = 0; i < ls.length; i++) { |
| 328 |
((ColumnViewerEditorActivationListener) ls[i]) |
| 329 |
.afterEditorDeactivated(tmp); |
| 330 |
} |
| 331 |
} |
| 260 |
} |
332 |
} |
| 261 |
} |
333 |
} |
| 262 |
|
334 |
|
|
Lines 265-329
Link Here
|
| 265 |
* |
337 |
* |
| 266 |
* @param event |
338 |
* @param event |
| 267 |
*/ |
339 |
*/ |
| 268 |
void handleMouseDown(MouseEvent event) { |
340 |
void handleEditorActivationEvent(ColumnViewerEditorActivationEvent event) { |
| 269 |
if (event.button != 1) { |
341 |
if (editorActivationStrategy.isEditorActivationEvent(event)) { |
| 270 |
return; |
342 |
if (cellEditor != null) { |
| 271 |
} |
343 |
applyEditorValue(); |
| 272 |
|
344 |
} |
| 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 |
|
345 |
|
| 295 |
/** |
346 |
this.cell = (ViewerCell) event.getSource(); |
| 296 |
* Start editing the given element. |
347 |
activationEvent = event; |
| 297 |
* |
348 |
activationTime = event.time |
| 298 |
* @param element |
349 |
+ Display.getCurrent().getDoubleClickTime(); |
| 299 |
* @param column |
|
|
| 300 |
*/ |
| 301 |
void editElement(Object element, int column) { |
| 302 |
if (cellEditor != null) { |
| 303 |
applyEditorValue(); |
| 304 |
} |
| 305 |
|
350 |
|
| 306 |
setSelection(createSelection(element), true); |
351 |
activateCellEditor(); |
| 307 |
Item[] selection = getSelection(); |
|
|
| 308 |
if (selection.length != 1) { |
| 309 |
return; |
| 310 |
} |
352 |
} |
| 311 |
|
|
|
| 312 |
item = selection[0]; |
| 313 |
|
| 314 |
// Make sure selection is visible |
| 315 |
showSelection(); |
| 316 |
columnNumber = column; |
| 317 |
activateCellEditor(); |
| 318 |
|
| 319 |
} |
353 |
} |
| 320 |
|
354 |
|
| 321 |
private void saveEditorValue(CellEditor cellEditor, Item tableItem) { |
355 |
private void saveEditorValue(CellEditor cellEditor, Item tableItem) { |
| 322 |
ViewerColumn part = viewer.getViewerColumn(columnNumber); |
356 |
ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex()); |
| 323 |
|
357 |
|
| 324 |
if (part != null && part.getEditingSupport() != null) { |
358 |
if (part != null && part.getEditingSupport() != null) { |
| 325 |
part.getEditingSupport().setValue(tableItem.getData(), |
359 |
Object value = part.getEditingSupport().getCellEditorValue(cellEditor); |
| 326 |
cellEditor.getValue()); |
360 |
part.getEditingSupport().setValue(tableItem.getData(),value); |
| 327 |
} |
361 |
} |
| 328 |
} |
362 |
} |
| 329 |
|
363 |
|
|
Lines 337-404
Link Here
|
| 337 |
return cellEditor != null; |
371 |
return cellEditor != null; |
| 338 |
} |
372 |
} |
| 339 |
|
373 |
|
| 340 |
/** |
374 |
void handleDoubleClickEvent() { |
| 341 |
* Set the cell editors |
375 |
viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer |
| 342 |
* |
376 |
.getSelection())); |
| 343 |
* @param editors |
377 |
viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection())); |
| 344 |
*/ |
|
|
| 345 |
void setCellEditors(CellEditor[] editors) { |
| 346 |
this.cellEditors = editors; |
| 347 |
} |
378 |
} |
| 348 |
|
379 |
|
| 349 |
/** |
380 |
void addEditorActivationListener( |
| 350 |
* Set the cell modifier |
381 |
ColumnViewerEditorActivationListener listener) { |
| 351 |
* |
382 |
if (editorActivationListener == null) { |
| 352 |
* @param modifier |
383 |
editorActivationListener = new ListenerList(); |
| 353 |
*/ |
384 |
} |
| 354 |
void setCellModifier(ICellModifier modifier) { |
385 |
editorActivationListener.add(listener); |
| 355 |
this.cellModifier = modifier; |
|
|
| 356 |
} |
386 |
} |
| 357 |
|
387 |
|
| 358 |
/** |
388 |
void removeEditorActivationListener( |
| 359 |
* Set the column properties |
389 |
ColumnViewerEditorActivationListener listener) { |
| 360 |
* |
390 |
if (editorActivationListener != null) { |
| 361 |
* @param columnProperties |
391 |
editorActivationListener.remove(listener); |
| 362 |
*/ |
392 |
} |
| 363 |
void setColumnProperties(String[] columnProperties) { |
|
|
| 364 |
this.columnProperties = columnProperties; |
| 365 |
} |
393 |
} |
| 366 |
|
394 |
|
| 367 |
/** |
395 |
void setEditorActivationStrategy( |
| 368 |
* Return the properties for the column |
396 |
ColumnViewerEditorActivationStrategy editorActivationStrategy) { |
| 369 |
* |
397 |
this.editorActivationStrategy = editorActivationStrategy; |
| 370 |
* @return the array of column properties |
|
|
| 371 |
*/ |
| 372 |
Object[] getColumnProperties() { |
| 373 |
return columnProperties; |
| 374 |
} |
398 |
} |
| 375 |
|
399 |
|
| 376 |
/** |
400 |
/** |
| 377 |
* Get the cell modifier |
401 |
* Process the travers event and opens the next available editor depending |
|
|
402 |
* of the implemented strategy. The default implementation uses the style |
| 403 |
* constants |
| 404 |
* <ul> |
| 405 |
* <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li> |
| 406 |
* <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li> |
| 407 |
* <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li> |
| 408 |
* <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li> |
| 409 |
* </ul> |
| 410 |
* |
| 411 |
* <p> |
| 412 |
* Subclasses may overwrite to implement their custom logic to edit the next |
| 413 |
* cell |
| 414 |
* </p> |
| 378 |
* |
415 |
* |
| 379 |
* @return the cell modifier |
416 |
* @param columnIndex |
|
|
417 |
* the index of the current column |
| 418 |
* @param row |
| 419 |
* the current row |
| 420 |
* @param event |
| 421 |
* the travers event |
| 380 |
*/ |
422 |
*/ |
| 381 |
ICellModifier getCellModifier() { |
423 |
protected void processTraversEvent(int columnIndex, ViewerRow row, |
| 382 |
return cellModifier; |
424 |
TraverseEvent event) { |
|
|
425 |
|
| 426 |
ViewerCell cell2edit = null; |
| 427 |
|
| 428 |
if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) { |
| 429 |
event.doit = false; |
| 430 |
|
| 431 |
if ((event.stateMask & SWT.CTRL) == SWT.CTRL |
| 432 |
&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) { |
| 433 |
cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true); |
| 434 |
} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { |
| 435 |
cell2edit = searchPreviousCell(row, viewer, columnIndex, |
| 436 |
columnIndex); |
| 437 |
} |
| 438 |
} else if (event.detail == SWT.TRAVERSE_TAB_NEXT) { |
| 439 |
event.doit = false; |
| 440 |
|
| 441 |
if ((event.stateMask & SWT.CTRL) == SWT.CTRL |
| 442 |
&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) { |
| 443 |
cell2edit = searchCellAboveBelow(row, viewer, columnIndex, |
| 444 |
false); |
| 445 |
} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { |
| 446 |
cell2edit = searchNextCell(row, viewer, columnIndex, |
| 447 |
columnIndex); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
if (cell2edit != null) { |
| 452 |
List l = viewer.getSelectionFromWidget(); |
| 453 |
|
| 454 |
viewer.getControl().setRedraw(false); |
| 455 |
|
| 456 |
// TODO Is this correct in terms of other controls e.g. grid |
| 457 |
if (!l.contains(cell2edit.getElement())) { |
| 458 |
viewer.setSelection(new StructuredSelection(cell2edit |
| 459 |
.getElement())); |
| 460 |
} |
| 461 |
|
| 462 |
ColumnViewerEditorActivationEvent acEvent = new ColumnViewerEditorActivationEvent( |
| 463 |
cell2edit, event); |
| 464 |
viewer.triggerEditorActivationEvent(acEvent); |
| 465 |
viewer.getControl().setRedraw(true); |
| 466 |
} |
| 383 |
} |
467 |
} |
| 384 |
|
468 |
|
| 385 |
/** |
469 |
private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer, |
| 386 |
* Return the array of CellEditors used in the viewer |
470 |
int columnIndex, boolean above) { |
| 387 |
* |
471 |
ViewerCell rv = null; |
| 388 |
* @return the cell editors |
472 |
|
| 389 |
*/ |
473 |
ViewerRow newRow = null; |
| 390 |
CellEditor[] getCellEditors() { |
474 |
|
| 391 |
return cellEditors; |
475 |
if (above) { |
|
|
476 |
newRow = row.getNeighbor(ViewerRow.ABOVE, false); |
| 477 |
} else { |
| 478 |
newRow = row.getNeighbor(ViewerRow.BELOW, false); |
| 479 |
} |
| 480 |
|
| 481 |
if (newRow != null) { |
| 482 |
ViewerColumn column = viewer.getViewerColumn(columnIndex); |
| 483 |
if (column != null && column.getEditingSupport() != null |
| 484 |
&& column.getEditingSupport().canEdit( |
| 485 |
newRow.getItem().getData())) { |
| 486 |
rv = newRow.getCell(columnIndex); |
| 487 |
} else { |
| 488 |
rv = searchCellAboveBelow(newRow, viewer, columnIndex, above); |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
return rv; |
| 392 |
} |
493 |
} |
| 393 |
|
494 |
|
| 394 |
void setSelection(StructuredSelection selection, boolean b) { |
495 |
private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer, |
| 395 |
viewer.setSelection(selection, b); |
496 |
int columnIndex, int startIndex) { |
|
|
497 |
ViewerCell rv = null; |
| 498 |
|
| 499 |
if (columnIndex - 1 >= 0) { |
| 500 |
ViewerColumn column = viewer.getViewerColumn(columnIndex - 1); |
| 501 |
if (column != null && column.getEditingSupport() != null |
| 502 |
&& column.getEditingSupport().canEdit( |
| 503 |
row.getItem().getData())) { |
| 504 |
rv = row.getCell(columnIndex - 1); |
| 505 |
} else { |
| 506 |
rv = searchPreviousCell(row, viewer, columnIndex - 1, |
| 507 |
startIndex); |
| 508 |
} |
| 509 |
} else { |
| 510 |
if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { |
| 511 |
// Check that we don't get into endless loop |
| 512 |
if (columnIndex - 1 != startIndex) { |
| 513 |
// Don't subtract -1 from getColumnCount() we need to |
| 514 |
// start in the virtual column |
| 515 |
// next to it |
| 516 |
rv = searchPreviousCell(row, viewer, row.getColumnCount(), |
| 517 |
startIndex); |
| 518 |
} |
| 519 |
} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { |
| 520 |
ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE, false); |
| 521 |
if (rowAbove != null) { |
| 522 |
rv = searchPreviousCell(rowAbove, viewer, rowAbove |
| 523 |
.getColumnCount(), startIndex); |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
return rv; |
| 396 |
} |
529 |
} |
| 397 |
|
530 |
|
| 398 |
void handleDoubleClickEvent() { |
531 |
private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer, |
| 399 |
viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer |
532 |
int columnIndex, int startIndex) { |
| 400 |
.getSelection())); |
533 |
ViewerCell rv = null; |
| 401 |
viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection())); |
534 |
|
|
|
535 |
if (columnIndex + 1 < row.getColumnCount()) { |
| 536 |
ViewerColumn column = viewer.getViewerColumn(columnIndex + 1); |
| 537 |
if (column != null && column.getEditingSupport() != null |
| 538 |
&& column.getEditingSupport().canEdit( |
| 539 |
row.getItem().getData())) { |
| 540 |
rv = row.getCell(columnIndex + 1); |
| 541 |
} else { |
| 542 |
rv = searchNextCell(row, viewer, columnIndex + 1, startIndex); |
| 543 |
} |
| 544 |
} else { |
| 545 |
if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { |
| 546 |
// Check that we don't get into endless loop |
| 547 |
if (columnIndex + 1 != startIndex) { |
| 548 |
// Start from -1 from the virtual column before the |
| 549 |
// first one |
| 550 |
rv = searchNextCell(row, viewer, -1, startIndex); |
| 551 |
} |
| 552 |
} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { |
| 553 |
ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW, false); |
| 554 |
if (rowBelow != null) { |
| 555 |
rv = searchNextCell(rowBelow, viewer, -1, startIndex); |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
return rv; |
| 402 |
} |
561 |
} |
| 403 |
|
562 |
|
| 404 |
/** |
563 |
/** |
|
Lines 431-442
Link Here
|
| 431 |
protected abstract void setLayoutData(CellEditor.LayoutData layoutData); |
590 |
protected abstract void setLayoutData(CellEditor.LayoutData layoutData); |
| 432 |
|
591 |
|
| 433 |
/** |
592 |
/** |
| 434 |
* Show up the current selection (scroll the selection into view) |
593 |
* @return the cell currently holding the focus |
|
|
594 |
* |
| 435 |
*/ |
595 |
*/ |
| 436 |
protected abstract void showSelection(); |
596 |
public ViewerCell getFocusCell() { |
|
|
597 |
return null; |
| 598 |
} |
| 437 |
|
599 |
|
| 438 |
/** |
600 |
/** |
| 439 |
* @return the current selection |
601 |
* @return the viewer working for |
| 440 |
*/ |
602 |
*/ |
| 441 |
protected abstract Item[] getSelection(); |
603 |
protected ColumnViewer getViewer() { |
| 442 |
} |
604 |
return viewer; |
|
|
605 |
} |
| 606 |
} |