| 
| [Databinding] databinding arrays and lists of strings [message #326668] | Thu, 27 March 2008 17:05  |  | 
| Eclipse User  |  |  |  |  | I'm hoping I'm missing a basic understanding and you can help me out.  I'm new to using databinding.
 
 I have a Person bean.  That object has a string array of nicknames for the
 person.  In the GUI, I want a table to show this list of names.
 Additionally, I want to add actions that can add or remove or change the
 order.  Right now I'm having trouble binding a table to this list property
 of a Person object.
 
 Can anyone help explain how binding works with lists?
 |  |  |  | 
| 
| Re: [Databinding] databinding arrays and lists of strings [message #326690 is a reply to message #326668] | Fri, 28 March 2008 13:08  |  | 
| Eclipse User  |  |  |  |  | Jay, 
 I'm assuming you're using BeansObservables.observeList(person,
 "listProperty") to observe the array property--is this correct?
 
 In order for DataBinding to pick up the change in your bean, you need to
 implement the full bean spec in your bean class:
 
 void addPropertyChangeListener(PropertyChangeListener listener)
 void removePropertyChangeListener(PropertyChangeListener listener)
 void addPropertyChangeListener(
 String propertyName, PropertyChangeListener listener)
 void removePropertyChangeListener(
 String propertyName, PropertyChangeListener listener)
 
 When the bean property changes, you need to fire a PropertyChangeEvent,
 and in the case of collections, the event's oldValue and newValue must
 be full copies of the old and new state of the array:
 
 private PropertyChangeSupport changeSupport = new
 PropertyChangeSupport(this);
 
 public void setNicknames(String[] nicknames) {
 // Do checks on argument, etc.
 
 Object oldValue = this.nicknames;
 this.nicknames = nicknames;
 Object newValue = nicknames.clone(); // defensive copy
 changeSupport.firePropertyChange("nicknames", oldValue, newValue);
 }
 
 When DataBinding receives the property change, it calculates the
 difference between the old array and the new array, and updates the
 IObservableList accordingly.
 
 Let me know if you need more information.
 
 Matthew
 
 Jay Simpson wrote:
 > I'm hoping I'm missing a basic understanding and you can help me out.  I'm
 > new to using databinding.
 >
 > I have a Person bean.  That object has a string array of nicknames for the
 > person.  In the GUI, I want a table to show this list of names.
 > Additionally, I want to add actions that can add or remove or change the
 > order.  Right now I'm having trouble binding a table to this list property
 > of a Person object.
 >
 > Can anyone help explain how binding works with lists?
 >
 >
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.03618 seconds