This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
At the moment, the refactoring mechanism only generates getter and setter methods when it encapsulates fields. It would be very useful to extend this so that it can generate bound and vetoable properties as well. At the moment, I need to go back and hand edit my encapsulated fields to make them bean compliant.
refactoring?
When you encapsulate fields. Instead of simply generating: class MyClass { private int top; public int getTop() { return top; } public void setTop(int top) { this.top = top; } } it would be nice if an option for something like the following could be done: class MyClass { PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); private int top; public int getTop() { return top; } public void setTop(int top) { int old = this.top; this.top = top; propertyChangeSupport.firePropertyChange("top", old, top); } } The above code makes 'top' a bound field. Something that also provides the option of making a vetoable field would also be useful.
An even better way to do this would be to first check if the current class contains a memeber which is a PropertyChangeSupport. If not, create one, including the add and remove listener methods. Also, setting a static final String to be the property name would be a good idea. class MyClass { PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); private int top; public static final PROP_top = "top"; public void addPropertyChangeListener(PropertyChangeListener l) { propertyChangeSupport.addPropertyChangeListener(l); } public void removePropertyChangeListener(PropertyChangeListener l) { propertyChangeSupport.removePropertyChangeListener(l); } public int getTop() { return top; } public void setTop(int top) { int old = this.top; this.top = top; propertyChangeSupport.firePropertyChange(PROP_top, old, top); } }
*** This bug has been marked as a duplicate of bug 69498 ***