I just run into an issue which was discussed a couple of month ago here on the NetBeans Dev mailing list. (see here)
Now, assuming we have the scenario of the MyBean as model as shown as an example in Wade Chandlers first answer. Now also assume you have a MyBeanNode which is representing this data.
Also assume you have the MyBeanNode listening to PropertyChanges to MyBean via some line like
myBean.addPropertyChangeListener(WeakListeners.
propertyChange(this, myBean));
The propertyChange(...) method in MyBeanNode will do needed updates to the model etc.
So far so good.
Now I was tempted to add the option to allow to Rename the object.
1) I added canRename() to the MyBeanNode and let it return true.
2) I added the Action[] getActions(..) method and made sure to add the SystemAction.get(RenameAction.class)
3) I added the setName(..) method
Happy a Rename popup was available and when I rename the object the Node name was changed - but - the name field in the Property Window was still showing the old value. Even though when doing some refreshing action like collapsing and expanding the property Sheet Set it was showing the correct value.
Hmpf - very similar to the problem the person in the discussion encountered.
Now .. the solution is to add the following line to the setName(String name) method of your MyBeanNode
this.firePropertyChange("name", oldname, newname)
Note, this is fire'ring a property change event to all listening to changes in the Node - while the pcs.firePropertyChange(...) call in the MyBean was sending it to its listeners - which was the MyBeanNode in this case.
Without knowing I assume that the PropertySheet's GUI is listening to PropertyChanges in the Node ? Well - anyhow - this solved my problem and the problem discussed in the link above.
No comments:
Post a Comment