Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/viewers/CellEditor.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | c1762259c684 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2008 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 * Tom Schindl <tom.schindl@bestsolution.at> - bugfix in: 187963, 218336 | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 | |
15 module org.eclipse.jface.viewers.CellEditor; | |
16 | |
17 import org.eclipse.jface.viewers.ICellEditorValidator; | |
18 import org.eclipse.jface.viewers.ICellEditorListener; | |
19 import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; | |
20 import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent; | |
21 | |
22 import org.eclipse.swt.SWT; | |
23 import org.eclipse.swt.events.KeyEvent; | |
24 import org.eclipse.swt.widgets.Composite; | |
25 import org.eclipse.swt.widgets.Control; | |
26 import org.eclipse.swt.widgets.Display; | |
27 import org.eclipse.core.runtime.Assert; | |
28 import org.eclipse.core.runtime.ListenerList; | |
29 import org.eclipse.jface.util.IPropertyChangeListener; | |
30 import org.eclipse.jface.util.PropertyChangeEvent; | |
31 import org.eclipse.jface.util.SafeRunnable; | |
32 | |
33 import java.lang.all; | |
34 import java.util.List; | |
35 import java.util.Set; | |
36 | |
37 /** | |
38 * Struct-like layout data for cell editors, with reasonable defaults for | |
39 * all fields. | |
40 * | |
41 * @noextend This class is not intended to be subclassed by clients. | |
42 */ | |
43 public static class LayoutData { | |
44 /** | |
45 * Horizontal alignment; <code>SWT.LEFT</code> by default. | |
46 */ | |
47 public int horizontalAlignment = SWT.LEFT; | |
48 | |
49 /** | |
50 * Indicates control grabs additional space; <code>true</code> by | |
51 * default. | |
52 */ | |
53 public bool grabHorizontal = true; | |
54 | |
55 /** | |
56 * Minimum width in pixels; <code>50</code> pixels by default. | |
57 */ | |
58 public int minimumWidth = 50; | |
59 | |
60 /** | |
61 * Minimum height in pixels; by default the height is aligned to the | |
62 * row-height | |
63 * @since 3.4 | |
64 */ | |
65 public int minimumHeight = SWT.DEFAULT; | |
66 | |
67 /** | |
68 * The vertical alignment; <code>SWT.CENTER</code> by default. | |
69 * @since 3.4 | |
70 */ | |
71 public int verticalAlignment = SWT.CENTER; | |
72 } | |
73 /** | |
74 * Abstract base class for cell editors. Implements property change listener | |
75 * handling, and SWT window management. | |
76 * <p> | |
77 * Subclasses implement particular kinds of cell editors. This package contains | |
78 * various specialized cell editors: | |
79 * <ul> | |
80 * <li><code>TextCellEditor</code> - for simple text strings</li> | |
81 * <li><code>ColorCellEditor</code> - for colors</li> | |
82 * <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo | |
83 * box</li> | |
84 * <li><code>CheckboxCellEditor</code> - bool valued checkbox</li> | |
85 * <li><code>DialogCellEditor</code> - value from arbitrary dialog</li> | |
86 * </ul> | |
87 * </p> | |
88 */ | |
89 public abstract class CellEditor { | |
90 | |
91 /** | |
92 * List of cell editor listeners (element type: | |
93 * <code>ICellEditorListener</code>). | |
94 */ | |
95 private ListenerList listeners; | |
96 | |
97 /** | |
98 * List of cell editor property change listeners (element type: | |
99 * <code>IPropertyChangeListener</code>). | |
100 */ | |
101 private ListenerList propertyChangeListeners; | |
102 | |
103 /** | |
104 * Indicates whether this cell editor's current value is valid. | |
105 */ | |
106 private bool valid = false; | |
107 | |
108 /** | |
109 * Optional cell editor validator; <code>null</code> if none. | |
110 */ | |
111 private ICellEditorValidator validator = null; | |
112 | |
113 /** | |
114 * The error message string to display for invalid values; <code>null</code> | |
115 * if none (that is, the value is valid). | |
116 */ | |
117 private String errorMessage = null; | |
118 | |
119 /** | |
120 * Indicates whether this cell editor has been changed recently. | |
121 */ | |
122 private bool dirty = false; | |
123 | |
124 /** | |
125 * This cell editor's control, or <code>null</code> if not created yet. | |
126 */ | |
127 private Control control = null; | |
128 | |
129 /** | |
130 * Default cell editor style | |
131 */ | |
132 private static const int defaultStyle = SWT.NONE; | |
133 | |
134 /** | |
135 * This cell editor's style | |
136 */ | |
137 private int style = defaultStyle; | |
138 | |
139 //public alias org.eclipse.jface.viewers.CellEditor.LayoutData LayoutData; | |
140 /** | |
141 * Property name for the copy action | |
142 */ | |
143 public static const String COPY = "copy"; //$NON-NLS-1$ | |
144 | |
145 /** | |
146 * Property name for the cut action | |
147 */ | |
148 public static const String CUT = "cut"; //$NON-NLS-1$ | |
149 | |
150 /** | |
151 * Property name for the delete action | |
152 */ | |
153 public static const String DELETE = "delete"; //$NON-NLS-1$ | |
154 | |
155 /** | |
156 * Property name for the find action | |
157 */ | |
158 public static const String FIND = "find"; //$NON-NLS-1$ | |
159 | |
160 /** | |
161 * Property name for the paste action | |
162 */ | |
163 public static const String PASTE = "paste"; //$NON-NLS-1$ | |
164 | |
165 /** | |
166 * Property name for the redo action | |
167 */ | |
168 public static const String REDO = "redo"; //$NON-NLS-1$ | |
169 | |
170 /** | |
171 * Property name for the select all action | |
172 */ | |
173 public static const String SELECT_ALL = "selectall"; //$NON-NLS-1$ | |
174 | |
175 /** | |
176 * Property name for the undo action | |
177 */ | |
178 public static const String UNDO = "undo"; //$NON-NLS-1$ | |
179 | |
180 /** | |
181 * Creates a new cell editor with no control The cell editor has no cell | |
182 * validator. | |
183 * | |
184 * @since 2.1 | |
185 */ | |
186 protected this() { | |
187 propertyChangeListeners = new ListenerList(); | |
188 listeners = new ListenerList(); | |
189 } | |
190 | |
191 /** | |
192 * Creates a new cell editor under the given parent control. The cell editor | |
193 * has no cell validator. | |
194 * | |
195 * @param parent | |
196 * the parent control | |
197 */ | |
198 protected this(Composite parent) { | |
199 this(parent, defaultStyle); | |
200 } | |
201 | |
202 /** | |
203 * Creates a new cell editor under the given parent control. The cell editor | |
204 * has no cell validator. | |
205 * | |
206 * @param parent | |
207 * the parent control | |
208 * @param style | |
209 * the style bits | |
210 * @since 2.1 | |
211 */ | |
212 protected this(Composite parent, int style) { | |
213 propertyChangeListeners = new ListenerList(); | |
214 listeners = new ListenerList(); | |
215 this.style = style; | |
216 create(parent); | |
217 } | |
218 | |
219 /** | |
220 * Activates this cell editor. | |
221 * <p> | |
222 * The default implementation of this framework method does nothing. | |
223 * Subclasses may reimplement. | |
224 * </p> | |
225 */ | |
226 public void activate() { | |
227 } | |
228 | |
229 /** | |
230 * Adds a listener to this cell editor. Has no effect if an identical | |
231 * listener is already registered. | |
232 * | |
233 * @param listener | |
234 * a cell editor listener | |
235 */ | |
236 public void addListener(ICellEditorListener listener) { | |
237 listeners.add(cast(Object)listener); | |
238 } | |
239 | |
240 /** | |
241 * Adds a property change listener to this cell editor. Has no effect if an | |
242 * identical property change listener is already registered. | |
243 * | |
244 * @param listener | |
245 * a property change listener | |
246 */ | |
247 public void addPropertyChangeListener(IPropertyChangeListener listener) { | |
248 propertyChangeListeners.add(cast(Object)listener); | |
249 } | |
250 | |
251 /** | |
252 * Creates the control for this cell editor under the given parent control. | |
253 * <p> | |
254 * This framework method must be implemented by concrete subclasses. | |
255 * </p> | |
256 * | |
257 * @param parent | |
258 * the parent control | |
259 * @return the new control, or <code>null</code> if this cell editor has | |
260 * no control | |
261 */ | |
262 protected abstract Control createControl(Composite parent); | |
263 | |
264 /** | |
265 * Creates the control for this cell editor under the given parent control. | |
266 * | |
267 * @param parent | |
268 * the parent control | |
269 * @since 2.1 | |
270 */ | |
271 public void create(Composite parent) { | |
272 Assert.isTrue(control is null); | |
273 control = createControl(parent); | |
274 // See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work | |
275 // Control is created with getVisible()is true by default. | |
276 // This causes composite.setFocus() to work incorrectly. | |
277 // The cell editor's control grabs focus instead, even if it is not | |
278 // active. | |
279 // Make the control invisible here by default. | |
280 deactivate(); | |
281 } | |
282 | |
283 /** | |
284 * Hides this cell editor's control. Does nothing if this cell editor is not | |
285 * visible. | |
286 */ | |
287 public void deactivate() { | |
288 if (control !is null && !control.isDisposed()) { | |
289 control.setVisible(false); | |
290 } | |
291 } | |
292 | |
293 /** | |
294 * Disposes of this cell editor and frees any associated SWT resources. | |
295 */ | |
296 public void dispose() { | |
297 if (control !is null && !control.isDisposed()) { | |
298 control.dispose(); | |
299 } | |
300 control = null; | |
301 } | |
302 | |
303 /** | |
304 * Returns this cell editor's value. | |
305 * <p> | |
306 * This framework method must be implemented by concrete subclasses. | |
307 * </p> | |
308 * | |
309 * @return the value of this cell editor | |
310 * @see #getValue | |
311 */ | |
312 protected abstract Object doGetValue(); | |
313 | |
314 /** | |
315 * Sets the focus to the cell editor's control. | |
316 * <p> | |
317 * This framework method must be implemented by concrete subclasses. | |
318 * </p> | |
319 * | |
320 * @see #setFocus | |
321 */ | |
322 protected abstract void doSetFocus(); | |
323 | |
324 /** | |
325 * Sets this cell editor's value. | |
326 * <p> | |
327 * This framework method must be implemented by concrete subclasses. | |
328 * </p> | |
329 * | |
330 * @param value | |
331 * the value of this cell editor | |
332 * @see #setValue | |
333 */ | |
334 protected abstract void doSetValue(Object value); | |
335 | |
336 /** | |
337 * Notifies all registered cell editor listeners of an apply event. Only | |
338 * listeners registered at the time this method is called are notified. | |
339 * | |
340 * @see ICellEditorListener#applyEditorValue | |
341 */ | |
342 protected void fireApplyEditorValue() { | |
343 Object[] array = listeners.getListeners(); | |
344 for (int i = 0; i < array.length; i++) { | |
345 SafeRunnable.run(new class(cast(ICellEditorListener) array[i]) SafeRunnable { | |
346 ICellEditorListener l; | |
347 this(ICellEditorListener a){ | |
348 l = a; | |
349 } | |
350 public void run() { | |
351 l.applyEditorValue(); | |
352 } | |
353 }); | |
354 } | |
355 } | |
356 | |
357 /** | |
358 * Notifies all registered cell editor listeners that editing has been | |
359 * canceled. | |
360 * | |
361 * @see ICellEditorListener#cancelEditor | |
362 */ | |
363 protected void fireCancelEditor() { | |
364 Object[] array = listeners.getListeners(); | |
365 for (int i = 0; i < array.length; i++) { | |
366 SafeRunnable.run(new class(cast(ICellEditorListener) array[i]) SafeRunnable { | |
367 ICellEditorListener l; | |
368 this(ICellEditorListener a){ | |
369 l = a; | |
370 } | |
371 public void run() { | |
372 l.cancelEditor(); | |
373 } | |
374 }); | |
375 } | |
376 } | |
377 | |
378 /** | |
379 * Notifies all registered cell editor listeners of a value change. | |
380 * | |
381 * @param oldValidState | |
382 * the valid state before the end user changed the value | |
383 * @param newValidState | |
384 * the current valid state | |
385 * @see ICellEditorListener#editorValueChanged | |
386 */ | |
387 protected void fireEditorValueChanged(bool oldValidState, | |
388 bool newValidState) { | |
389 Object[] array = listeners.getListeners(); | |
390 for (int i = 0; i < array.length; i++) { | |
391 SafeRunnable.run(new class(newValidState,oldValidState,cast(ICellEditorListener) array[i]) SafeRunnable { | |
392 bool newValidState_; | |
393 bool oldValidState_; | |
394 ICellEditorListener l; | |
395 this(bool a, bool b, ICellEditorListener c){ | |
396 newValidState_=a; | |
397 oldValidState_=b; | |
398 l = c; | |
399 } | |
400 public void run() { | |
401 l.editorValueChanged(oldValidState_, newValidState_); | |
402 } | |
403 }); | |
404 } | |
405 } | |
406 | |
407 /** | |
408 * Notifies all registered property listeners of an enablement change. | |
409 * | |
410 * @param actionId | |
411 * the id indicating what action's enablement has changed. | |
412 */ | |
413 protected void fireEnablementChanged(String actionId) { | |
414 Object[] array = propertyChangeListeners.getListeners(); | |
415 for (int i = 0; i < array.length; i++) { | |
416 SafeRunnable.run(new class(actionId,cast(IPropertyChangeListener) array[i]) SafeRunnable { | |
417 String actionId_; | |
418 IPropertyChangeListener l; | |
419 this(String a, IPropertyChangeListener b){ | |
420 actionId_=a; | |
421 l = b; | |
422 } | |
423 public void run() { | |
424 l.propertyChange(new PropertyChangeEvent(this, actionId_, | |
425 null, null)); | |
426 } | |
427 }); | |
428 } | |
429 } | |
430 | |
431 /** | |
432 * Sets the style bits for this cell editor. | |
433 * | |
434 * @param style | |
435 * the SWT style bits for this cell editor | |
436 * @since 2.1 | |
437 */ | |
438 public void setStyle(int style) { | |
439 this.style = style; | |
440 } | |
441 | |
442 /** | |
443 * Returns the style bits for this cell editor. | |
444 * | |
445 * @return the style for this cell editor | |
446 * @since 2.1 | |
447 */ | |
448 public int getStyle() { | |
449 return style; | |
450 } | |
451 | |
452 /** | |
453 * Returns the control used to implement this cell editor. | |
454 * | |
455 * @return the control, or <code>null</code> if this cell editor has no | |
456 * control | |
457 */ | |
458 public Control getControl() { | |
459 return control; | |
460 } | |
461 | |
462 /** | |
463 * Returns the current error message for this cell editor. | |
464 * | |
465 * @return the error message if the cell editor is in an invalid state, and | |
466 * <code>null</code> if the cell editor is valid | |
467 */ | |
468 public String getErrorMessage() { | |
469 return errorMessage; | |
470 } | |
471 | |
472 /** | |
473 * Returns a layout data object for this cell editor. This is called each | |
474 * time the cell editor is activated and controls the layout of the SWT | |
475 * table editor. | |
476 * <p> | |
477 * The default implementation of this method sets the minimum width to the | |
478 * control's preferred width. Subclasses may extend or reimplement. | |
479 * </p> | |
480 * | |
481 * @return the layout data object | |
482 */ | |
483 public LayoutData getLayoutData() { | |
484 LayoutData result = new LayoutData(); | |
485 Control control = getControl(); | |
486 if (control !is null) { | |
487 result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, | |
488 true).x; | |
489 } | |
490 return result; | |
491 } | |
492 | |
493 /** | |
494 * Returns the input validator for this cell editor. | |
495 * | |
496 * @return the input validator, or <code>null</code> if none | |
497 */ | |
498 public ICellEditorValidator getValidator() { | |
499 return validator; | |
500 } | |
501 | |
502 /** | |
503 * Returns this cell editor's value provided that it has a valid one. | |
504 * | |
505 * @return the value of this cell editor, or <code>null</code> if the cell | |
506 * editor does not contain a valid value | |
507 */ | |
508 public final Object getValue() { | |
509 if (!valid) { | |
510 return null; | |
511 } | |
512 | |
513 return doGetValue(); | |
514 } | |
515 | |
516 /** | |
517 * Returns whether this cell editor is activated. | |
518 * | |
519 * @return <code>true</code> if this cell editor's control is currently | |
520 * activated, and <code>false</code> if not activated | |
521 */ | |
522 public bool isActivated() { | |
523 // Use the state of the visible style bit (getVisible()) rather than the | |
524 // window's actual visibility (isVisible()) to get correct handling when | |
525 // an ancestor control goes invisible, see bug 85331. | |
526 return control !is null && control.getVisible(); | |
527 } | |
528 | |
529 /** | |
530 * Returns <code>true</code> if this cell editor is able to perform the | |
531 * copy action. | |
532 * <p> | |
533 * This default implementation always returns <code>false</code>. | |
534 * </p> | |
535 * <p> | |
536 * Subclasses may override | |
537 * </p> | |
538 * | |
539 * @return <code>true</code> if copy is possible, <code>false</code> | |
540 * otherwise | |
541 */ | |
542 public bool isCopyEnabled() { | |
543 return false; | |
544 } | |
545 | |
546 /** | |
547 * Returns whether the given value is valid for this cell editor. This cell | |
548 * editor's validator (if any) makes the actual determination. | |
549 * | |
550 * @param value | |
551 * the value to check for | |
552 * | |
553 * @return <code>true</code> if the value is valid, and <code>false</code> | |
554 * if invalid | |
555 */ | |
556 protected bool isCorrect(Object value) { | |
557 errorMessage = null; | |
558 if (validator is null) { | |
559 return true; | |
560 } | |
561 | |
562 errorMessage = validator.isValid(value); | |
563 return (errorMessage is null || errorMessage.equals(""));//$NON-NLS-1$ | |
564 } | |
565 | |
566 /** | |
567 * Returns <code>true</code> if this cell editor is able to perform the | |
568 * cut action. | |
569 * <p> | |
570 * This default implementation always returns <code>false</code>. | |
571 * </p> | |
572 * <p> | |
573 * Subclasses may override | |
574 * </p> | |
575 * | |
576 * @return <code>true</code> if cut is possible, <code>false</code> | |
577 * otherwise | |
578 */ | |
579 public bool isCutEnabled() { | |
580 return false; | |
581 } | |
582 | |
583 /** | |
584 * Returns <code>true</code> if this cell editor is able to perform the | |
585 * delete action. | |
586 * <p> | |
587 * This default implementation always returns <code>false</code>. | |
588 * </p> | |
589 * <p> | |
590 * Subclasses may override | |
591 * </p> | |
592 * | |
593 * @return <code>true</code> if delete is possible, <code>false</code> | |
594 * otherwise | |
595 */ | |
596 public bool isDeleteEnabled() { | |
597 return false; | |
598 } | |
599 | |
600 /** | |
601 * Returns whether the value of this cell editor has changed since the last | |
602 * call to <code>setValue</code>. | |
603 * | |
604 * @return <code>true</code> if the value has changed, and | |
605 * <code>false</code> if unchanged | |
606 */ | |
607 public bool isDirty() { | |
608 return dirty; | |
609 } | |
610 | |
611 /** | |
612 * Marks this cell editor as dirty. | |
613 * | |
614 * @since 2.1 | |
615 */ | |
616 protected void markDirty() { | |
617 dirty = true; | |
618 } | |
619 | |
620 /** | |
621 * Returns <code>true</code> if this cell editor is able to perform the | |
622 * find action. | |
623 * <p> | |
624 * This default implementation always returns <code>false</code>. | |
625 * </p> | |
626 * <p> | |
627 * Subclasses may override | |
628 * </p> | |
629 * | |
630 * @return <code>true</code> if find is possible, <code>false</code> | |
631 * otherwise | |
632 */ | |
633 public bool isFindEnabled() { | |
634 return false; | |
635 } | |
636 | |
637 /** | |
638 * Returns <code>true</code> if this cell editor is able to perform the | |
639 * paste action. | |
640 * <p> | |
641 * This default implementation always returns <code>false</code>. | |
642 * </p> | |
643 * <p> | |
644 * Subclasses may override | |
645 * </p> | |
646 * | |
647 * @return <code>true</code> if paste is possible, <code>false</code> | |
648 * otherwise | |
649 */ | |
650 public bool isPasteEnabled() { | |
651 return false; | |
652 } | |
653 | |
654 /** | |
655 * Returns <code>true</code> if this cell editor is able to perform the | |
656 * redo action. | |
657 * <p> | |
658 * This default implementation always returns <code>false</code>. | |
659 * </p> | |
660 * <p> | |
661 * Subclasses may override | |
662 * </p> | |
663 * | |
664 * @return <code>true</code> if redo is possible, <code>false</code> | |
665 * otherwise | |
666 */ | |
667 public bool isRedoEnabled() { | |
668 return false; | |
669 } | |
670 | |
671 /** | |
672 * Returns <code>true</code> if this cell editor is able to perform the | |
673 * select all action. | |
674 * <p> | |
675 * This default implementation always returns <code>false</code>. | |
676 * </p> | |
677 * <p> | |
678 * Subclasses may override | |
679 * </p> | |
680 * | |
681 * @return <code>true</code> if select all is possible, <code>false</code> | |
682 * otherwise | |
683 */ | |
684 public bool isSelectAllEnabled() { | |
685 return false; | |
686 } | |
687 | |
688 /** | |
689 * Returns <code>true</code> if this cell editor is able to perform the | |
690 * undo action. | |
691 * <p> | |
692 * This default implementation always returns <code>false</code>. | |
693 * </p> | |
694 * <p> | |
695 * Subclasses may override | |
696 * </p> | |
697 * | |
698 * @return <code>true</code> if undo is possible, <code>false</code> | |
699 * otherwise | |
700 */ | |
701 public bool isUndoEnabled() { | |
702 return false; | |
703 } | |
704 | |
705 /** | |
706 * Returns whether this cell editor has a valid value. The default value is | |
707 * false. | |
708 * | |
709 * @return <code>true</code> if the value is valid, and <code>false</code> | |
710 * if invalid | |
711 * | |
712 * @see #setValueValid(bool) | |
713 */ | |
714 public bool isValueValid() { | |
715 return valid; | |
716 } | |
717 | |
718 /** | |
719 * Processes a key release event that occurred in this cell editor. | |
720 * <p> | |
721 * The default implementation of this framework method cancels editing when | |
722 * the ESC key is pressed. When the RETURN key is pressed the current value | |
723 * is applied and the cell editor deactivates. Subclasses should call this | |
724 * method at appropriate times. Subclasses may also extend or reimplement. | |
725 * </p> | |
726 * | |
727 * @param keyEvent | |
728 * the key event | |
729 */ | |
730 protected void keyReleaseOccured(KeyEvent keyEvent) { | |
731 if (keyEvent.character is '\u001b') { // Escape character | |
732 fireCancelEditor(); | |
733 } else if (keyEvent.character is '\r') { // Return key | |
734 fireApplyEditorValue(); | |
735 deactivate(); | |
736 } | |
737 } | |
738 | |
739 /** | |
740 * Processes a focus lost event that occurred in this cell editor. | |
741 * <p> | |
742 * The default implementation of this framework method applies the current | |
743 * value and deactivates the cell editor. Subclasses should call this method | |
744 * at appropriate times. Subclasses may also extend or reimplement. | |
745 * </p> | |
746 */ | |
747 protected void focusLost() { | |
748 if (isActivated()) { | |
749 fireApplyEditorValue(); | |
750 deactivate(); | |
751 } | |
752 } | |
753 | |
754 /** | |
755 * Performs the copy action. This default implementation does nothing. | |
756 * <p> | |
757 * Subclasses may override | |
758 * </p> | |
759 */ | |
760 public void performCopy() { | |
761 } | |
762 | |
763 /** | |
764 * Performs the cut action. This default implementation does nothing. | |
765 * <p> | |
766 * Subclasses may override | |
767 * </p> | |
768 */ | |
769 public void performCut() { | |
770 } | |
771 | |
772 /** | |
773 * Performs the delete action. This default implementation does nothing. | |
774 * <p> | |
775 * Subclasses may override | |
776 * </p> | |
777 */ | |
778 public void performDelete() { | |
779 } | |
780 | |
781 /** | |
782 * Performs the find action. This default implementation does nothing. | |
783 * <p> | |
784 * Subclasses may override | |
785 * </p> | |
786 */ | |
787 public void performFind() { | |
788 } | |
789 | |
790 /** | |
791 * Performs the paste action. This default implementation does nothing. | |
792 * <p> | |
793 * Subclasses may override | |
794 * </p> | |
795 */ | |
796 public void performPaste() { | |
797 } | |
798 | |
799 /** | |
800 * Performs the redo action. This default implementation does nothing. | |
801 * <p> | |
802 * Subclasses may override | |
803 * </p> | |
804 */ | |
805 public void performRedo() { | |
806 } | |
807 | |
808 /** | |
809 * Performs the select all action. This default implementation does nothing. | |
810 * <p> | |
811 * Subclasses may override | |
812 * </p> | |
813 */ | |
814 public void performSelectAll() { | |
815 } | |
816 | |
817 /** | |
818 * Performs the undo action. This default implementation does nothing. | |
819 * <p> | |
820 * Subclasses may override | |
821 * </p> | |
822 */ | |
823 public void performUndo() { | |
824 } | |
825 | |
826 /** | |
827 * Removes the given listener from this cell editor. Has no affect if an | |
828 * identical listener is not registered. | |
829 * | |
830 * @param listener | |
831 * a cell editor listener | |
832 */ | |
833 public void removeListener(ICellEditorListener listener) { | |
834 listeners.remove(cast(Object)listener); | |
835 } | |
836 | |
837 /** | |
838 * Removes the given property change listener from this cell editor. Has no | |
839 * affect if an identical property change listener is not registered. | |
840 * | |
841 * @param listener | |
842 * a property change listener | |
843 */ | |
844 public void removePropertyChangeListener(IPropertyChangeListener listener) { | |
845 propertyChangeListeners.remove(cast(Object)listener); | |
846 } | |
847 | |
848 /** | |
849 * Sets or clears the current error message for this cell editor. | |
850 * <p> | |
851 * No formatting is done here, the message to be set is expected to be fully | |
852 * formatted before being passed in. | |
853 * </p> | |
854 * | |
855 * @param message | |
856 * the error message, or <code>null</code> to clear | |
857 */ | |
858 protected void setErrorMessage(String message) { | |
859 errorMessage = message; | |
860 } | |
861 | |
862 /** | |
863 * Sets the focus to the cell editor's control. | |
864 */ | |
865 public void setFocus() { | |
866 doSetFocus(); | |
867 } | |
868 | |
869 /** | |
870 * Sets the input validator for this cell editor. | |
871 * | |
872 * @param validator | |
873 * the input validator, or <code>null</code> if none | |
874 */ | |
875 public void setValidator(ICellEditorValidator validator) { | |
876 this.validator = validator; | |
877 } | |
878 | |
879 /** | |
880 * Sets this cell editor's value. | |
881 * | |
882 * @param value | |
883 * the value of this cell editor | |
884 */ | |
885 public final void setValue(Object value) { | |
886 valid = isCorrect(value); | |
887 dirty = false; | |
888 doSetValue(value); | |
889 } | |
890 | |
891 /** | |
892 * Sets the valid state of this cell editor. The default value is false. | |
893 * Subclasses should call this method on construction. | |
894 * | |
895 * @param valid | |
896 * <code>true</code> if the current value is valid, and | |
897 * <code>false</code> if invalid | |
898 * | |
899 * @see #isValueValid | |
900 */ | |
901 protected void setValueValid(bool valid) { | |
902 this.valid = valid; | |
903 } | |
904 | |
905 /** | |
906 * The value has changed. Updates the valid state flag, marks this cell | |
907 * editor as dirty, and notifies all registered cell editor listeners of a | |
908 * value change. | |
909 * | |
910 * @param oldValidState | |
911 * the valid state before the end user changed the value | |
912 * @param newValidState | |
913 * the current valid state | |
914 * @see ICellEditorListener#editorValueChanged | |
915 */ | |
916 protected void valueChanged(bool oldValidState, bool newValidState) { | |
917 valid = newValidState; | |
918 dirty = true; | |
919 fireEditorValueChanged(oldValidState, newValidState); | |
920 } | |
921 | |
922 /** | |
923 * Activate the editor but also inform the editor which event triggered its | |
924 * activation. <b>The default implementation simply calls | |
925 * {@link #activate()}</b> | |
926 * | |
927 * @param activationEvent | |
928 * the editor activation event | |
929 * @since 3.3 | |
930 */ | |
931 public void activate(ColumnViewerEditorActivationEvent activationEvent) { | |
932 activate(); | |
933 } | |
934 | |
935 /** | |
936 * The default implementation of this method returns true. Subclasses that | |
937 * hook their own focus listener should override this method and return | |
938 * false. See also bug 58777. | |
939 * | |
940 * @return <code>true</code> to indicate that a focus listener has to be | |
941 * attached | |
942 * @since 3.4 | |
943 */ | |
944 protected bool dependsOnExternalFocusListener() { | |
945 return true; | |
946 } | |
947 package bool dependsOnExternalFocusListener_package() { | |
948 return dependsOnExternalFocusListener(); | |
949 } | |
950 | |
951 /** | |
952 * @param event | |
953 * deactivation event | |
954 * @since 3.4 | |
955 * | |
956 */ | |
957 protected void deactivate(ColumnViewerEditorDeactivationEvent event) { | |
958 deactivate(); | |
959 } | |
960 package void deactivate_package(ColumnViewerEditorDeactivationEvent event) { | |
961 deactivate(event); | |
962 } | |
963 | |
964 /** | |
965 * Returns the duration, in milliseconds, between the mouse button click | |
966 * that activates the cell editor and a subsequent mouse button click that | |
967 * will be considered a <em>double click</em> on the underlying control. | |
968 * Clients may override, in particular, clients can return 0 to denote that | |
969 * two subsequent mouse clicks in a cell should not be interpreted as a | |
970 * double click. | |
971 * | |
972 * @return the timeout or <code>0</code> | |
973 * @since 3.4 | |
974 */ | |
975 protected int getDoubleClickTimeout() { | |
976 return Display.getCurrent().getDoubleClickTime(); | |
977 } | |
978 package int getDoubleClickTimeout_package() { | |
979 return getDoubleClickTimeout(); | |
980 } | |
981 } |