Java Doc for BeanAdapter.java in  » Swing-Library » jgoodies-data-binding » com » jgoodies » binding » beans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jgoodies data binding » com.jgoodies.binding.beans 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.jgoodies.binding.beans.Model
      com.jgoodies.binding.beans.BeanAdapter

BeanAdapter
public class BeanAdapter extends Model (Code)
Converts multiple Java Bean properties into ValueModels. The bean properties must be single valued properties as described by the Java Bean Specification. See below for a comparison with the more frequently used PresentationModel class and the rarely used PropertyAdapter.

ValueModels can be created for a property name using BeanAdapter.getValueModel(String) or for a triple of (property name, getter name, setter name) using BeanAdapter.getValueModel(String,String,String) . If you just specify the property name, the adapter uses the standard Java Bean introspection to lookup the available properties and how to read and write the property value. In case of custom readers and writers you may specify a custom BeanInfo class, or as a shortcut use the method that accepts the optional getter and setter name. If these are specified, introspection will be bypassed and a PropertyDescriptor will be created for the given property name, getter and setter name. Note: For each property name subsequent calls to these methods must use the same getter and setter names. Attempts to violate this constraint are rejected with an IllegalArgumentException.

Property values for a given property name can be read using BeanAdapter.getValue(String) . To set a value for a for a property name invoke BeanAdapter.setValue(String,Object) .

Optionally the BeanAdapter can observe changes in bound properties as described in section 7.4 of the Bean specification. The bean then must provide support for listening on properties as described in section 7.4 of this specification. You can enable this feature by setting the constructor parameter observeChanges to true. If the adapter observes changes, the ValueModels returned by #getValueModel will fire value change events, i.e. PropertyChangeEvents for the property "value". Even if you ignore property changes, you can access the adapted property value via #getValue(). It's just that you won't be notified about changes.

In addition you can observe the bean's bound properties by registering PropertyChangeListeners with the bean using #addBeanPropertyChangeListener. These listeners will be removed from the old bean before the bean changes and will be re-added after the new bean has been set. Therefore these listeners will be notified about changes only if the current bean changes a property. They won't be notified if the bean changes - and in turn the property value. If you want to observes property changes caused by bean changes too, register with the adapting ValueModel as returned by #getValueModel(String).

The BeanAdapter provides two access styles to the target bean that holds the adapted property: you can specify a bean directly, or you can use a bean channel to access the bean indirectly. In the latter case you specify a ValueModel that holds the bean that in turn holds the adapted properties.

If the adapted bean is null the BeanAdapter can neither read nor set a value. In this case #getValue returns null and #setValue will silently ignore the new value.

This adapter throws three PropertyChangeEvents if the bean changes: beforeBean, bean and afterBean. This is useful when sharing a bean channel and you must perform an operation before or after other listeners handle a bean change. Since you cannot rely on the order listeners will be notified, only the beforeBean and afterBean events are guaranteed to be fired before and after the bean change is fired. Note that #getBean() returns the new bean before any of these three PropertyChangeEvents is fired. Therefore listeners that handle these events must use the event's old and new value to determine the old and new bean. The order of events fired during a bean change is:

  1. this adapter's bean channel fires a value change,
  2. this adapter fires a beforeBean change,
  3. this adapter fires the bean change,
  4. this adapter fires an afterBean change.

Note: BeanAdapters that observe changes have a PropertyChangeListener registered with the target bean. Hence, a bean has a reference to any BeanAdapter that observes it. To avoid memory leaks it is recommended to remove this listener if the bean lives much longer than the BeanAdapter, enabling the garbage collector to remove the adapter. To do so, you can call setBean(null) or set the bean channel's value to null. As an alternative you can use event listener lists in your beans that implement references with WeakReference.

Setting the bean to null has side-effects, for example the adapter fires a change event for the bound property bean and other properties. And the value of ValueModel's vended by this adapter may change. However, typically this is fine and setting the bean to null is the first choice for removing the reference from the bean to the adapter. Another way to clear the reference from the target bean is to call #release. It has no side-effects, but the adapter must not be used anymore once #release has been called.

Constraints: If property changes shall be observed, the bean class must support bound properties, i. e. it must provide the following pair of methods for registration of multicast property change event listeners:

 public void addPropertyChangeListener(PropertyChangeListener x);
 public void removePropertyChangeListener(PropertyChangeListener x);
 
PropertyAdapter vs. BeanAdapter vs. PresentationModel
Basically the BeanAdapter does for multiple properties what the com.jgoodies.binding.beans.PropertyAdapter does for a single bean property. If you adapt multiple properties of the same bean, you better use the BeanAdapter. It registers a single PropertyChangeListener with the bean, where multiple PropertyAdapters would register multiple listeners. If you adapt bean properties for an editor, you will typically use the com.jgoodies.binding.PresentationModel . The PresentationModel is more powerful than the BeanAdapter. It adds support for buffered models, and provides an extensible mechanism for observing the change state of the bean and related objects.

Basic Examples:

 // Direct access, ignores changes
 Address address = new Address()
 BeanAdapter adapter = new BeanAdapter(address);
 adapter.setValue("street", "Broadway");
 System.out.println(address.getStreet());        // Prints "Broadway"
 address.setStreet("Franz-Josef-Str.");
 System.out.println(adapter.getValue("street")); // Prints "Franz-Josef-Str."
 //Direct access, observes changes
 BeanAdapter adapter = new BeanAdapter(address, true);
 // Indirect access, ignores changes
 ValueHolder addressHolder = new ValueHolder(address1);
 BeanAdapter adapter = new BeanAdapter(addressHolder);
 adapter.setValue("street", "Broadway");         // Sets the street in address1
 System.out.println(address1.getStreet());       // Prints "Broadway"
 adapter.setBean(address2);
 adapter.setValue("street", "Robert-Koch-Str."); // Sets the street in address2
 System.out.println(address2.getStreet());       // Prints "Robert-Koch-Str."
 // Indirect access, observes changes
 ValueHolder addressHolder = new ValueHolder();
 BeanAdapter adapter = new BeanAdapter(addressHolder, true);
 addressHolder.setValue(address1);
 address1.setStreet("Broadway");
 System.out.println(adapter.getValue("street")); // Prints "Broadway"
 // Access through ValueModels
 Address address = new Address();
 BeanAdapter adapter = new BeanAdapter(address);
 ValueModel streetModel = adapter.getValueModel("street");
 ValueModel cityModel   = adapter.getValueModel("city");
 streetModel.setValue("Broadway");
 System.out.println(address.getStreet());        // Prints "Broadway"
 address.setCity("Hamburg");
 System.out.println(cityModel.getValue());       // Prints "Hamburg"
 
Adapter Chain Example:
Builds an adapter chain from a domain model to the presentation layer.
 Country country = new Country();
 country.setName("Germany");
 country.setEuMember(true);
 BeanAdapter countryAdapter = new BeanAdapter(country, true);
 JTextField nameField = new JTextField();
 nameField.setDocument(new DocumentAdapter(
 countryAdapter.getValueModel("name")));
 JCheckBox euMemberBox = new JCheckBox("Is EU Member");
 euMemberBox.setModel(new ToggleButtonAdapter(
 countryAdapter.getValueModel("euMember")));
 // Using factory methods
 JTextField nameField   = Factory.createTextField(country, "name");
 JCheckBox  euMemberBox = Factory.createCheckBox (country, "euMember");
 euMemberBox.setText("Is EU Member");
 

As of version 1.3 this class is no longer marked as final, but lacks the documentation for subclass constraints. I plan to introduce an interface that shall describe the semantics required by the PresentationModel class. Until then, this BeanAdapter implementation describes the semantics and all constraints.

TODO: Improve the class comment and focus on the main features.

TODO: Consider adding a feature to ensure that update notifications are performed in the event dispatch thread. In case the adapted bean is changed in a thread other than the event dispatch thread, such a feature would help complying with Swing's single thread rule. The feature could be implemented by an extended PropertyChangeSupport.

TODO: I plan to improve the support for adapting beans that do not fire PropertyChangeEvents. This affects the classes PropertyAdapter, BeanAdapter, and PresentationModel. Basically the PropertyAdapter and the BeanAdapter's internal SimplePropertyAdapter's shall be able to optionally self-fire a PropertyChangeEvent in case the bean does not. There are several downsides with self-firing events compared to bound bean properties. See Issue 49 for more information about the downsides.

The observeChanges constructor parameter shall be replaced by a more fine-grained choice to not observe (former observeChanges=false), to observe bound properties (former observeChanges=true), and a new setting for self-firing PropertyChangeEvents if a value is set. The latter case may be further splitted up to specify how the self-fired PropertyChangeEvent is created:

  1. oldValue=null, newValue=null
  2. oldValue=null, newValue=the value set
  3. oldValue=value read before the set, newValue=the value set
  4. oldValue=value read before the set, newValue=value read after the set

author:
   Karsten Lentzsch
version:
   $Revision: 1.24 $
See Also:   com.jgoodies.binding.beans.PropertyAdapter
See Also:   ValueModel
See Also:   ValueModel.getValue
See Also:   ValueModel.setValue(Object)
See Also:   PropertyChangeEvent
See Also:   PropertyChangeListener
See Also:   java.beans.Introspector
See Also:   java.beans.BeanInfo
See Also:   PropertyDescriptor<
Parameters:
  B - > the type of the bean managed by this BeanAdapter

Inner Class :public class SimplePropertyAdapter extends AbstractValueModel

Field Summary
final public static  StringPROPERTYNAME_AFTER_BEAN
     The property name used in the PropertyChangeEvent that is fired after the bean property fires its PropertyChangeEvent. Useful to perform an operation after listeners that handle the bean change are notified.
final public static  StringPROPERTYNAME_BEAN
     The name of the read-write bound property that holds the target bean.
final public static  StringPROPERTYNAME_BEFORE_BEAN
     The property name used in the PropertyChangeEvent that is fired before the bean property fires its PropertyChangeEvent. Useful to perform an operation before listeners that handle the bean change are notified.
final public static  StringPROPERTYNAME_CHANGED
     The name of the read-only bound bean property that indicates whether one of the observed properties has changed.
 BstoredOldBean
     Refers to the old bean.

Constructor Summary
public  BeanAdapter(B bean)
     Constructs a BeanAdapter for the given bean; does not observe changes.

Installs a default bean channel that checks the identity not equity to ensure that listeners are reregistered properly if the old and new bean are equal but not the same.

public  BeanAdapter(B bean, boolean observeChanges)
     Constructs a BeanAdapter for the given bean; observes changes if specified.

Installs a default bean channel that checks the identity not equity to ensure that listeners are reregistered properly if the old and new bean are equal but not the same.
Parameters:
  bean - the bean that owns the properties to adapt
Parameters:
  observeChanges - true to observe changes of boundor constrained properties, false to ignore changes
throws:
  PropertyUnboundException - if observeChangesis true but the property is unbound, i.

public  BeanAdapter(ValueModel beanChannel)
     Constructs a BeanAdapter for the given bean channel; does not observe changes.

It is strongly recommended that the bean channel checks the identity not equity.

public  BeanAdapter(ValueModel beanChannel, boolean observeChanges)
     Constructs a BeanAdapter for the given bean channel; observes changes if specified.

It is strongly recommended that the bean channel checks the identity not equity.


Method Summary
public synchronized  voidaddBeanPropertyChangeListener(PropertyChangeListener listener)
     Adds a PropertyChangeListener to the list of bean listeners.
public synchronized  voidaddBeanPropertyChangeListener(String propertyName, PropertyChangeListener listener)
     Adds a PropertyChangeListener to the list of bean listeners for a specific property.
protected  SimplePropertyAdaptercreatePropertyAdapter(String propertyName, String getterName, String setterName)
     Creates and returns a SimplePropertyAdapter that adapts the bound property with the specified name.
public  BgetBean()
     Returns the Java Bean that holds the adapted properties.
public  ValueModelgetBeanChannel()
     Returns the ValueModel that holds the bean that in turn holds the adapted properties.
public synchronized  PropertyChangeListener[]getBeanPropertyChangeListeners()
     Returns an array of all the property change listeners registered on this component.
public synchronized  PropertyChangeListener[]getBeanPropertyChangeListeners(String propertyName)
     Returns an array of all the listeners which have been associated with the named property.
public  booleangetObserveChanges()
     Answers whether this adapter observes changes in the adapted Bean properties.
 SimplePropertyAdaptergetPropertyAdapter(String propertyName)
     Looks up and returns the SimplePropertyAdapter that adapts the bound property with the specified name.
public  ObjectgetValue(String propertyName)
     Returns the value of specified bean property, null if the current bean is null.

This operation is supported only for readable bean properties.

public  SimplePropertyAdaptergetValueModel(String propertyName)
     Looks up and lazily creates a ValueModel that adapts the bound property with the specified name.
public  SimplePropertyAdaptergetValueModel(String propertyName, String getterName, String setterName)
     Looks up and lazily creates a ValueModel that adapts the bound property with the specified name.
public  booleanisChanged()
     Answers whether a bean property has changed since the changed state has been reset.
public synchronized  voidrelease()
     Removes the PropertyChangeHandler from the observed bean, if the bean is not null and if bean property changes are observed. Also removes all listeners from the bean that have been registered with #addBeanPropertyChangeListener before.

BeanAdapters that observe changes have a PropertyChangeListener registered with the target bean.

public synchronized  voidremoveBeanPropertyChangeListener(PropertyChangeListener listener)
     Removes a PropertyChangeListener from the list of bean listeners.
public synchronized  voidremoveBeanPropertyChangeListener(String propertyName, PropertyChangeListener listener)
     Removes a PropertyChangeListener from the listener list for a specific property.
public  voidresetChanged()
     Resets this tracker's changed state to false.
public  voidsetBean(B newBean)
     Sets a new Java Bean as holder of the adapted properties.
public  voidsetValue(String propertyName, Object newValue)
     Sets the given new value for the specified bean property.
public  voidsetVetoableValue(String propertyName, Object newValue)
     Sets a new value for the specified bean property.

Field Detail
PROPERTYNAME_AFTER_BEAN
final public static String PROPERTYNAME_AFTER_BEAN(Code)
The property name used in the PropertyChangeEvent that is fired after the bean property fires its PropertyChangeEvent. Useful to perform an operation after listeners that handle the bean change are notified. See also the class comment.



PROPERTYNAME_BEAN
final public static String PROPERTYNAME_BEAN(Code)
The name of the read-write bound property that holds the target bean.
See Also:   BeanAdapter.getBean()
See Also:   BeanAdapter.setBean(Object)



PROPERTYNAME_BEFORE_BEAN
final public static String PROPERTYNAME_BEFORE_BEAN(Code)
The property name used in the PropertyChangeEvent that is fired before the bean property fires its PropertyChangeEvent. Useful to perform an operation before listeners that handle the bean change are notified. See also the class comment.



PROPERTYNAME_CHANGED
final public static String PROPERTYNAME_CHANGED(Code)
The name of the read-only bound bean property that indicates whether one of the observed properties has changed.
See Also:   BeanAdapter.isChanged()



storedOldBean
B storedOldBean(Code)
Refers to the old bean. Used as old value if the bean changes. Updated after a bean change in the BeanChangeHandler.




Constructor Detail
BeanAdapter
public BeanAdapter(B bean)(Code)
Constructs a BeanAdapter for the given bean; does not observe changes.

Installs a default bean channel that checks the identity not equity to ensure that listeners are reregistered properly if the old and new bean are equal but not the same.
Parameters:
  bean - the bean that owns the properties to adapt




BeanAdapter
public BeanAdapter(B bean, boolean observeChanges)(Code)
Constructs a BeanAdapter for the given bean; observes changes if specified.

Installs a default bean channel that checks the identity not equity to ensure that listeners are reregistered properly if the old and new bean are equal but not the same.
Parameters:
  bean - the bean that owns the properties to adapt
Parameters:
  observeChanges - true to observe changes of boundor constrained properties, false to ignore changes
throws:
  PropertyUnboundException - if observeChangesis true but the property is unbound, i. e. the beandoes not provide a pair of methods to register a multicastPropertyChangeListener




BeanAdapter
public BeanAdapter(ValueModel beanChannel)(Code)
Constructs a BeanAdapter for the given bean channel; does not observe changes.

It is strongly recommended that the bean channel checks the identity not equity. This ensures that listeners are reregistered properly if the old and new bean are equal but not the same.
Parameters:
  beanChannel - the ValueModel that holds the bean




BeanAdapter
public BeanAdapter(ValueModel beanChannel, boolean observeChanges)(Code)
Constructs a BeanAdapter for the given bean channel; observes changes if specified.

It is strongly recommended that the bean channel checks the identity not equity. This ensures that listeners are reregistered properly if the old and new bean are equal but not the same.
Parameters:
  beanChannel - the ValueModel that holds the bean
Parameters:
  observeChanges - true to observe changes of boundor constrained properties, false to ignore changes
throws:
  IllegalArgumentException - if the beanChannel is a ValueHolderthat has the identityCheck feature disabled
throws:
  PropertyUnboundException - if observeChangesis true but the property is unbound, i. e. the beandoes not provide a pair of methods to register a multicastPropertyChangeListener





Method Detail
addBeanPropertyChangeListener
public synchronized void addBeanPropertyChangeListener(PropertyChangeListener listener)(Code)
Adds a PropertyChangeListener to the list of bean listeners. The listener is registered for all bound properties of the target bean.

The listener will be notified if and only if this BeanAdapter's current bean changes a property. It'll not be notified if the bean changes.

If listener is null, no exception is thrown and no action is performed.
Parameters:
  listener - the PropertyChangeListener to be added
See Also:   BeanAdapter.removeBeanPropertyChangeListener(PropertyChangeListener)
See Also:   BeanAdapter.removeBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.addBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners()




addBeanPropertyChangeListener
public synchronized void addBeanPropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)
Adds a PropertyChangeListener to the list of bean listeners for a specific property. The specified property may be user-defined.

The listener will be notified if and only if this BeanAdapter's current bean changes the specified property. It'll not be notified if the bean changes. If you want to observe property changes and bean changes, you may observe the ValueModel that adapts this property - as returned by #getValueModel(String).

Note that if the bean is inheriting a bound property, then no event will be fired in response to a change in the inherited property.

If listener is null, no exception is thrown and no action is performed.
Parameters:
  propertyName - one of the property names listed above
Parameters:
  listener - the PropertyChangeListener to be added
See Also:   BeanAdapter.removeBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.addBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners(String)




createPropertyAdapter
protected SimplePropertyAdapter createPropertyAdapter(String propertyName, String getterName, String setterName)(Code)
Creates and returns a SimplePropertyAdapter that adapts the bound property with the specified name.
Parameters:
  propertyName - the name of the property to adapt
Parameters:
  getterName - the name of the method that reads the value
Parameters:
  setterName - the name of the method that sets the value a SimplePropertyAdapter that adapts the propertywith the specified name
since:
   1.4



getBean
public B getBean()(Code)
Returns the Java Bean that holds the adapted properties. the Bean that holds the adapted properties
See Also:   BeanAdapter.setBean(Object)



getBeanChannel
public ValueModel getBeanChannel()(Code)
Returns the ValueModel that holds the bean that in turn holds the adapted properties. This bean channel is shared by the PropertyAdapters created by the factory method #getValueModel. the ValueModel that holds the bean that in turnholds the adapted properties
See Also:   BeanAdapter.getBean()
See Also:   BeanAdapter.setBean(Object)
since:
   1.3



getBeanPropertyChangeListeners
public synchronized PropertyChangeListener[] getBeanPropertyChangeListeners()(Code)
Returns an array of all the property change listeners registered on this component. all of this component's PropertyChangeListenersor an empty array if no property changelisteners are currently registered
See Also:   BeanAdapter.addBeanPropertyChangeListener(PropertyChangeListener)
See Also:   BeanAdapter.removeBeanPropertyChangeListener(PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners(String)
See Also:   java.beans.PropertyChangeSupport.getPropertyChangeListeners



getBeanPropertyChangeListeners
public synchronized PropertyChangeListener[] getBeanPropertyChangeListeners(String propertyName)(Code)
Returns an array of all the listeners which have been associated with the named property.
Parameters:
  propertyName - the name of the property to lookup listeners all of the PropertyChangeListeners associated withthe named property or an empty array if no listeners havebeen added
See Also:   BeanAdapter.addBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.removeBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners()



getObserveChanges
public boolean getObserveChanges()(Code)
Answers whether this adapter observes changes in the adapted Bean properties. true if this adapter observes changes, false if not



getPropertyAdapter
SimplePropertyAdapter getPropertyAdapter(String propertyName)(Code)
Looks up and returns the SimplePropertyAdapter that adapts the bound property with the specified name.
Parameters:
  propertyName - the name of the adapted property a SimplePropertyAdapter that adapts the bound propertywith the specified name or null, if none has been created before



getValue
public Object getValue(String propertyName)(Code)
Returns the value of specified bean property, null if the current bean is null.

This operation is supported only for readable bean properties.
Parameters:
  propertyName - the name of the property to be read the value of the adapted bean property, null if the bean is null
throws:
  NullPointerException - if propertyName is null
throws:
  UnsupportedOperationException - if the property is write-only
throws:
  PropertyNotFoundException - if the property could not be found
throws:
  PropertyAccessException - if the value could not be read




getValueModel
public SimplePropertyAdapter getValueModel(String propertyName)(Code)
Looks up and lazily creates a ValueModel that adapts the bound property with the specified name. Uses the Bean introspection to look up the getter and setter names.

Subsequent calls to this method with the same property name return the same ValueModel.

To prevent potential runtime errors this method eagerly looks up the associated PropertyDescriptor if the target bean is not null.

For each property name all calls to this method and to #getValueModel(String, String, String) must use the same getter and setter names. Attempts to violate this constraint will be rejected with an IllegalArgumentException. Especially once you've called this method you must not call #getValueModel(String, String, String) with a non-null getter or setter name. And vice versa, once you've called the latter method with a non-null getter or setter name, you must not call this method.

This method uses a return type of AbstractValueModel, not a ValueModel. This makes BeanAdapter.setVetoableValue(String,Object) visible. It also makes the AbstractValueModel convenience type converters available, which can significantly shrink the source code necessary to read and write values from/to these models.
Parameters:
  propertyName - the name of the property to adapt a ValueModel that adapts the property with the specified name
throws:
  NullPointerException - if propertyName is null
throws:
  PropertyNotFoundException - if the property could not be found
throws:
  IllegalArgumentException - if #getValueModel(String, String, String) has beencalled before with the same property name and a non-null getteror setter name




getValueModel
public SimplePropertyAdapter getValueModel(String propertyName, String getterName, String setterName)(Code)
Looks up and lazily creates a ValueModel that adapts the bound property with the specified name. Unlike #getValueModel(String) this method bypasses the Bean Introspection and uses the given getter and setter names to setup the access to the adapted Bean property.

Subsequent calls to this method with the same parameters will return the same ValueModel.

To prevent potential runtime errors this method eagerly looks up the associated PropertyDescriptor if the target bean is not null.

For each property name all calls to this method and to #getValueModel(String) must use the same getter and setter names. Attempts to violate this constraint will be rejected with an IllegalArgumentException. Especially once you've called this method with a non-null getter or setter name, you must not call #getValueModel(String). And vice versa, once you've called the latter method you must not call this method with a non-null getter or setter name.

This method uses a return type of AbstractValueModel, not a ValueModel. This makes BeanAdapter.setVetoableValue(String,Object) visible. It also makes the AbstractValueModel convenience type converters available, which can significantly shrink the source code necessary to read and write values from/to these models.
Parameters:
  propertyName - the name of the property to adapt
Parameters:
  getterName - the name of the method that reads the value
Parameters:
  setterName - the name of the method that sets the value a ValueModel that adapts the property with the specified name
throws:
  NullPointerException - if propertyName is null
throws:
  PropertyNotFoundException - if the property could not be found
throws:
  IllegalArgumentException - if this method has been called beforewith the same property name and different getter or setter names




isChanged
public boolean isChanged()(Code)
Answers whether a bean property has changed since the changed state has been reset. The changed state is implicitly reset every time the target bean changes. true if a property of the current target beanhas changed since the last reset



release
public synchronized void release()(Code)
Removes the PropertyChangeHandler from the observed bean, if the bean is not null and if bean property changes are observed. Also removes all listeners from the bean that have been registered with #addBeanPropertyChangeListener before.

BeanAdapters that observe changes have a PropertyChangeListener registered with the target bean. Hence, a bean has a reference to all BeanAdapters that observe it. To avoid memory leaks it is recommended to remove this listener if the bean lives much longer than the BeanAdapter, enabling the garbage collector to remove the adapter. To do so, you can call setBean(null) or set the bean channel's value to null. As an alternative you can use event listener lists in your beans that implement references with WeakReference.

Setting the bean to null has side-effects, for example the adapter fires a change event for the bound property bean and other properties. And the value of ValueModel's vended by this adapter may change. However, typically this is fine and setting the bean to null is the first choice for removing the reference from the bean to the adapter. Another way to clear the reference from the target bean is to call #release. It has no side-effects, but the adapter must not be used anymore once #release has been called.
See Also:   BeanAdapter.setBean(Object)
See Also:   java.lang.ref.WeakReference




removeBeanPropertyChangeListener
public synchronized void removeBeanPropertyChangeListener(PropertyChangeListener listener)(Code)
Removes a PropertyChangeListener from the list of bean listeners. This method should be used to remove PropertyChangeListeners that were registered for all bound properties of the target bean.

If listener is null, no exception is thrown and no action is performed.
Parameters:
  listener - the PropertyChangeListener to be removed
See Also:   BeanAdapter.addBeanPropertyChangeListener(PropertyChangeListener)
See Also:   BeanAdapter.addBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.removeBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners()




removeBeanPropertyChangeListener
public synchronized void removeBeanPropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)
Removes a PropertyChangeListener from the listener list for a specific property. This method should be used to remove PropertyChangeListeners that were registered for a specific bound property.

If listener is null, no exception is thrown and no action is performed.
Parameters:
  propertyName - a valid property name
Parameters:
  listener - the PropertyChangeListener to be removed
See Also:   BeanAdapter.addBeanPropertyChangeListener(String,PropertyChangeListener)
See Also:   BeanAdapter.removeBeanPropertyChangeListener(PropertyChangeListener)
See Also:   BeanAdapter.getBeanPropertyChangeListeners(String)




resetChanged
public void resetChanged()(Code)
Resets this tracker's changed state to false.



setBean
public void setBean(B newBean)(Code)
Sets a new Java Bean as holder of the adapted properties. Notifies any registered value listeners that are registered with the adapting ValueModels created in #getValueModel. Also notifies listeners that have been registered with this adapter to observe the bound property bean.

Resets the changed state to false.

If this adapter observes bean changes, the bean change handler will be removed from the former bean and will be added to the new bean. Hence, if the new bean is null, this adapter has no listener registered with a bean. And so, setBean(null) can be used as a clean release method that allows to use this adapter later again.
Parameters:
  newBean - the new holder of the adapted properties
See Also:   BeanAdapter.getBean()
See Also:   BeanAdapter.isChanged()
See Also:   BeanAdapter.resetChanged()
See Also:   BeanAdapter.release()




setValue
public void setValue(String propertyName, Object newValue)(Code)
Sets the given new value for the specified bean property. Does nothing if this adapter's bean is null. If the setter associated with the propertyName throws a PropertyVetoException, it is silently ignored.

Notifies the associated value change listeners if the bean reports a property change. Note that a bean may suppress PropertyChangeEvents if the old and new value are the same, or if the old and new value are equal.

This operation is supported only for writable bean properties.
Parameters:
  propertyName - the name of the property to set
Parameters:
  newValue - the value to set
throws:
  NullPointerException - if propertyName is null
throws:
  UnsupportedOperationException - if the property is read-only
throws:
  PropertyNotFoundException - if the property could not be found
throws:
  PropertyAccessException - if the new value could not be set




setVetoableValue
public void setVetoableValue(String propertyName, Object newValue) throws PropertyVetoException(Code)
Sets a new value for the specified bean property. Does nothing if the bean is null. If the setter associated with the propertyName throws a PropertyVetoException, this methods throws the same exception.

Notifies the associated value change listeners if the bean reports a property change. Note that a bean may suppress PropertyChangeEvents if the old and new value are the same, or if the old and new value are equal.

This operation is supported only for writable bean properties.
Parameters:
  propertyName - the name of the property to set
Parameters:
  newValue - the value to set
throws:
  NullPointerException - if propertyName is null
throws:
  UnsupportedOperationException - if the property is read-only
throws:
  PropertyNotFoundException - if the property could not be found
throws:
  PropertyAccessException - if the new value could not be set
throws:
  PropertyVetoException - if the bean setterthrows a PropertyVetoException
since:
   1.1




Methods inherited from com.jgoodies.binding.beans.Model
final public synchronized void addPropertyChangeListener(PropertyChangeListener listener)(Code)(Java Doc)
final public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)(Java Doc)
final public synchronized void addVetoableChangeListener(VetoableChangeListener listener)(Code)(Java Doc)
final public synchronized void addVetoableChangeListener(String propertyName, VetoableChangeListener listener)(Code)(Java Doc)
final protected boolean equals(Object o1, Object o2)(Code)(Java Doc)
final protected void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue)(Code)(Java Doc)
final protected void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue)(Code)(Java Doc)
final protected void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue)(Code)(Java Doc)
final protected void fireMultiplePropertiesChanged()(Code)(Java Doc)
final protected void firePropertyChange(PropertyChangeEvent event)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue, boolean checkIdentity)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, double oldValue, double newValue)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, float oldValue, float newValue)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, int oldValue, int newValue)(Code)(Java Doc)
final protected void firePropertyChange(String propertyName, long oldValue, long newValue)(Code)(Java Doc)
final protected void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, double oldValue, double newValue) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, float oldValue, float newValue) throws PropertyVetoException(Code)(Java Doc)
final protected void fireVetoableChange(String propertyName, long oldValue, long newValue) throws PropertyVetoException(Code)(Java Doc)
final public synchronized PropertyChangeListener[] getPropertyChangeListeners()(Code)(Java Doc)
final public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName)(Code)(Java Doc)
final public synchronized VetoableChangeListener[] getVetoableChangeListeners()(Code)(Java Doc)
final public synchronized VetoableChangeListener[] getVetoableChangeListeners(String propertyName)(Code)(Java Doc)
final public synchronized void removePropertyChangeListener(PropertyChangeListener listener)(Code)(Java Doc)
final public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)(Java Doc)
final public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)(Code)(Java Doc)
final public synchronized void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.