Interface AttributeEditor
- All Superinterfaces:
AttributeWidget
An attribute editor is used to edit attributes of one or more attribute types.
-
Nested Class Summary
Nested classes/interfaces inherited from interface se.conciliate.extensions.attribute.AttributeWidget
AttributeWidget.WidgetType
-
Method Summary
Modifier and TypeMethodDescriptioncreateSwingEditor
(Edit edit, EditCallback callback, AttributeWidget.WidgetType type) Creates a new JComponent that can be used to edit the given Edit and that is the only one sending events to the given callback.default boolean
Returns true if the value is editable by the user.default boolean
isFullWidth
(PreparedAttribute preparedAttribute) Returns true if this widget prefers to take up its parent's full width when editing the given prepared attribute, false otherwise.prepare
(String value, String refinement, AttributeDataType dataType, String valueHolderUUID) Prepares the value for display.default Collection<PreparedBatchEntry>
prepareBatch
(Collection<AttributeValue> values, MTLanguage lang, String refinement, AttributeDataType dataType) Prepares the values for display in batch.default boolean
setMainColumnWidth
(int width, JComponent editor) IfisFullWidth(PreparedAttribute)
returns false, this method must be called by consumers of this interface, and it must be called after createSwingEditor.Methods inherited from interface se.conciliate.extensions.attribute.AttributeWidget
getID, getName, getSupportedWidgetTypes, isSupported
-
Method Details
-
createSwingEditor
Creates a new JComponent that can be used to edit the given Edit and that is the only one sending events to the given callback. The widget type is a member ofAttributeWidget.getSupportedWidgetTypes()
and denotes what type of widget that the caller want. A widget type that is not a member of the supported types will result in undefined behaviour.
Note that this method will only be called with edits having prepared attributes created by editors of this type, and only after having properly prepared the attribute.- Parameters:
edit
- The object to edit.callback
- A callback used to indicate when editing starts, stopps or is cancelled.type
- the type of widget to create. Must be a member of the supported types for this editor.- Returns:
- A new JComponent (for each invocation of the method) that can be used to edit the object given.
-
prepare
PreparedAttribute prepare(String value, String refinement, AttributeDataType dataType, String valueHolderUUID) Prepares the value for display. Some implementation may not need any preparation and can thus return a simple wrapper around the value, refinement and data type. Some implementations might need to fetch external data (external to the string value) before the widget can be properly displayed (such as when the value is an id in some database).
Returning from this method indicates that the widget is ready to display the prepared attribute.
NOTE: Since the refinement and data type may change for a value, this method may be called with values that are not consistent with the refinement and data type. If this is the case, the value was created for a different data type or a different refinement and should therefore be treated as the empty string (no value has been set yet).- Parameters:
value
- the value of the attributerefinement
- the attribute's refinementdataType
- the data type of the attributevalueHolderUUID
- the uuid of the data object that the value is attached to, e.g. a symbol uuid.- Returns:
- a prepared attribute who's data this widget is ready to display
-
prepareBatch
default Collection<PreparedBatchEntry> prepareBatch(Collection<AttributeValue> values, MTLanguage lang, String refinement, AttributeDataType dataType) Prepares the values for display in batch. The default implementation callsprepare
for each AttributeValue in the collection and returns the result as a set of batch-entries. The main use of this method is when one wants to present a specific attribute for multiple value-holders. In such cases, calling prepare for each value-holder may be slow and the presenter may be able to alleviate this if it gets a "batch" of values to prepare instead. Implementation of this method is optional but to enhance performance, it is preferred - especially if the preparation is a slow running task.- Parameters:
values
- A collection of AttributeValue that corresponds the value of the attribute and the UUID of the value holder (e.g. symbol or model).lang
- the language of the refinement (and thus the language used to create ALL values in 'values').refinement
- the refinement that MUST be applicable to ALL values in 'values'.dataType
- the data type that MUST be applicable to ALL values in 'values'.- Returns:
- a collection of prepared attributes who's data this widget is ready to display
- See Also:
-
isEditable
default boolean isEditable()Returns true if the value is editable by the user. This should return false for editors that are only used to present a computed value, e.g. the "relation" field type.- Returns:
- true if attribute value is editable by the user with this editor.
-
isFullWidth
Returns true if this widget prefers to take up its parent's full width when editing the given prepared attribute, false otherwise.- Parameters:
preparedAttribute
- The attribute that will be edited by the return value of createSwingEditor. Note that this method may be called before or after createSwingEditor, or not at all. It is up to consumers of this interface to decide how the layout is done, this is just a layout hint.- Returns:
- true if this widget prefers to take up its parent's full width, false otherwise.
-
setMainColumnWidth
IfisFullWidth(PreparedAttribute)
returns false, this method must be called by consumers of this interface, and it must be called after createSwingEditor.
The parameter width is used to set the width of the main column of the editor, if the editor has multiple sub-components and 'column' makes sense. True is then returned. If the editor does not have sub-components, or if 'column' does not make sense in the editor's layout, width is ignored and false is returned.
For example, if the editor is a drop-down box it may have sub-components but 'column' makes no sense, so false is returned.
If the editor is a text field with a label behind it (maybe specifying a unit), then the editor has sub-components and 'column' makes sense. The main column is the text filed and the unit label is the second column. In this case, the text field's width should be set to width and true should be returned.
A final example is a simple text field. It has no sub-components so false is returned.- Parameters:
width
- The width to set the main column to, if editor has sub-components and column makes sense in the layout of editor.editor
- The value returned by createSwingEditor- Returns:
- true if the editor's main column's width has been set to width, false otherwise.
-