Interface AttributePresenter<T extends PreparedAttribute>
- All Superinterfaces:
AttributeWidget
An attribute presenter is a presentation of an attribute value for one or more
attribute types.
- Author:
- Per-Erik
-
Nested Class Summary
Nested classes/interfaces inherited from interface se.conciliate.extensions.attribute.AttributeWidget
AttributeWidget.WidgetType
-
Method Summary
Modifier and TypeMethodDescriptioncreateSwingPresenter
(PreparedAttribute prepared, AttributeWidget.WidgetType type) Creates a new JComponent that can be used to present the given prepared attribute.getComparator
(String refinement, MTLanguage language, AttributeDataType dataType) Returns a comparator for prepared attributes.htmlPresentation
(PreparedAttribute prepared) Returns an optional html presentation of the given prepared attribute.default boolean
isFullWidth
(PreparedAttribute preparedAttribute) Returns true if this widget prefers to take up its parent's full width when presenting 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 presenter) IfisFullWidth(PreparedAttribute)
returns false, this method must be called by consumers of this interface, and it must be called after createSwingPresenter.stringPresentation
(PreparedAttribute prepared) Returns a string presentation for the given prepared attribute.Methods inherited from interface se.conciliate.extensions.attribute.AttributeWidget
getID, getName, getSupportedWidgetTypes, isSupported
-
Method Details
-
getComparator
Returns a comparator for prepared attributes. This method will only be called with data types yielding a true value from #isSupported. The returned comparator will only have to compare values with the given refinement (cross refinement comparisons will never happen) and language.- Parameters:
refinement
- The refinement that the comparator's arguments will be of.language
- The language that the comparator's values will have.dataType
- The data type.- Returns:
- A comparator comparing prepared attributes where all prepared attributes are guaranteed to have the given refinement and data type, and where the language of the prepared attribute's value is the given language.
-
createSwingPresenter
Creates a new JComponent that can be used to present the given prepared attribute. The widget type is a member ofgetSupportedWidgetTypes()
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 prepared attributes created by presenters of this type.- Parameters:
prepared
- the prepared attribute to displaytype
- 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 present the given value.
-
stringPresentation
Returns a string presentation for the given prepared attribute. This is analogous to an image "alt" description and for some data types may be as simple as returning the value.
Note that this method will only be called with prepared attributes having created by presenters of this type.- Parameters:
prepared
- the prepared attribute to "stringify".- Returns:
- a string representation of the given value, never null.
-
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. The order of the collection does not have to be the same as the order in the sent in "values" collection (since the collection of values may not be ordered). To "map" the values to the result, the value used to prepare the result-entry is present as part of the entry and is guaranteed to be the same instance (this is why the only way to create a PreparedBatchEntry is by calling AttributeValue#preparedWith). The SIZE of the returned value must however be the same as the "values"-collection (implying all values MUST be prepared). Since null is NOT accepted as a return value from #prepare, this should not be hard to uphold.
- See Also:
-
htmlPresentation
Returns an optional html presentation of the given prepared attribute. The default is to return empty. The returned string must be valid HTML5.
Note that this method will only be called with prepared attributes having created by presenters of this type- Parameters:
prepared
- The prepared attribute to render into HTML5.- Returns:
- Empty if no html presentation is available or an HTML5 string presenting the value.
-
isFullWidth
Returns true if this widget prefers to take up its parent's full width when presenting the given prepared attribute, false otherwise.- Parameters:
preparedAttribute
- The attribute that will be presented by the return value of createSwingPresenter. Note that this method may be called before or after createSwingPresenter, 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 createSwingPresenter.
The parameter width is used to set the width of the main column of the presenter, if the presenter has multiple sub-components and 'column' makes sense. True is then returned. If the presenter does not have sub-components, or if 'column' does not make sense in the presenter's layout, width is ignored and false is returned.
For example, if the presenter is a drop-down box it may have sub-components but 'column' makes no sense, so false is returned.
If the presenter is a text field with a label behind it (maybe specifying a unit), then the presenter 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 presenter has sub-components and column makes sense in the layout of presenter.presenter
- The value returned by createSwingPresenter- Returns:
- true if the presenter's main column's width has been set to width, false otherwise.
-