de.matthiasmann.twl.model
Class SimpleProperty<T>

java.lang.Object
  extended by de.matthiasmann.twl.model.AbstractProperty<T>
      extended by de.matthiasmann.twl.model.SimpleProperty<T>
Type Parameters:
T - the type of the property value
All Implemented Interfaces:
Property<T>

public class SimpleProperty<T>
extends AbstractProperty<T>

A simple implementation of a property


Constructor Summary
SimpleProperty(java.lang.Class<T> type, java.lang.String name, T value)
           
SimpleProperty(java.lang.Class<T> type, java.lang.String name, T value, boolean readOnly)
           
 
Method Summary
 boolean canBeNull()
          Returns true if this property can be set to null.
 java.lang.String getName()
          The property name as displayed in the UI
 T getPropertyValue()
          Retrieves the current property value
 java.lang.Class<T> getType()
          Returns the type of the property.
 boolean isReadOnly()
          Returns true if this property is read only.
 void setPropertyValue(T value)
          Changes the property value.
 void setReadOnly(boolean readOnly)
           
protected  boolean valueChanged(T newValue)
          This method is used by setPropertyValue to check if the callback should be fired or not The default implementation calls equals on the current value.
 
Methods inherited from class de.matthiasmann.twl.model.AbstractProperty
addValueChangedCallback, fireValueChangedCallback, hasValueChangedCallbacks, removeValueChangedCallback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleProperty

public SimpleProperty(java.lang.Class<T> type,
                      java.lang.String name,
                      T value)

SimpleProperty

public SimpleProperty(java.lang.Class<T> type,
                      java.lang.String name,
                      T value,
                      boolean readOnly)
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Property
The property name as displayed in the UI

Returns:
the property name

isReadOnly

public boolean isReadOnly()
Description copied from interface: Property
Returns true if this property is read only. Calling the setValue() method on a read only property is undefined.

Returns:
true if this property is read only

setReadOnly

public void setReadOnly(boolean readOnly)

canBeNull

public boolean canBeNull()
Description copied from interface: Property
Returns true if this property can be set to null. This is similar to a SQL null.

Returns:
true if this property can be null

getPropertyValue

public T getPropertyValue()
Description copied from interface: Property
Retrieves the current property value

Returns:
the current property value

setPropertyValue

public void setPropertyValue(T value)
                      throws java.lang.IllegalArgumentException
Changes the property value. It calls valueChanged to determine if the value has really changed and if so updates the value and calls the callbacks.

Parameters:
value - the new value for the property
Throws:
java.lang.IllegalArgumentException - is not thrown but part of the Property interface
java.lang.NullPointerException - if value is null and canBeNull returned false
See Also:
canBeNull(), valueChanged(java.lang.Object)

getType

public java.lang.Class<T> getType()
Description copied from interface: Property
Returns the type of the property. This is used to select an editor widget in the PropertySheet.

Returns:
The class of the property values

valueChanged

protected boolean valueChanged(T newValue)
This method is used by setPropertyValue to check if the callback should be fired or not The default implementation calls equals on the current value.

Parameters:
newValue - the new value passed to setPropertyValue
Returns:
true if the value has changed and the callback should be fired