|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.itmill.toolkit.data.util.PropertyFormatter
public abstract class PropertyFormatter
Formatting proxy for a property.
This class can be used to implement formatting for any type of Property datasources. The idea is to connect this as proxy between UI component and the original datasource.
For example
textfield.setPropertyDataSource(new PropertyFormatter(property) {
public String format(Object value) {
return ((Double) value).toString() + "000000000";
}
public Object parse(String formattedValue) throws Exception {
return Double.parseDouble(formattedValue);
}
});
adds formatter for Double-typed property that extends standard
"1.0" notation with more zeroes.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Property |
---|
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer |
Constructor Summary | |
---|---|
PropertyFormatter(Property propertyDataSource)
Construct a new formatter that is connected to given datasource. |
Method Summary | |
---|---|
void |
addListener(Property.ReadOnlyStatusChangeListener listener)
Registers a new read-only status change listener for this Property. |
void |
addListener(Property.ValueChangeListener listener)
Registers a new value change listener for this ObjectProperty. |
abstract String |
format(Object value)
This method must be implemented to format the values received from DataSource. |
Property |
getPropertyDataSource()
Gets the current data source of the formatter, if any. |
Class |
getType()
Returns the type of the Property. |
Object |
getValue()
Get the formatted value. |
boolean |
isReadOnly()
Reflects the read-only status of the datasource. |
abstract Object |
parse(String formattedValue)
Parse string and convert it to format compatible with datasource. |
void |
readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event)
Listens for changes in the datasource. |
void |
removeListener(Property.ReadOnlyStatusChangeListener listener)
Removes a previously registered read-only status change listener. |
void |
removeListener(Property.ValueChangeListener listener)
Removes a previously registered value change listener. |
void |
setPropertyDataSource(Property newDataSource)
Sets the specified Property as the data source for the formatter. |
void |
setReadOnly(boolean newStatus)
Sets the Property's read-only mode to the specified status. |
void |
setValue(Object newValue)
Sets the value of the Property. |
String |
toString()
Get the formatted value. |
void |
valueChange(Property.ValueChangeEvent event)
Listens for changes in the datasource. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PropertyFormatter(Property propertyDataSource)
propertyDataSource
- to connect this property to.Method Detail |
---|
public Property getPropertyDataSource()
null
if
none defined.public void setPropertyDataSource(Property newDataSource)
Remember that new data sources getValue() must return objects that are compatible with parse() and format() methods.
newDataSource
- the new data source Property.public Class getType()
Property
getValue
and
setValue
must be compatible with this type: one must be able
to safely cast the value returned from getValue
to the given
type and pass any variable assignable to this type as an argument to
setValue
.
getType
in interface Property
public Object getValue()
getValue
in interface Property
public String toString()
toString
in interface Property
toString
in class Object
public boolean isReadOnly()
isReadOnly
in interface Property
true
if the Property is in read-only mode,
false
if it's notpublic abstract String format(Object value)
value
- Value object got from the datasource. This is guaranteed to be
non-null and of the type compatible with getType() of the
datasource.
public abstract Object parse(String formattedValue) throws Exception
formattedValue
- This is guaranteed to be non-null string.
Exception
- Any type of exception can be thrown to indicate that the
conversion was not succesful.public void setReadOnly(boolean newStatus)
setReadOnly
in interface Property
newStatus
- the new read-only status of the Property.public void setValue(Object newValue) throws Property.ReadOnlyException, Property.ConversionException
Property
Implementing this functionality is optional. If the functionality is
missing, one should declare the Property to be in read-only mode and
throw Property.ReadOnlyException
in this function.
String
in addition to the native type of the
Property (as given by the getType
method). If the
String
conversion fails or is unsupported, the method should
throw Property.ConversionException
. The string conversion
should at least understand the format returned by the
toString
method of the Property.
setValue
in interface Property
newValue
- New value of the Property. This should be assignable to the
type returned by getType, but also String type should be
supported
Property.ReadOnlyException
- if the object is in read-only mode
Property.ConversionException
- if newValue can't be converted into the Property's native
type directly or through Stringpublic void removeListener(Property.ValueChangeListener listener)
removeListener
in interface Property.ValueChangeNotifier
listener
- the listener to be removed.public void addListener(Property.ValueChangeListener listener)
addListener
in interface Property.ValueChangeNotifier
listener
- the new Listener to be registeredpublic void addListener(Property.ReadOnlyStatusChangeListener listener)
addListener
in interface Property.ReadOnlyStatusChangeNotifier
listener
- the new Listener to be registeredpublic void removeListener(Property.ReadOnlyStatusChangeListener listener)
removeListener
in interface Property.ReadOnlyStatusChangeNotifier
listener
- the listener to be removed.public void valueChange(Property.ValueChangeEvent event)
valueChange
in interface Property.ValueChangeListener
event
- value change event objectpublic void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event)
readOnlyStatusChange
in interface Property.ReadOnlyStatusChangeListener
event
- Read-only status change event object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |