Re: LogicalViewProvider.createLogicalView is called twice when project explorer is created. Why?

Eirik Bakke <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <D2D64EC1.51288%[email protected]>
> The constructor of the Node adds itself as a PropertyChangeListener (I use a WeakListener, by the way) to the preference manager object.   When the preference manager fires a property change, both instances of the node respond to that change, causing the action to be fired twice.

That sounds like the correct behavior, then. Could the act of responding to the change be made into a cheap operation? For instance by running the expensive initialization in a separate thread that is only started once, or when actually necessary?

As Tim mentions, there's also the opportunity to do additional expensive work as other descendant nodes are expanded, using the ChildFactory API.

-- Eirik

From: Todd Stevenson <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Date: Tuesday, February 2, 2016 at 11:24 AM
To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Subject: [platform-dev] Re: LogicalViewProvider.createLogicalView is called twice when project explorer is created. Why?

I misspoke on the propertyChangeListener.  The constructor of the Node adds itself as a PropertyChangeListener (I use a WeakListener, by the way) to the preference manager object.   When the preference manager fires a property change, both instances of the node respond to that change, causing the action to be fired twice.



Todd Stevenson
Sr Clinical Modeling Engineer
Clinical Modeling
3930 Parkway Blvd |Salt Lake City, UT 84120
Office: 801-442-5112 | Cell: 801-589-1115
[email protected]<mailto:[email protected]>
[cid:[email protected]]

From: Eirik Bakke [mailto:[email protected]]
Sent: Tuesday, February 02, 2016 9:11 AM
To: [email protected]<mailto:[email protected]>
Subject: [platform-dev] Re: LogicalViewProvider.createLogicalView is called twice when project explorer is created. Why?

It's the Node object that shouldn't be cached--you're free to cache data structures that you define yourself in your business logic. Generally, nodes should be cheap to create, and they can be created multiple times.

> My problem is that I’m setting a PropertyChangedListener in the constructor of the root node.  This is getting set twice and then later on when the property changes, all the nodes in the project are updated twice.

This sounds odd. If each node adds a PropertyChangeListener in its own constructor, then each node will only be subscribed once, since a constructor runs only once per object instance.

One note, though: When attaching listeners to external model objects from new Node implementations, it's important to use weak listeners [1] only. Otherwise your Node objects will stay in memory and receive events even after the UI has thrown away its last references to them.

[1] http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/WeakListeners.html

From: Todd Stevenson <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Date: Tuesday, February 2, 2016 at 10:35 AM
To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Subject: [platform-dev] Re: LogicalViewProvider.createLogicalView is called twice when project explorer is created. Why?

The documentation in LogicalViewProvider says not to cache the call.

http://bits.netbeans.org/8.1/javadoc/org-netbeans-modules-projectuiapi/org/netbeans/spi/project/ui/LogicalViewProvider.html

My problem is that I’m setting a PropertyChangedListener in the constructor of the root node.  This is getting set twice and then later on when the property changes, all the nodes in the project are updated twice.

Todd Stevenson
Sr Clinical Modeling Engineer
Clinical Modeling
3930 Parkway Blvd |Salt Lake City, UT 84120
Office: 801-442-5112 | Cell: 801-589-1115
[email protected]<mailto:[email protected]>
[cid:[email protected]]

From: Tim Boudreau [mailto:[email protected]]
Sent: Monday, February 01, 2016 8:57 PM
To: [email protected]<mailto:[email protected]>
Subject: [platform-dev] Re: LogicalViewProvider.createLogicalView is called twice when project explorer is created. Why?

Cache the result of the first call.

Better yet, initialize as little as possible up-front (you can do structural stuff on-demand when the node is expanded), but it's perfectly fine to cache the result.  There's nothing in the API that guarantees that it will only be called once.

-Tim

On Mon, Feb 1, 2016 at 6:34 PM, Todd Stevenson <[email protected]<mailto:[email protected]>> wrote:
I am looking at the tutorial found at

https://platform.netbeans.org/tutorials/nbm-projecttype.html#projectlogicalview

and I’ve built it from the source found in the repository at:

https://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/tutorials/CustomerProjectType

After I create a customer project as outlined in the tutorial and save it and restart the component I can see that createLogicalView() is called twice.  (line 223 of CustomerProject.java).  Is this correct behavior?  It seems that it should be called once when initializing the app.

This is causing performance problems in my app because the initialization of the project structure in my app is somewhat expensive.

I’m using Netbeans 8.0.2.

Any ideas?  Any suggestions?

Thank you.

Todd Stevenson




--
http://timboudreau.com
image003.jpg (image/jpeg, 2.9 KB) - not displayed
image002.jpg (image/jpeg, 2.9 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.