public abstract class AbstractDialogCellEditor extends Object implements ICellEditor, ICellEditDialog
ICellEditor
that is also a ICellEditDialog
.
By creating a ICellEditor
based on this abstract implementation, you are able
to create an editor that wraps a SWT or JFace dialog. As SWT and JFace dialogs does not
extend the same base classes, the local instance for the wrapped dialog is of type object
in here. In the concrete implementation the getDialogInstance()
should return the concrete dialog type that is wrapped.
By using this implementation, the CellEditDialogFactory
will return the instance of this
editor, after it was activated previously.
Modifier and Type | Field and Description |
---|---|
protected IConfigRegistry |
configRegistry
The
IConfigRegistry containing the configuration of the
current NatTable instance. |
protected IEditErrorHandler |
conversionEditErrorHandler
The error handler that will be used to show conversion errors.
|
protected IDataValidator |
dataValidator
The
IDataValidator that should be used to validate the input value
prior committing. |
protected Object |
dialog
The
Dialog that should be used as a cell editor. |
protected IDisplayConverter |
displayConverter
The
IDisplayConverter that should be used to convert the input value
to the canonical value and vice versa. |
protected Map<String,Object> |
editDialogSettings
Map that contains custom configurations for this
CellEditDialog . |
protected DialogEditHandler |
editHandler
The
ICellEditHandler that will be used on commit. |
protected ILayerCell |
layerCell
The cell whose editor should be activated.
|
protected org.eclipse.swt.widgets.Composite |
parent
The parent Composite, needed for the creation of the dialog.
|
protected IEditErrorHandler |
validationEditErrorHandler
The error handler that will be used to show validation errors.
|
DIALOG_MESSAGE, DIALOG_SHELL_ICON, DIALOG_SHELL_LOCATION, DIALOG_SHELL_RESIZABLE, DIALOG_SHELL_SIZE, DIALOG_SHELL_TITLE
Constructor and Description |
---|
AbstractDialogCellEditor() |
Modifier and Type | Method and Description |
---|---|
boolean |
activateAtAnyPosition()
This method is intended to be used by
IMouseEventMatcher implementations that need
to check for the editor and the click position to determine whether an editor should be
activated or not. |
org.eclipse.swt.widgets.Control |
activateCell(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.
|
void |
addEditorControlListeners()
This method is intended to add listeners to the wrapped editor control to add context related
behaviour.
|
Object |
calculateValue(Object currentValue,
Object processValue)
In case
ICellEditDialog.getEditType() returns an edit type for processing
values, this method should implemented to do that transformation. |
abstract void |
close()
Close/dispose the contained
Control |
boolean |
commit(SelectionLayer.MoveDirectionEnum direction)
Commits the current value of this editor.
|
boolean |
commit(SelectionLayer.MoveDirectionEnum direction,
boolean closeAfterCommit)
Commits the current value of this editor.
|
boolean |
commit(SelectionLayer.MoveDirectionEnum direction,
boolean closeAfterCommit,
boolean skipValidation)
Commits the current value of this editor.
|
abstract Object |
createDialogInstance()
Will create the dialog instance that should be wrapped by this
AbstractDialogCellEditor . |
org.eclipse.swt.widgets.Control |
createEditorControl(org.eclipse.swt.widgets.Composite parent)
Creates the editor control that is wrapped by this ICellEditor.
|
Object |
getCanonicalValue()
Converts the current value in this editor using the configured
IDisplayConverter . |
Object |
getCanonicalValue(IEditErrorHandler conversionErrorHandler)
Converts the current value in this editor using the configured
IDisplayConverter . |
int |
getColumnIndex() |
int |
getColumnPosition() |
Object |
getCommittedValue() |
abstract Object |
getDialogInstance() |
org.eclipse.swt.widgets.Control |
getEditorControl() |
abstract Object |
getEditorValue()
Returns the current value in this editor prior to conversion.
|
EditTypeEnum |
getEditType() |
int |
getRowIndex() |
int |
getRowPosition() |
abstract boolean |
isClosed() |
abstract int |
open()
Opens this dialog, creating it first if it has not yet been created.
|
boolean |
openAdjacentEditor()
Determines behaviour after committing the value of this editor in combination with selection
movement.
|
boolean |
openInline(IConfigRegistry configRegistry,
List<String> configLabels)
Determines whether the editor should be opened inline or using a dialog.
|
void |
removeEditorControlListeners()
This method is intended to remove listeners from the wrapped editor control that was added by
ICellEditor.addEditorControlListeners() before to add context related behaviour. |
void |
setCanonicalValue(Object canonicalValue)
Sets the given canonical value to the wrapped editor control.
|
void |
setDialogSettings(Map<String,Object> editDialogSettings)
Allows to customize the appearance of the dialog.
|
abstract void |
setEditorValue(Object value)
Sets the given value to editor control.
|
boolean |
supportMultiEdit(IConfigRegistry configRegistry,
List<String> configLabels)
Determines whether this editor supports multi edit behaviour or not.
|
boolean |
validateCanonicalValue(Object canonicalValue)
Validates the given value using the configured
IDataValidator . |
boolean |
validateCanonicalValue(Object canonicalValue,
IEditErrorHandler validationErrorHandler)
Validates the current value in this editor using the configured
IDataValidator . |
protected org.eclipse.swt.widgets.Composite parent
protected Object dialog
Dialog
that should be used as a cell editor.protected ILayerCell layerCell
protected DialogEditHandler editHandler
ICellEditHandler
that will be used on commit.protected IDisplayConverter displayConverter
IDisplayConverter
that should be used to convert the input value
to the canonical value and vice versa.protected IDataValidator dataValidator
IDataValidator
that should be used to validate the input value
prior committing.protected IEditErrorHandler conversionEditErrorHandler
protected IEditErrorHandler validationEditErrorHandler
protected IConfigRegistry configRegistry
IConfigRegistry
containing 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.protected Map<String,Object> editDialogSettings
CellEditDialog
.
We do not use the IDialogSettings
provided by JFace, because they are
used to store and load the settings in XML rather than overriding the behaviour.public EditTypeEnum getEditType()
getEditType
in interface ICellEditDialog
EditTypeEnum.SET
is returned, which
will simply set the committed value to the data model. Every other
edit type will do some calculation based on the committed value and
the current value in the data model.public Object calculateValue(Object currentValue, Object processValue)
ICellEditDialog
ICellEditDialog.getEditType()
returns an edit type for processing
values, this method should implemented to do that transformation.calculateValue
in interface ICellEditDialog
currentValue
- The current value for the cell before data model updateprocessValue
- The value committed to the editor that should be used for
calculation on the current value.public abstract int open()
ICellEditDialog
Specified in here for convenience so we only need to check against this interface for a dialog.
open
in interface ICellEditDialog
public org.eclipse.swt.widgets.Control activateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue, EditModeEnum editMode, ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry)
ICellEditor
activateCell
in interface ICellEditor
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
- The EditModeEnum
which 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.editHandler
- The ICellEditHandler
that will be used on commit.cell
- The cell whose corresponding editor should be activated.configRegistry
- The IConfigRegistry
containing 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.Control
to be used for capturing the new cell value.public abstract Object createDialogInstance()
AbstractDialogCellEditor
.
Note that you always need to create and return a new instance because on commit or close the
dialog will be closed, which disposes the shell of the dialog. Therefore the instance will not
be usable after commit/close.AbstractDialogCellEditor
public abstract Object getDialogInstance()
AbstractDialogCellEditor
public abstract Object getEditorValue()
ICellEditor
getEditorValue
in interface ICellEditor
public abstract void setEditorValue(Object value)
ICellEditor
setEditorValue
in interface ICellEditor
value
- The display value to set to the wrapped editor control.public Object getCanonicalValue()
ICellEditor
IDisplayConverter
.
If there is no IDisplayConverter
registered for this editor, the value itself
will be returned.getCanonicalValue
in interface ICellEditor
IDisplayConverter
is configured.IDisplayConverter
public Object getCanonicalValue(IEditErrorHandler conversionErrorHandler)
ICellEditor
IDisplayConverter
.
If there is no IDisplayConverter
registered for this editor, the value itself
will be returned. Will use the specified IEditErrorHandler
for handling
conversion errors.getCanonicalValue
in interface ICellEditor
conversionErrorHandler
- The error handler that will be activated in case of
conversion errors.IDisplayConverter
is configured.IDisplayConverter
public void setCanonicalValue(Object canonicalValue)
ICellEditor
IDisplayConverter
.setCanonicalValue
in interface ICellEditor
canonicalValue
- The canonical value to be set to the wrapped editor control.public boolean validateCanonicalValue(Object canonicalValue)
ICellEditor
IDataValidator
. This method should
be called with the value converted before by using ICellEditor.getCanonicalValue()
.validateCanonicalValue
in interface ICellEditor
canonicalValue
- The canonical value to validate.true
if the current value in this editor is valid or no
IDataValidator
is registered, false
if the value is not valid.public boolean validateCanonicalValue(Object canonicalValue, IEditErrorHandler validationErrorHandler)
ICellEditor
IDataValidator
.
Validates the given value using the configured IDataValidator
. This method should
be called with the value converted before by using ICellEditor.getCanonicalValue()
.
Will use the specified IEditErrorHandler
for handling validation errors.validateCanonicalValue
in interface ICellEditor
canonicalValue
- The canonical value to validate.validationErrorHandler
- The error handler that will be activated in case of
validation errors.true
if the current value in this editor is valid or no
IDataValidator
is registered, false
if the value is not valid.public boolean commit(SelectionLayer.MoveDirectionEnum direction)
ICellEditor
commit
in interface ICellEditor
direction
- The direction the selection within the NatTable should move
after commit has finished.true
if the commit operation succeeded,
false
if the current value could not be committed.
A value might not be committed for example if the conversion or
the validation failed.public boolean commit(SelectionLayer.MoveDirectionEnum direction, boolean closeAfterCommit)
ICellEditor
commit
in interface ICellEditor
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.true
if the commit operation succeeded,
false
if the current value could not be committed.
A value might not be committed for example if the conversion or
the validation failed.public boolean commit(SelectionLayer.MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation)
ICellEditor
commit
in interface ICellEditor
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.true
if the commit operation succeeded,
false
if the current value could not be committed.
A value might not be committed for example if the conversion or
the validation failed.public Object getCommittedValue()
getCommittedValue
in interface ICellEditDialog
public abstract void close()
ICellEditor
Control
close
in interface ICellEditor
public abstract boolean isClosed()
isClosed
in interface ICellEditor
true
if this editor has been closed already,
false
if it is still openpublic org.eclipse.swt.widgets.Control getEditorControl()
getEditorControl
in interface ICellEditor
public org.eclipse.swt.widgets.Control createEditorControl(org.eclipse.swt.widgets.Composite parent)
ICellEditor
createEditorControl
in interface ICellEditor
parent
- The Composite that will be the parent of the new editor control.
Can not be null
public boolean openInline(IConfigRegistry configRegistry, List<String> configLabels)
ICellEditor
EditConfigAttributes.OPEN_IN_DIALOG
.
If there is no configuration found for this, true
will 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.
openInline
in interface ICellEditor
configRegistry
- The IConfigRegistry
to retrieve the configuration for
inline/dialog editing out of. Needed here because the instance IConfigRegistry
might 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.true
if the editor should opened inline, false
if not.EditConfigAttributes.OPEN_IN_DIALOG
public boolean supportMultiEdit(IConfigRegistry configRegistry, List<String> configLabels)
ICellEditor
true
, 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 return true
. You can change this behaviour by setting
the configuration attribute EditConfigAttributes.SUPPORT_MULTI_EDIT
.
You should consider returning false
e.g. if the update operation is complex or
you use conditional validation, where a value is validated against another value in the data model.
supportMultiEdit
in interface ICellEditor
configRegistry
- The IConfigRegistry
to retrieve the configuration for
multi edit support out of. Needed here because the instance IConfigRegistry
might 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.true
if this editor will open in a subdialog for multi editing, false
if the multi editing of this kind of cell editor is not supported.EditConfigAttributes.SUPPORT_MULTI_EDIT
public boolean openAdjacentEditor()
ICellEditor
true
and the selection is moved after committing,
the editor for the newly selected cell will be activated immediately. If this method returns
false
or the selection is not moved after commit, no action should be executed.
The behaviour previous to this configuration was to not open the adjacent editor. So if there
is no configuration registered for this, false
will 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.
openAdjacentEditor
in interface ICellEditor
true
if the adjacent editor should be opened if the selection moves after
commit, false
if not.EditConfigAttributes.OPEN_ADJACENT_EDITOR
public boolean activateAtAnyPosition()
ICellEditor
IMouseEventMatcher
implementations 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 return true
. Special implementations
that need a different behaviour need to return false
instead. E.g. checkbox editors
should only be activated in case the icon that represents the checkbox is clicked.activateAtAnyPosition
in interface ICellEditor
true
if this ICellEditor
should be activated by clicking at any
position in the corresponding cell, false
if there need to be a special
position clicked.public void addEditorControlListeners()
ICellEditor
EditModeEnum.INLINE
by 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:
EditController.editCell(ILayerCell, Composite,
Object, IConfigRegistry)
.addEditorControlListeners
in interface ICellEditor
public void removeEditorControlListeners()
ICellEditor
ICellEditor.addEditorControlListeners()
before to add context related behaviour.
This method was introduced to add the possibilty to create an ICellEditor
whose
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 of ICellEditor
.removeEditorControlListeners
in interface ICellEditor
public void setDialogSettings(Map<String,Object> editDialogSettings)
ICellEditDialog
CellEditDialogFactory
.
The map containing the settings can be registered to the IConfigRegistry
for
the key EditConfigAttributes.EDIT_DIALOG_SETTINGS
. The keys that are valid
for this map are specified below.
setDialogSettings
in interface ICellEditDialog
editDialogSettings
- Map containing the settings to customize the edit dialog
appearance.ICellEditDialog.DIALOG_SHELL_TITLE
,
ICellEditDialog.DIALOG_SHELL_ICON
,
ICellEditDialog.DIALOG_SHELL_LOCATION
,
ICellEditDialog.DIALOG_SHELL_SIZE
,
ICellEditDialog.DIALOG_SHELL_RESIZABLE
,
ICellEditDialog.DIALOG_MESSAGE
,
EditConfigAttributes.EDIT_DIALOG_SETTINGS
public int getColumnIndex()
getColumnIndex
in interface ICellEditor
public int getRowIndex()
getRowIndex
in interface ICellEditor
public int getColumnPosition()
getColumnPosition
in interface ICellEditor
public int getRowPosition()
getRowPosition
in interface ICellEditor
Copyright © 2013. All Rights Reserved.