Class CellEditor
- java.lang.Object
-
- org.eclipse.jface.viewers.CellEditor
-
- Direct Known Subclasses:
CheckboxCellEditor,ComboBoxCellEditor,ComboBoxViewerCellEditor,DialogCellEditor,TextCellEditor
public abstract class CellEditor extends Object
Abstract base class for cell editors. Implements property change listener handling, and SWT window management.Subclasses implement particular kinds of cell editors. This package contains various specialized cell editors:
TextCellEditor- for simple text stringsColorCellEditor- for colorsComboBoxCellEditor- value selected from drop-down combo boxCheckboxCellEditor- boolean valued checkboxDialogCellEditor- value from arbitrary dialog
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCellEditor.LayoutDataStruct-like layout data for cell editors, with reasonable defaults for all fields.
-
Field Summary
Fields Modifier and Type Field Description static StringCOPYProperty name for the copy actionstatic StringCUTProperty name for the cut actionstatic StringDELETEProperty name for the delete actionstatic StringFINDProperty name for the find actionstatic StringPASTEProperty name for the paste actionstatic StringREDOProperty name for the redo actionstatic StringSELECT_ALLProperty name for the select all actionstatic StringUNDOProperty name for the undo action
-
Constructor Summary
Constructors Modifier Constructor Description protectedCellEditor()Creates a new cell editor with no control The cell editor has no cell validator.protectedCellEditor(Composite parent)Creates a new cell editor under the given parent control.protectedCellEditor(Composite parent, int style)Creates a new cell editor under the given parent control.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidactivate()Activates this cell editor.voidactivate(ColumnViewerEditorActivationEvent activationEvent)Activate the editor but also inform the editor which event triggered its activation.voidaddListener(ICellEditorListener listener)Adds a listener to this cell editor.voidaddPropertyChangeListener(IPropertyChangeListener listener)Adds a property change listener to this cell editor.voidcreate(Composite parent)Creates the control for this cell editor under the given parent control.protected abstract ControlcreateControl(Composite parent)Creates the control for this cell editor under the given parent control.voiddeactivate()Hides this cell editor's control.protected voiddeactivate(ColumnViewerEditorDeactivationEvent event)protected booleandependsOnExternalFocusListener()The default implementation of this method returns true.voiddispose()Disposes of this cell editor and frees any associated SWT resources.protected abstract ObjectdoGetValue()Returns this cell editor's value.protected abstract voiddoSetFocus()Sets the focus to the cell editor's control.protected abstract voiddoSetValue(Object value)Sets this cell editor's value.protected voidfireApplyEditorValue()Notifies all registered cell editor listeners of an apply event.protected voidfireCancelEditor()Notifies all registered cell editor listeners that editing has been canceled.protected voidfireEditorValueChanged(boolean oldValidState, boolean newValidState)Notifies all registered cell editor listeners of a value change.protected voidfireEnablementChanged(String actionId)Notifies all registered property listeners of an enablement change.protected voidfocusLost()Processes a focus lost event that occurred in this cell editor.ControlgetControl()Returns the control used to implement this cell editor.protected intgetDoubleClickTimeout()Returns the duration, in milliseconds, between the mouse button click that activates the cell editor and a subsequent mouse button click that will be considered a double click on the underlying control.StringgetErrorMessage()Returns the current error message for this cell editor.CellEditor.LayoutDatagetLayoutData()Returns a layout data object for this cell editor.intgetStyle()Returns the style bits for this cell editor.ICellEditorValidatorgetValidator()Returns the input validator for this cell editor.ObjectgetValue()Returns this cell editor's value provided that it has a valid one.booleanisActivated()Returns whether this cell editor is activated.booleanisCopyEnabled()Returnstrueif this cell editor is able to perform the copy action.protected booleanisCorrect(Object value)Returns whether the given value is valid for this cell editor.booleanisCutEnabled()Returnstrueif this cell editor is able to perform the cut action.booleanisDeleteEnabled()Returnstrueif this cell editor is able to perform the delete action.booleanisDirty()Returns whether the value of this cell editor has changed since the last call tosetValue.booleanisFindEnabled()Returnstrueif this cell editor is able to perform the find action.booleanisPasteEnabled()Returnstrueif this cell editor is able to perform the paste action.booleanisRedoEnabled()Returnstrueif this cell editor is able to perform the redo action.booleanisSelectAllEnabled()Returnstrueif this cell editor is able to perform the select all action.booleanisUndoEnabled()Returnstrueif this cell editor is able to perform the undo action.booleanisValueValid()Returns whether this cell editor has a valid value.protected voidkeyReleaseOccured(KeyEvent keyEvent)Processes a key release event that occurred in this cell editor.protected voidmarkDirty()Marks this cell editor as dirty.voidperformCopy()Performs the copy action.voidperformCut()Performs the cut action.voidperformDelete()Performs the delete action.voidperformFind()Performs the find action.voidperformPaste()Performs the paste action.voidperformRedo()Performs the redo action.voidperformSelectAll()Performs the select all action.voidperformUndo()Performs the undo action.voidremoveListener(ICellEditorListener listener)Removes the given listener from this cell editor.voidremovePropertyChangeListener(IPropertyChangeListener listener)Removes the given property change listener from this cell editor.protected voidsetErrorMessage(String message)Sets or clears the current error message for this cell editor.voidsetFocus()Sets the focus to the cell editor's control.voidsetStyle(int style)Sets the style bits for this cell editor.voidsetValidator(ICellEditorValidator validator)Sets the input validator for this cell editor.voidsetValue(Object value)Sets this cell editor's value.protected voidsetValueValid(boolean valid)Sets the valid state of this cell editor.protected voidvalueChanged(boolean oldValidState, boolean newValidState)The value has changed.
-
-
-
Field Detail
-
COPY
public static final String COPY
Property name for the copy action- See Also:
- Constant Field Values
-
CUT
public static final String CUT
Property name for the cut action- See Also:
- Constant Field Values
-
DELETE
public static final String DELETE
Property name for the delete action- See Also:
- Constant Field Values
-
FIND
public static final String FIND
Property name for the find action- See Also:
- Constant Field Values
-
PASTE
public static final String PASTE
Property name for the paste action- See Also:
- Constant Field Values
-
REDO
public static final String REDO
Property name for the redo action- See Also:
- Constant Field Values
-
SELECT_ALL
public static final String SELECT_ALL
Property name for the select all action- See Also:
- Constant Field Values
-
UNDO
public static final String UNDO
Property name for the undo action- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CellEditor
protected CellEditor()
Creates a new cell editor with no control The cell editor has no cell validator.- Since:
- 2.1
-
CellEditor
protected CellEditor(Composite parent)
Creates a new cell editor under the given parent control. The cell editor has no cell validator.- Parameters:
parent- the parent control
-
CellEditor
protected CellEditor(Composite parent, int style)
Creates a new cell editor under the given parent control. The cell editor has no cell validator.- Parameters:
parent- the parent controlstyle- the style bits- Since:
- 2.1
-
-
Method Detail
-
activate
public void activate()
Activates this cell editor.The default implementation of this framework method does nothing. Subclasses may reimplement.
-
addListener
public void addListener(ICellEditorListener listener)
Adds a listener to this cell editor. Has no effect if an identical listener is already registered.- Parameters:
listener- a cell editor listener
-
addPropertyChangeListener
public void addPropertyChangeListener(IPropertyChangeListener listener)
Adds a property change listener to this cell editor. Has no effect if an identical property change listener is already registered.- Parameters:
listener- a property change listener
-
createControl
protected abstract Control createControl(Composite parent)
Creates the control for this cell editor under the given parent control.This framework method must be implemented by concrete subclasses.
- Parameters:
parent- the parent control- Returns:
- the new control, or
nullif this cell editor has no control
-
create
public void create(Composite parent)
Creates the control for this cell editor under the given parent control.- Parameters:
parent- the parent control- Since:
- 2.1
-
deactivate
public void deactivate()
Hides this cell editor's control. Does nothing if this cell editor is not visible.
-
dispose
public void dispose()
Disposes of this cell editor and frees any associated SWT resources.
-
doGetValue
protected abstract Object doGetValue()
Returns this cell editor's value.This framework method must be implemented by concrete subclasses.
- Returns:
- the value of this cell editor
- See Also:
getValue()
-
doSetFocus
protected abstract void doSetFocus()
Sets the focus to the cell editor's control.This framework method must be implemented by concrete subclasses.
- See Also:
setFocus()
-
doSetValue
protected abstract void doSetValue(Object value)
Sets this cell editor's value.This framework method must be implemented by concrete subclasses.
- Parameters:
value- the value of this cell editor- See Also:
setValue(java.lang.Object)
-
fireApplyEditorValue
protected void fireApplyEditorValue()
Notifies all registered cell editor listeners of an apply event. Only listeners registered at the time this method is called are notified.- See Also:
ICellEditorListener.applyEditorValue()
-
fireCancelEditor
protected void fireCancelEditor()
Notifies all registered cell editor listeners that editing has been canceled.- See Also:
ICellEditorListener.cancelEditor()
-
fireEditorValueChanged
protected void fireEditorValueChanged(boolean oldValidState, boolean newValidState)Notifies all registered cell editor listeners of a value change.- Parameters:
oldValidState- the valid state before the end user changed the valuenewValidState- the current valid state- See Also:
ICellEditorListener.editorValueChanged(boolean, boolean)
-
fireEnablementChanged
protected void fireEnablementChanged(String actionId)
Notifies all registered property listeners of an enablement change.- Parameters:
actionId- the id indicating what action's enablement has changed.
-
setStyle
public void setStyle(int style)
Sets the style bits for this cell editor.- Parameters:
style- the SWT style bits for this cell editor- Since:
- 2.1
-
getStyle
public int getStyle()
Returns the style bits for this cell editor.- Returns:
- the style for this cell editor
- Since:
- 2.1
-
getControl
public Control getControl()
Returns the control used to implement this cell editor.- Returns:
- the control, or
nullif this cell editor has no control
-
getErrorMessage
public String getErrorMessage()
Returns the current error message for this cell editor.- Returns:
- the error message if the cell editor is in an invalid state, and
nullif the cell editor is valid
-
getLayoutData
public CellEditor.LayoutData getLayoutData()
Returns a layout data object for this cell editor. This is called each time the cell editor is activated and controls the layout of the SWT table editor.The default implementation of this method sets the minimum width to the control's preferred width. Subclasses may extend or reimplement.
- Returns:
- the layout data object
-
getValidator
public ICellEditorValidator getValidator()
Returns the input validator for this cell editor.- Returns:
- the input validator, or
nullif none
-
getValue
public final Object getValue()
Returns this cell editor's value provided that it has a valid one.- Returns:
- the value of this cell editor, or
nullif the cell editor does not contain a valid value
-
isActivated
public boolean isActivated()
Returns whether this cell editor is activated.- Returns:
trueif this cell editor's control is currently activated, andfalseif not activated
-
isCopyEnabled
public boolean isCopyEnabled()
Returnstrueif this cell editor is able to perform the copy action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif copy is possible,falseotherwise
-
isCorrect
protected boolean isCorrect(Object value)
Returns whether the given value is valid for this cell editor. This cell editor's validator (if any) makes the actual determination.- Parameters:
value- the value to check for- Returns:
trueif the value is valid, andfalseif invalid
-
isCutEnabled
public boolean isCutEnabled()
Returnstrueif this cell editor is able to perform the cut action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif cut is possible,falseotherwise
-
isDeleteEnabled
public boolean isDeleteEnabled()
Returnstrueif this cell editor is able to perform the delete action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif delete is possible,falseotherwise
-
isDirty
public boolean isDirty()
Returns whether the value of this cell editor has changed since the last call tosetValue.- Returns:
trueif the value has changed, andfalseif unchanged
-
markDirty
protected void markDirty()
Marks this cell editor as dirty.- Since:
- 2.1
-
isFindEnabled
public boolean isFindEnabled()
Returnstrueif this cell editor is able to perform the find action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif find is possible,falseotherwise
-
isPasteEnabled
public boolean isPasteEnabled()
Returnstrueif this cell editor is able to perform the paste action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif paste is possible,falseotherwise
-
isRedoEnabled
public boolean isRedoEnabled()
Returnstrueif this cell editor is able to perform the redo action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif redo is possible,falseotherwise
-
isSelectAllEnabled
public boolean isSelectAllEnabled()
Returnstrueif this cell editor is able to perform the select all action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif select all is possible,falseotherwise
-
isUndoEnabled
public boolean isUndoEnabled()
Returnstrueif this cell editor is able to perform the undo action.This default implementation always returns
false.Subclasses may override
- Returns:
trueif undo is possible,falseotherwise
-
isValueValid
public boolean isValueValid()
Returns whether this cell editor has a valid value. The default value is false.- Returns:
trueif the value is valid, andfalseif invalid- See Also:
setValueValid(boolean)
-
keyReleaseOccured
protected void keyReleaseOccured(KeyEvent keyEvent)
Processes a key release event that occurred in this cell editor.The default implementation of this framework method cancels editing when the ESC key is pressed. When the RETURN key is pressed the current value is applied and the cell editor deactivates. Subclasses should call this method at appropriate times. Subclasses may also extend or reimplement.
- Parameters:
keyEvent- the key event
-
focusLost
protected void focusLost()
Processes a focus lost event that occurred in this cell editor.The default implementation of this framework method applies the current value and deactivates the cell editor. Subclasses should call this method at appropriate times. Subclasses may also extend or reimplement.
-
performCopy
public void performCopy()
Performs the copy action. This default implementation does nothing.Subclasses may override
-
performCut
public void performCut()
Performs the cut action. This default implementation does nothing.Subclasses may override
-
performDelete
public void performDelete()
Performs the delete action. This default implementation does nothing.Subclasses may override
-
performFind
public void performFind()
Performs the find action. This default implementation does nothing.Subclasses may override
-
performPaste
public void performPaste()
Performs the paste action. This default implementation does nothing.Subclasses may override
-
performRedo
public void performRedo()
Performs the redo action. This default implementation does nothing.Subclasses may override
-
performSelectAll
public void performSelectAll()
Performs the select all action. This default implementation does nothing.Subclasses may override
-
performUndo
public void performUndo()
Performs the undo action. This default implementation does nothing.Subclasses may override
-
removeListener
public void removeListener(ICellEditorListener listener)
Removes the given listener from this cell editor. Has no effect if an identical listener is not registered.- Parameters:
listener- a cell editor listener
-
removePropertyChangeListener
public void removePropertyChangeListener(IPropertyChangeListener listener)
Removes the given property change listener from this cell editor. Has no effect if an identical property change listener is not registered.- Parameters:
listener- a property change listener
-
setErrorMessage
protected void setErrorMessage(String message)
Sets or clears the current error message for this cell editor.No formatting is done here, the message to be set is expected to be fully formatted before being passed in.
- Parameters:
message- the error message, ornullto clear
-
setFocus
public void setFocus()
Sets the focus to the cell editor's control.
-
setValidator
public void setValidator(ICellEditorValidator validator)
Sets the input validator for this cell editor.- Parameters:
validator- the input validator, ornullif none
-
setValue
public final void setValue(Object value)
Sets this cell editor's value.- Parameters:
value- the value of this cell editor
-
setValueValid
protected void setValueValid(boolean valid)
Sets the valid state of this cell editor. The default value is false. Subclasses should call this method on construction.- Parameters:
valid-trueif the current value is valid, andfalseif invalid- See Also:
isValueValid()
-
valueChanged
protected void valueChanged(boolean oldValidState, boolean newValidState)The value has changed. Updates the valid state flag, marks this cell editor as dirty, and notifies all registered cell editor listeners of a value change.- Parameters:
oldValidState- the valid state before the end user changed the valuenewValidState- the current valid state- See Also:
ICellEditorListener.editorValueChanged(boolean, boolean)
-
activate
public void activate(ColumnViewerEditorActivationEvent activationEvent)
Activate the editor but also inform the editor which event triggered its activation. The default implementation simply callsactivate()- Parameters:
activationEvent- the editor activation event- Since:
- 3.3
-
dependsOnExternalFocusListener
protected boolean dependsOnExternalFocusListener()
The default implementation of this method returns true. Subclasses that hook their own focus listener should override this method and return false. See also bug 58777.- Returns:
trueto indicate that a focus listener has to be attached- Since:
- 3.4
-
deactivate
protected void deactivate(ColumnViewerEditorDeactivationEvent event)
- Parameters:
event- deactivation event- Since:
- 3.4
-
getDoubleClickTimeout
protected int getDoubleClickTimeout()
Returns the duration, in milliseconds, between the mouse button click that activates the cell editor and a subsequent mouse button click that will be considered a double click on the underlying control. Clients may override, in particular, clients can return 0 to denote that two subsequent mouse clicks in a cell should not be interpreted as a double click.- Returns:
- the timeout or
0 - Since:
- 3.4
-
-