Learning the NetBeans Platform

Utilities.actionsGlobalContext on startup

Here’s a problem I had recently: I spent quite a lot of time to fix it so I think it’s a good idea to share the experience…

I’m registering a listener on the global context selection in a TopComponent like this:

Lookup.Template tpl = new Lookup.Template(FieldsVisibility.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);

The topcomponent has a PERSISTENCE_ALWAYS persistence type.

The problem is that the listener is not registered correctly when the application is started.
The user must close and re-open the topcomponent…

The solution to the problem is to add result.allInstances(); like this:

Lookup.Template tpl = new Lookup.Template(FieldsVisibility.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.allInstances();
result.addLookupListener(this);

Discussion on the topic in the mailing list: http://www.nabble.com/Lookup-Listeners-problems-td5947615.html#a5948612

Advertisements

June 8, 2009 - Posted by | NetBeans RCP

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: