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.
Summary: | Refactoring should be able to create bound properties | ||
---|---|---|---|
Product: | java | Reporter: | kitfox <kitfox> |
Component: | Refactoring | Assignee: | Jan Becicka <jbecicka> |
Status: | RESOLVED DUPLICATE | ||
Severity: | blocker | ||
Priority: | P3 | ||
Version: | 5.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
kitfox
2005-12-01 02:09:05 UTC
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); } } |