com.vaadin.addon.jpacontainer.fieldfactory
Class PropertyTranslator

java.lang.Object
  extended by com.vaadin.data.util.AbstractProperty
      extended by com.vaadin.addon.jpacontainer.fieldfactory.PropertyTranslator
All Implemented Interfaces:
com.vaadin.data.Property, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer, Serializable
Direct Known Subclasses:
ListTranslator

public abstract class PropertyTranslator
extends com.vaadin.data.util.AbstractProperty
implements com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.Viewer

PropertyTranslator is bit like the PropertyFormatter, but works also for other than string fields.

Typical use case is where you have a select whose value is an Entity, but the container datasource used in the select uses a different identifier (most commonly entity id in database).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractProperty
com.vaadin.data.util.AbstractProperty.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyException, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.Transactional<T>, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer
 
Constructor Summary
protected PropertyTranslator()
          Construct a new PropertyTranslator that is not connected to any data source.
  PropertyTranslator(com.vaadin.data.Property propertyDataSource)
          Construct a new translator that is connected to given data source.
 
Method Summary
 com.vaadin.data.Property getPropertyDataSource()
          Gets the current data source of the translator, if any.
 Class getType()
           
 Object getValue()
          Get the translated value.
 boolean isReadOnly()
          Reflects the read-only status of the datasource.
 void readOnlyStatusChange(com.vaadin.data.Property.ReadOnlyStatusChangeEvent event)
          Listens for changes in the datasource.
 void setPropertyDataSource(com.vaadin.data.Property newDataSource)
          Sets the specified Property as the data source for the translator.
 void setReadOnly(boolean newStatus)
          Sets the Property's read-only mode to the specified status.
 void setValue(Object newValue)
           
 String toString()
          Get the translated value as string.
abstract  Object translateFromDatasource(Object value)
          This method must be implemented to translate the value received from DataSource.
abstract  Object translateToDatasource(Object formattedValue)
          This method is used by setValue() method to translate given value to be suitable for the datasource.
 void valueChange(com.vaadin.data.Property.ValueChangeEvent event)
          Listens for changes in the datasource.
 
Methods inherited from class com.vaadin.data.util.AbstractProperty
addListener, addListener, addReadOnlyStatusChangeListener, addValueChangeListener, fireReadOnlyStatusChange, fireValueChange, getListeners, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValueChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyTranslator

protected PropertyTranslator()
Construct a new PropertyTranslator that is not connected to any data source. Call setPropertyDataSource(Property) later on to attach it to a property.


PropertyTranslator

public PropertyTranslator(com.vaadin.data.Property propertyDataSource)
Construct a new translator that is connected to given data source. Calls translateFromDatasource(Object) which can be a problem if the formatter has not yet been initialized.

Parameters:
propertyDataSource - to connect this property to.
Method Detail

getPropertyDataSource

public com.vaadin.data.Property getPropertyDataSource()
Gets the current data source of the translator, if any.

Specified by:
getPropertyDataSource in interface com.vaadin.data.Property.Viewer
Returns:
the current data source as a Property, or null if none defined.

setPropertyDataSource

public void setPropertyDataSource(com.vaadin.data.Property newDataSource)
Sets the specified Property as the data source for the translator.

Specified by:
setPropertyDataSource in interface com.vaadin.data.Property.Viewer
Parameters:
newDataSource - the new data source Property.

getType

public Class getType()
Specified by:
getType in interface com.vaadin.data.Property

getValue

public Object getValue()
Get the translated value.

Specified by:
getValue in interface com.vaadin.data.Property
Returns:
the translated value

toString

public String toString()
Get the translated value as string.

Overrides:
toString in class com.vaadin.data.util.AbstractProperty
Returns:
If the datasource returns null, this is null. Otherwise this is translateFromDatasource.toString().

isReadOnly

public boolean isReadOnly()
Reflects the read-only status of the datasource.

Specified by:
isReadOnly in interface com.vaadin.data.Property
Overrides:
isReadOnly in class com.vaadin.data.util.AbstractProperty

translateFromDatasource

public abstract Object translateFromDatasource(Object value)
This method must be implemented to translate the value received from DataSource.

Parameters:
value - Value object got from the datasource. This is guaranteed to be non-null and of the type compatible with getType() of the datasource.
Returns:

translateToDatasource

public abstract Object translateToDatasource(Object formattedValue)
                                      throws Exception
This method is used by setValue() method to translate given value to be suitable for the datasource. The method is required to assure that translateToDatasource(translateFromDatasource(x)) equals x.

Parameters:
translatedValue - this is the value set by user of the formatter (typically field).
Returns:
Non-null value compatible with datasource.
Throws:
Exception - Any type of exception can be thrown to indicate that the conversion was not succesful.

setReadOnly

public void setReadOnly(boolean newStatus)
Sets the Property's read-only mode to the specified status.

Specified by:
setReadOnly in interface com.vaadin.data.Property
Overrides:
setReadOnly in class com.vaadin.data.util.AbstractProperty
Parameters:
newStatus - the new read-only status of the Property.

setValue

public void setValue(Object newValue)
              throws com.vaadin.data.Property.ReadOnlyException,
                     com.vaadin.data.util.converter.Converter.ConversionException
Specified by:
setValue in interface com.vaadin.data.Property
Throws:
com.vaadin.data.Property.ReadOnlyException
com.vaadin.data.util.converter.Converter.ConversionException

valueChange

public void valueChange(com.vaadin.data.Property.ValueChangeEvent event)
Listens for changes in the datasource. This should not be called directly.

Specified by:
valueChange in interface com.vaadin.data.Property.ValueChangeListener

readOnlyStatusChange

public void readOnlyStatusChange(com.vaadin.data.Property.ReadOnlyStatusChangeEvent event)
Listens for changes in the datasource. This should not be called directly.

Specified by:
readOnlyStatusChange in interface com.vaadin.data.Property.ReadOnlyStatusChangeListener


Copyright © 2013 Vaadin Ltd. All rights reserved.