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