Class AbstractCellEditor
- All Implemented Interfaces:
ICellEditor
- Direct Known Subclasses:
CDateTimeCellEditor,CheckBoxCellEditor,ComboBoxCellEditor,DateCellEditor,RichTextCellEditor,TableCellEditor,TextCellEditor
ICellEditor that wraps SWT controls to be
NatTable editors. It is used to hide several default behaviour and styling
from concrete editor implementations, so implementing an editor can focus on
the editor specific handling instead of NatTable default behaviour.
Note that most of the member variables defined will be set on activating the editor. So you can not access those variables expecting reasonable values prior activation. This makes it possible to use the same editor instance for several cells instead of creating a new one for every cell.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classFocusListenerthat tries to commit if the focus is lost.protected classTraverseListenerthat will try to commit and close this editor with the current value, prior to proceed the traversal. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IStyleThe style that should be used for rendering within the editor control.protected IConfigRegistryTheIConfigRegistrycontaining the configuration of the current NatTable instance.protected IEditErrorHandlerThe error handler that will be used to show conversion errors.protected IDataValidatorTheIDataValidatorthat should be used to validate the input value prior committing.protected IDisplayConverterTheIDisplayConverterthat should be used to convert the input value to the canonical value and vice versa.protected EditModeEnumTheEditModeEnumwhich is used to activate special behaviour and styling.protected org.eclipse.swt.events.FocusListenerTheFocusListenerthat will be added to the created editor control forEditModeEnum.INLINEto close it if it loses focus.protected LabelStackTheLabelStackof the cell whose editor should be activated.protected ILayerCellThe cell whose editor should be activated.protected org.eclipse.swt.widgets.CompositeThe parent Composite, needed for the creation of the editor control.protected org.eclipse.swt.events.TraverseListenerTheTraverseListenerthat will be added to the created editor control forEditModeEnum.INLINEtrying to commit the editor prior to traversal.protected IEditErrorHandlerThe error handler that will be used to show validation errors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis method is intended to be used byIMouseEventMatcherimplementations that need to check for the editor and the click position to determine whether an editor should be activated or not.protected abstract org.eclipse.swt.widgets.ControlactivateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue) This method will be called byactivateCell(Composite, Object, EditModeEnum, ICellEditHandler, ILayerCell, IConfigRegistry)after initializing the activation values and before adding the default listeners.final org.eclipse.swt.widgets.ControlactivateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue, EditModeEnum editMode, ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) This method will be called by the framework to activate this cell editor.booleanactivateOnTraversal(IConfigRegistry configRegistry, List<String> configLabels) This method is asked on tab traversal whether thisICellEditorshould be automatically activated or not.voidThis method is intended to add listeners to the wrapped editor control to add context related behavior.org.eclipse.swt.graphics.RectanglecalculateControlBounds(org.eclipse.swt.graphics.Rectangle cellBounds) This method is used to calculate the bounds of the edit control when opened inline.voidclose()Close/dispose the containedControlbooleancommit(SelectionLayer.MoveDirectionEnum direction) Commits the current value of this editor.booleancommit(SelectionLayer.MoveDirectionEnum direction, boolean closeAfterCommit) Commits the current value of this editor.booleancommit(SelectionLayer.MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) Commits the current value of this editor.Converts the current value in this editor using the configuredIDisplayConverter.getCanonicalValue(IEditErrorHandler conversionErrorHandler) Converts the current value in this editor using the configuredIDisplayConverter.intintintintprotected ObjecthandleConversion(Object displayValue, IEditErrorHandler conversionErrorHandler) Converts the given display value using the configuredIDisplayConverter.booleanisClosed()booleanDetermines behavior after committing the value of this editor in combination with selection movement.booleanopenInline(IConfigRegistry configRegistry, List<String> configLabels) Determines whether the editor should be opened inline or using a dialog.booleanThis is a very special configuration to tell whether an ICellEditor should open a multi edit dialog for multi editing or not.voidThis method is intended to remove listeners from the wrapped editor control that was added byICellEditor.addEditorControlListeners()before to add context related behavior.voidsetCanonicalValue(Object canonicalValue) Sets the given canonical value to the wrapped editor control.voidsetDataValidator(IDataValidator validator) This method can be used to set theIDataValidatorto use.booleansupportMultiEdit(IConfigRegistry configRegistry, List<String> configLabels) Determines whether this editor supports multi edit behavior or not.booleanvalidateCanonicalValue(Object canonicalValue) Validates the given value using the configuredIDataValidator.booleanvalidateCanonicalValue(Object canonicalValue, IEditErrorHandler validationEditErrorHandler) Validates the current value in this editor using the configuredIDataValidator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor
createEditorControl, getEditorControl, getEditorValue, setEditorValue
-
Field Details
-
parent
protected org.eclipse.swt.widgets.Composite parentThe parent Composite, needed for the creation of the editor control. Used internally for adding general behaviour, e.g. forcing the focus if the editor is closed. -
cellStyle
The style that should be used for rendering within the editor control. Mainly it will cover foreground color, background color and font. If the editor control supports further styles, this needs to be specified be the ICellEditor implementation itself. -
displayConverter
TheIDisplayConverterthat should be used to convert the input value to the canonical value and vice versa. -
dataValidator
TheIDataValidatorthat should be used to validate the input value prior committing. -
editMode
TheEditModeEnumwhich is used to activate special behaviour and styling. This is needed because activating an editor inline will have different behaviour (e.g. moving the selection after commit) and styling than rendering the editor on a subdialog. -
layerCell
The cell whose editor should be activated. -
labelStack
TheLabelStackof the cell whose editor should be activated. -
conversionEditErrorHandler
The error handler that will be used to show conversion errors. -
validationEditErrorHandler
The error handler that will be used to show validation errors. -
configRegistry
TheIConfigRegistrycontaining the configuration of the current NatTable instance. This is necessary because the editors in the current architecture are not aware of the NatTable instance they are running in. -
focusListener
protected org.eclipse.swt.events.FocusListener focusListenerTheFocusListenerthat will be added to the created editor control forEditModeEnum.INLINEto close it if it loses focus. -
traverseListener
protected org.eclipse.swt.events.TraverseListener traverseListenerTheTraverseListenerthat will be added to the created editor control forEditModeEnum.INLINEtrying to commit the editor prior to traversal.
-
-
Constructor Details
-
AbstractCellEditor
public AbstractCellEditor()
-
-
Method Details
-
activateCell
public final org.eclipse.swt.widgets.Control activateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue, EditModeEnum editMode, ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) Description copied from interface:ICellEditorThis method will be called by the framework to activate this cell editor. It initializes the the values needed for further processing of the editor and will add listeners for general behavior of the editor control.- Specified by:
activateCellin interfaceICellEditor- Parameters:
parent- The parent Composite, needed for the creation of the editor control.originalCanonicalValue- The value that should be put to the activated editor control.editMode- TheEditModeEnumwhich is used to activate special behavior and styling. This is needed because activating an editor inline will have different behavior (e.g. moving the selection after commit) and styling than rendering the editor on a subdialog.editHandler- TheICellEditHandlerthat will be used on commit.cell- The cell whose corresponding editor should be activated.configRegistry- TheIConfigRegistrycontaining the configuration of the current NatTable instance. This is necessary because the editors in the current architecture are not aware of the NatTable instance they are running in.- Returns:
- The SWT
Controlto be used for capturing the new cell value.
-
activateCell
protected abstract org.eclipse.swt.widgets.Control activateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue) This method will be called byactivateCell(Composite, Object, EditModeEnum, ICellEditHandler, ILayerCell, IConfigRegistry)after initializing the activation values and before adding the default listeners. In this method the underlying editor control should be created and initialized, hiding default configuration from editor implementors.- Parameters:
parent- The parent Composite, needed for the creation of the editor control.originalCanonicalValue- The value that should be put to the activated editor control.- Returns:
- The SWT
Controlto be used for capturing the new cell value.
-
getColumnIndex
public int getColumnIndex()- Specified by:
getColumnIndexin interfaceICellEditor- Returns:
- The column index of the cell to which this editor is attached.
- See Also:
-
getRowIndex
public int getRowIndex()- Specified by:
getRowIndexin interfaceICellEditor- Returns:
- The row index of the cell to which this editor is attached.
- See Also:
-
getColumnPosition
public int getColumnPosition()- Specified by:
getColumnPositionin interfaceICellEditor- Returns:
- The column position of the cell to which this editor is attached.
- See Also:
-
getRowPosition
public int getRowPosition()- Specified by:
getRowPositionin interfaceICellEditor- Returns:
- The row position of the cell to which this editor is attached.
- See Also:
-
getCanonicalValue
Converts the current value in this editor using the configuredIDisplayConverter. If there is noIDisplayConverterregistered for this editor, the value itself will be returned.- Specified by:
getCanonicalValuein interfaceICellEditor- Returns:
- The canonical value after converting the current value or the
value itself if no
IDisplayConverteris configured. - Throws:
RuntimeException- for conversion failures. As theIDisplayConverterinterface does not specify throwing checked Exceptions on converting data, only unchecked Exceptions can occur. This is needed to stop further commit processing if the conversion failed.- See Also:
-
getCanonicalValue
Converts the current value in this editor using the configuredIDisplayConverter. If there is noIDisplayConverterregistered for this editor, the value itself will be returned. Will use the specifiedIEditErrorHandlerfor handling conversion errors.- Specified by:
getCanonicalValuein interfaceICellEditor- Parameters:
conversionErrorHandler- The error handler that will be activated in case of conversion errors.- Returns:
- The canonical value after converting the current value or the
value itself if no
IDisplayConverteris configured. - Throws:
RuntimeException- for conversion failures. As theIDisplayConverterinterface does not specify throwing checked Exceptions on converting data, only unchecked Exceptions can occur. This is needed to stop further commit processing if the conversion failed.- See Also:
-
handleConversion
Converts the given display value using the configuredIDisplayConverter. If there is noIDisplayConverterregistered for this editor, the value itself will be returned. Will use the specifiedIEditErrorHandlerfor handling conversion errors.- Parameters:
displayValue- The display value that needs to be converted.conversionErrorHandler- The error handler that will be activated in case of conversion errors.- Returns:
- The canonical value after converting the current value or the
value itself if no
IDisplayConverteris configured. - Throws:
RuntimeException- for conversion failures. As theIDisplayConverterinterface does not specify throwing checked Exceptions on converting data, only unchecked Exceptions can occur. This is needed to stop further commit processing if the conversion failed.- See Also:
-
setCanonicalValue
Description copied from interface:ICellEditorSets the given canonical value to the wrapped editor control. Prior to setting the value it needs to be converted to the display value, using the configuredIDisplayConverter.- Specified by:
setCanonicalValuein interfaceICellEditor- Parameters:
canonicalValue- The canonical value to be set to the wrapped editor control.
-
validateCanonicalValue
Description copied from interface:ICellEditorValidates the given value using the configuredIDataValidator. This method should be called with the value converted before by usingICellEditor.getCanonicalValue().- Specified by:
validateCanonicalValuein interfaceICellEditor- Parameters:
canonicalValue- The canonical value to validate.- Returns:
trueif the current value in this editor is valid or noIDataValidatoris registered,falseif the value is not valid.
-
validateCanonicalValue
public boolean validateCanonicalValue(Object canonicalValue, IEditErrorHandler validationEditErrorHandler) Description copied from interface:ICellEditorValidates the current value in this editor using the configuredIDataValidator. Validates the given value using the configuredIDataValidator. This method should be called with the value converted before by usingICellEditor.getCanonicalValue(). Will use the specifiedIEditErrorHandlerfor handling validation errors.- Specified by:
validateCanonicalValuein interfaceICellEditor- Parameters:
canonicalValue- The canonical value to validate.validationEditErrorHandler- The error handler that will be activated in case of validation errors.- Returns:
trueif the current value in this editor is valid or noIDataValidatoris registered,falseif the value is not valid.
-
commit
Description copied from interface:ICellEditorCommits the current value of this editor. Will first try to convert and validate the current value, and if that succeeds and the value can be committed to the data model, the editor will be closed afterwards.- Specified by:
commitin interfaceICellEditor- Parameters:
direction- The direction the selection within the NatTable should move after commit has finished.- Returns:
trueif the commit operation succeeded,falseif the current value could not be committed. A value might not be committed for example if the conversion or the validation failed.
-
commit
Description copied from interface:ICellEditorCommits the current value of this editor. Will first try to convert the current value. Then it is checked if the validation should be executed which can be specified via parameter. If that succeeds and the value can be committed to the data model, the editor will be closed afterwards.- Specified by:
commitin interfaceICellEditor- Parameters:
direction- The direction the selection within the NatTable should move after commit has finished.closeAfterCommit- flag to tell whether this editor needs to closed after the commit or if it should stay open.- Returns:
trueif the commit operation succeeded,falseif the current value could not be committed. A value might not be committed for example if the conversion or the validation failed.
-
commit
public boolean commit(SelectionLayer.MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) Description copied from interface:ICellEditorCommits the current value of this editor.- Specified by:
commitin interfaceICellEditor- Parameters:
direction- The direction the selection within the NatTable should move after commit has finished.closeAfterCommit- flag to tell whether this editor needs to closed after the commit or if it should stay open.skipValidation- Flag to specify whether the current value in this editor should be validated or not.- Returns:
trueif the commit operation succeeded,falseif the current value could not be committed. A value might not be committed for example if the conversion or the validation failed.
-
close
public void close()Description copied from interface:ICellEditorClose/dispose the containedControl- Specified by:
closein interfaceICellEditor
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceICellEditor- Returns:
trueif this editor has been closed already,falseif it is still open
-
openInline
Description copied from interface:ICellEditorDetermines whether the editor should be opened inline or using a dialog. By default it will check this by configuration attributeEditConfigAttributes.OPEN_IN_DIALOG. If there is no configuration found for this,truewill be returned for backwards compatibility.If this method returns
true, the editor will be opened inline (default).There might be editors that are only able to be opened in a dialog. These implementations need to override this method to always return
false, so the editor never gets opened inline.- Specified by:
openInlinein interfaceICellEditor- Parameters:
configRegistry- TheIConfigRegistryto retrieve the configuration for inline/dialog editing out of. Needed here because the instanceIConfigRegistrymight not be set on calling this method.configLabels- The labels out of the LabelStack of the cell whose editor should be activated. Needed here because this method needs to be called prior to activation to determine where to activate it.- Returns:
trueif the editor should opened inline,falseif not.- See Also:
-
supportMultiEdit
Description copied from interface:ICellEditorDetermines whether this editor supports multi edit behavior or not. If this method returnstrue, on selecting and pressing F2 on several cells that are editable, having the same editor type and converter registered, a multi edit dialog will open. By default this method will returntrue. You can change this behavior by setting the configuration attributeEditConfigAttributes.SUPPORT_MULTI_EDIT.You should consider returning
falsee.g. if the update operation is complex or you use conditional validation, where a value is validated against another value in the data model.- Specified by:
supportMultiEditin interfaceICellEditor- Parameters:
configRegistry- TheIConfigRegistryto retrieve the configuration for multi edit support out of. Needed here because the instanceIConfigRegistrymight not be set on calling this method.configLabels- The labels out of the LabelStack of the cell whose editor should be activated. Needed here because this method needs to be called prior to activation to determine where to activate it.- Returns:
trueif this editor will open in a subdialog for multi editing,falseif the multi editing of this kind of cell editor is not supported.- See Also:
-
openMultiEditDialog
public boolean openMultiEditDialog()Description copied from interface:ICellEditorThis is a very special configuration to tell whether an ICellEditor should open a multi edit dialog for multi editing or not. Usually for multi editing there should be always a multi edit dialog be opened. There are only special cases where this doesn't make sense. The only types of ICellEditors that shouldn't open multi edit dialogs are editors that change their values directly and there is no interactively editor control opened, e.g. checkboxes.- Specified by:
openMultiEditDialogin interfaceICellEditor- Returns:
trueif for multi editing a multi edit dialog should be opened,falseif the multi editing should be performed directly without opening a multi edit dialog. Note:trueis the default value and changing it tofalsefor a custom editor might cause issues if not dealed correctly.
-
openAdjacentEditor
public boolean openAdjacentEditor()Description copied from interface:ICellEditorDetermines behavior after committing the value of this editor in combination with selection movement. If this method returntrueand the selection is moved after committing, the editor for the newly selected cell will be activated immediately. If this method returnsfalseor the selection is not moved after commit, no action should be executed.The behavior previous to this configuration was to not open the adjacent editor. So if there is no configuration registered for this,
falsewill be returned by default.Note: It only makes sense to call this method if the editor is already activated. Calling this method on an editor that has not been activated already will lead to exceptions.
- Specified by:
openAdjacentEditorin interfaceICellEditor- Returns:
trueif the adjacent editor should be opened if the selection moves after commit,falseif not.- See Also:
-
activateAtAnyPosition
public boolean activateAtAnyPosition()Description copied from interface:ICellEditorThis method is intended to be used byIMouseEventMatcherimplementations that need to check for the editor and the click position to determine whether an editor should be activated or not. By default this method will returntrue. Special implementations that need a different behavior need to returnfalseinstead. E.g. checkbox editors should only be activated in case the icon that represents the checkbox is clicked.- Specified by:
activateAtAnyPositionin interfaceICellEditor- Returns:
trueif thisICellEditorshould be activated by clicking at any position in the corresponding cell,falseif there need to be a special position clicked.
-
activateOnTraversal
Description copied from interface:ICellEditorThis method is asked on tab traversal whether thisICellEditorshould be automatically activated or not. This is necessary to avoid automatically changing the value of a checkbox or opening a dialog editor on traversal.- Specified by:
activateOnTraversalin interfaceICellEditor- Parameters:
configRegistry- TheIConfigRegistryto retrieve the configuration out of. Needed here because the instanceIConfigRegistrymight not be set on calling this method.configLabels- The labels out of the LabelStack of the cell whose editor should be activated.- Returns:
trueif thisICellEditorshould be activated in case of tab traversal,falseif not.- See Also:
-
addEditorControlListeners
public void addEditorControlListeners()Description copied from interface:ICellEditorThis method is intended to add listeners to the wrapped editor control to add context related behavior. For example, inEditModeEnum.INLINEby default this should add a FocusListener that commits the current value if the editor control loses focus.This method was introduced mainly because of two issues:
- On Mac OS calling setBounds() on a Control will cause losing focus. So listeners need to be added after this method is called by the EditController, otherwise on activating the editor it will be closed immediately after the correct size is calculated.
- The main concept for cell editor activation is, that the editor control is disposed on closing the editor. This way everytime the cell editor is activated, a new editor control will be created. If an editor is implemented that needs to keep the editor control after closing the editor, it needs to be ensured that the listeners are removed again. Otherwise the listeners would be added again everytime the editor is activated.
EditController.editCell(ILayerCell, Composite, Object, IConfigRegistry).- Specified by:
addEditorControlListenersin interfaceICellEditor
-
removeEditorControlListeners
public void removeEditorControlListeners()Description copied from interface:ICellEditorThis method is intended to remove listeners from the wrapped editor control that was added byICellEditor.addEditorControlListeners()before to add context related behavior.This method was introduced to add the possibility to create an
ICellEditorwhose wrapped editor control should not be disposed on closing the editor.The main concept for cell editor activation is, that the editor control is disposed on closing the editor. This way everytime the cell editor is activated, a new editor control will be created. If an editor is implemented that needs to keep the editor control after closing the editor, it needs to be ensured that the listeners are removed again. Otherwise the listeners would be added again everytime the editor is activated.
This method needs to be called onICellEditor.close(). There is no automatical call by the framework if you are not using the abstract implementation ofICellEditor.- Specified by:
removeEditorControlListenersin interfaceICellEditor
-
calculateControlBounds
public org.eclipse.swt.graphics.Rectangle calculateControlBounds(org.eclipse.swt.graphics.Rectangle cellBounds) Description copied from interface:ICellEditorThis method is used to calculate the bounds of the edit control when opened inline. By default it should return the given cell bounds to match the cell structure in NatTable. For several cases it might be useful to return the preferred size to show all content rather than trimming the control to the cell size.Note: By changing the bounds you should ensure to only modify width and height attributes and not x and y coordinate, otherwise the editor control will show up somewhere else and not in place of the cell that is edited.
- Specified by:
calculateControlBoundsin interfaceICellEditor- Parameters:
cellBounds- The bounds of the cell for which the editor is opened.- Returns:
- The bounds of the editor control that should be applied. By default the cell bounds for several cases bigger.
-
setDataValidator
This method can be used to set theIDataValidatorto use. This might be useful e.g. the configured validator needs to be wrapped to add special behaviour. Setting a validator prior to activating the editor will have no effect.Note: It is not suggested to call this method in custom code. It is used e.g. by the TickUpdateCellEditDialog as dependent on the selected update type, the validator needs to be enabled or not.
- Parameters:
validator- TheIDataValidatorto set.
-