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.

Bug 258518

Summary: the wrapping model for JTree OptionsFilter$FilteringTreeModel doesn't delegate addition/removal of listeners to the underlying model
Product: editor Reporter: ilia
Component: OptionsAssignee: Milutin Kristofic <mkristofic>
Status: RESOLVED FIXED    
Severity: normal CC: issues, jlahoda, sdedic
Priority: P3    
Version: 8.2   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 258503, 267267    
Attachments: patch
Suggestion for

Description ilia 2016-03-24 10:29:26 UTC
I have a custom implementation of TreeModel (named ExtendedModel), which is used in Editor->Hints->C/C++.
When initializing a JTree I use OptionsFilter to add a filtering functionality:

  ((OptionsFilter) filter).installFilteringModel(errorTree, model, new AcceptorImpl());

The OptionsFilter$FilteringTreeModel wraps my model and properly delegates methods like isLeaf(Object node), getRoot(), etc.
But the problem is that it's not delegating addTreeModelListener/removeTreeModelListener methods to the underlying model.

This is critical because JTree itself and some other classes like BasicTreeUI adds theirs listeners to model.
What happens: imagine the structure of nodes was changed in ExtendedModel. To properly redraw the tree I should notify all related UI components of JTree that the branch was changed. But the addition of this listeners was not correctly delegated to my model, thus UI is not redrawn.

Fix attached:
  * delegate listeners to the inner model
  * remove UOE from treeNodes* methods
Comment 1 ilia 2016-03-24 10:31:04 UTC
Created attachment 158990 [details]
patch
Comment 2 ilia 2016-03-31 09:45:18 UTC
Can you review and apply the fix, please?
Comment 3 Milutin Kristofic 2016-06-17 14:07:57 UTC
Thank you ilia for patch and patience. I am sorry for waiting. Here is pushed into repository. http://hg.netbeans.org/jet-main/rev/7820b6906e42
Comment 4 ilia 2016-06-17 14:38:37 UTC
Thanks, Milutin!
Comment 5 Svata Dedic 2016-07-25 09:03:22 UTC
The change causes issue #267267; since the event comes to filtered model client from the original unfiltered source, integer indices are broken - from the filered point of view.
Comment 6 Milutin Kristofic 2016-07-26 14:20:39 UTC
Created attachment 161452 [details]
Suggestion for

Hi Ilia,
this change is causing problem with filtering tree, since it triggers tree changes in Handler. I have not find solution with leaving delegate listeners as are in your patch. 

Maybe we can do something like I am suggesting in patch. What do you think?
Comment 7 ilia 2016-08-15 14:18:18 UTC
Hi Milutin,

Fix looks safe.
I believe spec. version in module's properties should be incremented too because this is an API change.
Comment 8 Milutin Kristofic 2016-08-15 15:03:54 UTC
Great,thank you.
I push patch to repository. http://hg.netbeans.org/jet-main/rev/64fa8c731fa9 

After discussion with Svata, I changed implementation to overload.

Best,
Milutin
Comment 9 Quality Engineering 2016-08-27 02:20:00 UTC
Integrated into 'main-silver', will be available in build *201608270002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/64fa8c731fa9
User: Milutin Kristofic <mkristofic@netbeans.org>
Log: #258518 - the wrapping model for JTree OptionsFilter$FilteringTreeModel doesn't delegate addition/removal of listeners to the underlying model