Bug 226199 - Add Ability to Generate PropertyChangeSupport on Entities
Summary: Add Ability to Generate PropertyChangeSupport on Entities
Status: NEW
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Neil Hauge CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-04-08 16:52 EDT by Tim Hollosy CLA
Modified: 2008-04-09 12:38 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hollosy CLA 2008-04-08 16:52:17 EDT
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.
Comment 1 Neil Hauge CLA 2008-04-09 12:02:50 EDT
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?
Comment 2 Tim Hollosy CLA 2008-04-09 12:38:59 EDT
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.