public class PropertyBase<T, K>

  1. Object
  2. PropertyBase

Known subtypesCollectionProperty, MapProperty, Property

Base class for property types

Constructors

protected PropertyBase(String name)All properties must have a name
protected PropertyBase(String name, Class genericType)All properties must have a name, a generic type is helpful

Methods

public static void bindGlobalSetListener(PropertyChangeListener listener)Deprecated Binds an event callback for set calls and property mutation
public static void bindGlobalGetListener(PropertyChangeListener listener)Deprecated Binds an event callback for get calls and property reads
public String getName()The property name is immutable and can’t be changed after creation it should match the parent field name by convention
protected void firePropertyChanged()Delivers the property change event to listeners if applicable
public void stopListening()This method will work when invoked from a propertyChanged callback and should be similar to removePropertyChangeListener(this).
public void addChangeListener(PropertyChangeListener<T, K> pl)Fires a notification that a property value changed to the given listener
public void removeChangeListener(PropertyChangeListener<T, K> pl)Removes the property change listener from the list of listeners
public void putClientProperty(String key, Object o)Places a property that will apply statically to all instances of this property
public Object getClientProperty(String key)Returns the client property set to this property name
public boolean equals(Object obj)Compares this property to another property
public int hashCode()Returns a hash code value for the object.
public String toString()Default toString that provides easier debug information
public Class getGenericType()Returns the generic type of this property if it is known or null
public String getLabel()The label of the property defaults to its name but can be changed to anything
public void setLabel(String label)The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements
protected final void validateCollectionType(Class elementType)Validates that the collection type is valid and throws an exception otherwise

Inherited methods

Constructor details

PropertyBase

protected PropertyBase(String name)
All properties must have a name

Parameters

name String
the name of the property

PropertyBase

protected PropertyBase(String name, Class genericType)
All properties must have a name, a generic type is helpful

Parameters

name String
the name of the property
genericType Class
the property type to workaround issues with erasure

Method details

bindGlobalSetListener

public static void bindGlobalSetListener(PropertyChangeListener listener)
Deprecated. Usage of this method isn’t recommended, it’s designed for internal use
Binds an event callback for set calls and property mutation

Parameters

listener PropertyChangeListener
will be invoked whenever any mutable property is changed

Throws

RuntimeException
if a set listener is already bound, there can be only one per application

bindGlobalGetListener

public static void bindGlobalGetListener(PropertyChangeListener listener)
Deprecated. Usage of this method isn’t recommended, it’s designed for internal use
Binds an event callback for get calls and property reads

Parameters

listener PropertyChangeListener
will be invoked whenever any property is read

Throws

RuntimeException
if a get listener is already bound, there can be only one per application

getName

public String getName()
The property name is immutable and can’t be changed after creation it should match the parent field name by convention

Returns

the property name;

firePropertyChanged

protected void firePropertyChanged()
Delivers the property change event to listeners if applicable

stopListening

public void stopListening()
This method will work when invoked from a propertyChanged callback and should be similar to removePropertyChangeListener(this). It’s useful for lambda’s where this means the base class and not the listener so removePropertyChangeListener(this) won’t do what we want unless we convert to an inner class

addChangeListener

public void addChangeListener(PropertyChangeListener<T, K> pl)
Fires a notification that a property value changed to the given listener

Parameters

pl PropertyChangeListener<T, K>
the listener

removeChangeListener

public void removeChangeListener(PropertyChangeListener<T, K> pl)
Removes the property change listener from the list of listeners

Parameters

pl PropertyChangeListener<T, K>
the change listener

putClientProperty

public void putClientProperty(String key, Object o)
Places a property that will apply statically to all instances of this property

Parameters

key String
the key to put
o Object
the value object

getClientProperty

public Object getClientProperty(String key)
Returns the client property set to this property name

Parameters

key String
the key of the property

Returns

the value that was previously placed with put client property

equals

public boolean equals(Object obj)
Compares this property to another property

Parameters

obj Object
the other property

Returns

true if they are equal in name and value

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

toString

public String toString()
Default toString that provides easier debug information

Returns

a formatted representation of the property for debugging

getGenericType

public Class getGenericType()
Returns the generic type of this property if it is known or null

Returns

the generic type

getLabel

public String getLabel()
The label of the property defaults to its name but can be changed to anything

Returns

the label for the property

setLabel

public void setLabel(String label)
The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements

Parameters

label String
the new label value

validateCollectionType

protected final void validateCollectionType(Class elementType)
Validates that the collection type is valid and throws an exception otherwise

Parameters

elementType Class
the generic type of the collection