Community
Participate
Working Groups
A common requirement to use model objects (Entities) with the Databinding Frameworks such as JFace Databinding is is to have the Model Object provide bound property support through the PropertyChangeSupport class. See: http://java.sun.com/j2se/1.5.0/docs/api/java/beans/PropertyChangeSupport.html This entails having your setters in a pattern like: public void setName(String name) { if (this.name == null && name == null) { return; } firePropertyChange("name", this.name, this.name = name); } And having your Model (Entity in this case) extend a base class that implements the methods: private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this); public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); } public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(propertyName, listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.removePropertyChangeListener(listener); } public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { propertyChangeSupport.removePropertyChangeListener(propertyName, listener); } protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); } Other similar plugins like HiberObjects currently offer PropertyChangeSupport implementations in their Entity generation, it would be nice if JPA Tools did the same.
This does sound like a nice feature to add to Entity Generation. I'm thinking it would be optional, with a checkbox on the wizard to enable the generation of the property change support. Perhaps this is something that you would be interested in contributing to the project?
Could we piggy back on to the New Class Wizard Page? That way we'd be able to choose any classes to extend and interfaces to implement as well. Maybe have 2 options before that page though: 1) Add PropertyChangeSupport methods (if your base class does this, you wouldn't want them) 2) Add firePropertyChange methods to the setters. I'll consider contributing this, because if it's not there I'd have to write a code gen anyway.