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 | Leave a comment

Getting rid of IllegalStateException warnings

If you want to get rid of IllegalStateException of this kind:

INFO [org.netbeans.ProxyClassLoader]
java.lang.IllegalStateException: You are trying to access file: jcommon.properties from the default package. Please see http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#default_package

Just add a new line to your project.properties:

run.args.extra=-J-Dorg.netbeans.ProxyClassLoader.level=1000

Note that all extra parameters must be on the same line:

run.args.extra=-J-Djava.util.logging.config.file="logging.properties" -J-Dorg.netbeans.ProxyClassLoader.level=1000 --locale en:US

June 4, 2009 Posted by | NetBeans RCP | Leave a comment