public class BeanSupport extends java.lang.Object implements GPBean
This support class provides the necessary methods to register a listener and provides methods to send PropertyChangeEvents. The bean can use the protected methods to fire events each time a property changes.
In order to be represented by a node, the bean can provide extra information that is not directly related to the
business of the bean but that is nevertheless interesting to control the node. The bean can provide that information
through its BeanInfo or through specific getters (defined in the interface GPNode). The
information provided can be static or dynamic. It is static if the value is just given once when the node is created,
it is dynamic if the bean allow the node to register itself as PropertyChangeListener and fire events
when those properties changes.
The list of properties recognized by the node and associated getters is given by the GPBean interface.
This support class implements all the getter methods in GPNode by returning a null value. You should
override each method you want to provide information for. For each property that can be dynamically updated there is
a protected method in this class you can use to fire an event to update the value. Here is the list :
| property name | method name | method to fire related event |
| name | getName() |
fireNamePropertyChange() |
| displayName | getDisplayName() |
fireDisplayNamePropertyChange() |
| shortDescription | getShortDescription() |
fireShortDescriptionPropertyChange() |
| nodeDefaultAction | getNodeDefaultAction() |
fireNodeDefaultActionPropertyChange() |
| nodeIcon | getNodeIcon |
fireNodeIconPropertyChange() |
If the bean fire a given event, it should provide the getter matching the PropertyChangeEvent that
it fires. For instance if the bean call the protected method fireNamePropertyChange when a
name change occurs, it should have the matching getter getName() implemented and returning a non null
value.
When a given getter is not available in this bean, the corresponding information will be looked-up in the
BeanInfo. It will only be static, because the BeanInfo provides static information common to all beans.
There is only one BeanInfo for a given class of beans and therefore the information founds inside the BeanInfo is
shared by all beans of that class. If the BeanInfo does not contain the information, a standard default
value will be applied when possible.
CLASS_PROPERTY_NAME, DISPLAYNAME_PROPERTY_DISPLAY_NAME, DISPLAYNAME_PROPERTY_NAME, NAME_PROPERTY_DISPLAY_NAME, NAME_PROPERTY_NAME, NODE_ACTIONS_PROPERTY_NAME, NODE_DEFAULT_ACTION_PROPERTY_NAME, NODE_ICON_PROPERTY_NAME, NODE_PROPERTIES_CACHEABLE_PROPERTY_NAME, PROPERTY_INFO_PROPERTY_NAME, SHORTDESCRIPTION_PROPERTY_DISPLAY_NAME, SHORTDESCRIPTION_PROPERTY_NAME| Modifier | Constructor and Description |
|---|---|
protected |
BeanSupport() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
|
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.
|
protected void |
checkPropertyChangeSupport()
Lazily creates the PropertyChangeSupport
|
protected void |
fireDisplayNamePropertyChange(java.lang.String newDisplayName)
Reports a DisplayName property update to any registered listeners.
|
protected void |
fireNamePropertyChange(java.lang.String newName)
Reports a Name property update to any registered listeners.
|
protected void |
fireNodeDefaultActionPropertyChange(java.lang.String newDefaultAction)
Reports a default action property update to any registered listeners.
|
protected void |
fireNodeIconPropertyChange(java.awt.Image newIcon)
Reports a icon property update to any registered listeners.
|
protected void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Reports a bound property update to any registered listeners.
|
protected void |
fireShortDescriptionPropertyChange(java.lang.String newShortDescription)
Reports a ShortDescription property update to any registered listeners.
|
java.lang.String |
getDisplayName()
Returns the internal display name of the associated bean.
|
java.lang.String |
getName()
Returns the internal name of the associated bean.
|
java.lang.String[] |
getNodeActions()
Returns an array of qualified name of actions for the node representing the associated bean.
|
java.lang.String |
getNodeDefaultAction()
Returns the qualified name of the default action for the node representing the associated bean.
|
java.awt.Image |
getNodeIcon()
Returns the icon in 16x16 size used to display the node representing the associated bean.
|
protected java.awt.Image |
getNodeIconFromPathname(java.lang.String newIconPathname)
Returns the icon image from the pathname of the icon.
|
java.lang.Boolean |
getNodePropertiesCacheable()
Returns true if the value of the properties can be cached in the node, false if they cannot or null if no behavior
is specified.
|
PropertyInfo[] |
getPropertyInfo()
Returns an array of
PropertyInfo specifying information on some properties. |
java.lang.String |
getShortDescription()
Returns a short description of the associated bean (used in tooltip for instance).
|
protected static java.lang.String[] |
mergeNodeActions(java.lang.String[] actions1,
java.lang.String[] actions2)
Merges the two
String arrays into one. |
protected static PropertyInfo[] |
mergePropertyInfo(PropertyInfo[] info1,
PropertyInfo[] info2)
Merges the two
PropertyInfo arrays into one. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property.
|
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property.
|
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener - The PropertyChangeListener to be addedpublic void addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
listener - The PropertyChangeListener to be removedpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
propertyName - The name of the property to listen on.listener - The PropertyChangeListener to be addedpublic void removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
propertyName - The name of the property that was listened on.listener - The PropertyChangeListener to be removedpublic java.lang.String getDisplayName()
GPBeandisplayNamenormal (visible in a property sheet)if getName() is available it is used instead of
getDisplayName(), else beanInfo.getBeanDescriptor().getDisplayName() is usedgetDisplayName in interface GPBeanpublic java.lang.String getName()
GPBeannamenormal (visible in a property sheet)a unique name generated using BeanUtils.
generateUniqueBeanName()
public java.lang.String[] getNodeActions()
GPBeannodeActionshidden (not visible in a property sheet)use the possible tagging of the BeanDescriptor
of the BeanInfo : BeanTagger.getActions(beanInfo.getBeanDescriptor())getNodeActions in interface GPBeanpublic java.lang.String getNodeDefaultAction()
GPBeannodeDefaultActionhiddenuse the possible tagging of the BeanDescriptor
of the BeanInfo : BeanTagger.getDefaultAction(beanInfo.getBeanDescriptor())getNodeDefaultAction in interface GPBeanpublic java.awt.Image getNodeIcon()
GPBeannodeIconhidden (not visible in a property sheet)beanInfo.getIcon()getNodeIcon in interface GPBeanpublic java.lang.Boolean getNodePropertiesCacheable()
GPBeanIf the value of a property is not cached, the getter method will be invoked whenever the node need to get the value of the property.
If the value of the property is cached, the getter method for the property will only be invoked
once to read the value. Then, whenever the node need the value of the property it will used the cached
one until a PropertyChangeEvent for the property (or for all properties) is fired.
Caching values can improve performance greatly but it adds one more responsibility on the developer
who has to fire PropertyChangeEvent whenever the property values change.
This property gives the caching strategy for all properties. It is possible to override the bean level caching
strategy at the property level by using the property information getPropertyInformation().
nodePropertiesCacheablehidden (not visible in a property sheet)use the possible tagging of the BeanDescriptor
of the BeanInfo : BeanTagger.isCacheable(beanInfo.getBeanDescriptor())getNodePropertiesCacheable in interface GPBeanpublic java.lang.String getShortDescription()
GPBeanshortDescriptionnormal (visible in a property sheet)beanInfo.getBeanDescriptor().
getShortDescription()getShortDescription in interface GPBeanpublic PropertyInfo[] getPropertyInfo()
GPBeanPropertyInfo specifying information on some properties.
Each PropertyInfo of this array defines information for one property of this bean. Defining a
PropertyInfo for a given property is usefull when there is no explicit BeanInfo for the
bean and when the property have non default characteristics such as, for instance, a specific
PropertyEditor.
propertyInfohidden (not visible in a property sheet)use PropertyDescriptors from
BeanInfogetPropertyInfo in interface GPBeanprotected void firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
propertyName - The programmatic name of the property that was changed.oldValue - The old value of the property.newValue - The new value of the property.protected void fireNamePropertyChange(java.lang.String newName)
newName - The new value of the name.protected void fireDisplayNamePropertyChange(java.lang.String newDisplayName)
newDisplayName - The new value of the DisplayName.protected void fireShortDescriptionPropertyChange(java.lang.String newShortDescription)
newShortDescription - The new value of the ShortDescription.protected void fireNodeIconPropertyChange(java.awt.Image newIcon)
newIcon - The new value of the icon.getNodeIconFromPathname(String)protected void fireNodeDefaultActionPropertyChange(java.lang.String newDefaultAction)
newDefaultAction - The new value of the default action.protected java.awt.Image getNodeIconFromPathname(java.lang.String newIconPathname)
The pathname should be relative to the package of this bean and be contained in the classpath.
For instance if this bean is in cern.gp.beans and the icon is stored in
cern/gp/beans/images/MyIcon.gif the pathname to give would be
images/MyIcon.gif.
newIconPathname - The new value of the Icon pathname.protected static java.lang.String[] mergeNodeActions(java.lang.String[] actions1,
java.lang.String[] actions2)
String arrays into one. This method is useful when a class inherits from another that
already has a method getNodeActions that returned an array of String. If the subclass
wants to return a String array while taking into account the one from the parent class it can use this
method. For instance :
String[] parentArray= super.getNodeActions();
String[] myArray = new String [] { .... };
return mergePropertyInfo(parentPI, myPI);
actions1 - the first array of String to mergeactions2 - the second array of String to mergeprotected static PropertyInfo[] mergePropertyInfo(PropertyInfo[] info1, PropertyInfo[] info2)
PropertyInfo arrays into one. This method is useful when a class inherits from another
that already has a method getPropertyInfo that returned an array of PropertyInfo. If the
subclass wants to return PropertyInfo while taking into account the one from the parent class it can
use this method. For instance :
PropertyInfo[] parentPI = super.getPropertyInfo();
PropertyInfo[] myPI = new PropertyInfo[] { .... };
return mergePropertyInfo(parentPI, myPI);
info1 - the first array of PropertyInfo to mergeinfo2 - the second array of PropertyInfo to mergeprotected void checkPropertyChangeSupport()