Package com.install4j.api.beaninfo
Interface PropertyConverter
-
public interface PropertyConverter
A property converter translates between a string representation and the actual object state and provides an optionalproperty customizer
. Property converters are registered on a per-bean basis withInstall4JBeanInfo.setPropertyConverters(PropertyConverter[])
.This class and the
PropertyConverter
class are similar to thePropertyEditor
class which was not used in the install4j API since the editing concepts of the install4j IDE do not quite match with the ideas in the java.beans API.In concept, this class is similar to the
EnumerationMapper
class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_CONTEXT
A default context that you can use in thegetContext()
method if there is only one property converter for the property type returned bygetPropertyClass()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Object
fromString(java.lang.String string)
Converts a string representation to an object of typegetPropertyClass()
.java.lang.String
getContext()
The property descriptor of a property that wants to use this property converter must have a non-null context that corresponds to the return value of this method.java.lang.Class
getPropertyClass()
Returns the property type for which this property converter is eligible.java.lang.Class
getPropertyCustomizerClass()
Returns the class of the optional property customizer.boolean
supportsFromString()
Returns if the property converter is able to convert a string representation to an object.java.lang.String
toString(java.lang.Object object)
Converts the property value to a string value.
-
-
-
Field Detail
-
DEFAULT_CONTEXT
static final java.lang.String DEFAULT_CONTEXT
A default context that you can use in thegetContext()
method if there is only one property converter for the property type returned bygetPropertyClass()
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPropertyClass
java.lang.Class getPropertyClass()
Returns the property type for which this property converter is eligible. Derived classes are also captured.- Returns:
- the property type
-
getContext
java.lang.String getContext()
The property descriptor of a property that wants to use this property converter must have a non-null context that corresponds to the return value of this method. In this way the runtime knows that this property converter should be used for displaying and editing a property. The context must not be globally unique, property converters of other property types can use the same context value.For classes that do not have default handlers in install4j, the property converter will also be used if this method returns
DEFAULT_CONTEXT
, thegetPropertyClass()
method returns the class of the property and the context of the property is not set. However, it is safer not to rely on that behavior.- Returns:
- the context that will be used by the properties
-
toString
java.lang.String toString(java.lang.Object object)
Converts the property value to a string value. The string value will be displayed in the install4j IDE. IfsupportsFromString()
returnstrue
, the string value must be valid input forfromString(String)
and return an object with the same internal state.- Parameters:
object
- the property value of the type returned bygetPropertyClass()
or possibly of a derived class- Returns:
- the string value
-
supportsFromString
boolean supportsFromString()
Returns if the property converter is able to convert a string representation to an object. If yes, the user will be able to edit the string returned bytoString(Object)
in the install4j IDE.- Returns:
true
if a string can be converted to an object
-
fromString
java.lang.Object fromString(java.lang.String string)
Converts a string representation to an object of typegetPropertyClass()
. When editing of the property is completed in the install4j IDE, this method will be called to construct an object that will be set as the property value. This method is only called ifsupportsFromString()
returnstrue
.- Parameters:
string
- the string representation- Returns:
- the object
-
getPropertyCustomizerClass
java.lang.Class getPropertyCustomizerClass()
Returns the class of the optional property customizer. If you want to offer a dialog where the user can edit the property value, you have to implementPropertyCustomizer
and return the name of your property customizer class, otherwise returnnull
.If a non-null value is returned, the user will see a "..." button in the install4j IDE that brings up the dialog with the property customizer.
- Returns:
- the property customizer class or
null
-
-