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

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

Set the language for your RCP application

By default, an application built with the NetBeans Platform will use the system’s language. What this means is that if you are in Germany, the default messages (i.e. from JFileChooser) will be in German:

German GUI

Now what if you need to develop your application in English. Well, it’s easy. You just have to edit the file project.properties (under Important Files) from your application (nbproject folder) and add:

run.args.extra= --locale en:US

This way, the default messages will be displayed in English:

English GUI

Similar post on the subject: http://www.sepix.de/blogs/blogrittner/blog/archive////ide_67_mulitingual_switch_ins_angloamerikanische/index.html

May 15, 2009 Posted by | NetBeans RCP | Leave a comment

Change the version number in a NetBeans Platform application

You have developed your application on top of the NetBeans platform? Now I guess that when you start it, you see a weird build version number in the title bar…

Version number

If you want to set your own version number, you just have to set the “netbeans.buildnumber” property when the application starts (in a ModuleInstall class for example):

System.setProperty(“netbeans.buildnumber”, “0.1.0”);

Version number

Two interesting posts on this subject:

April 15, 2009 Posted by | NetBeans RCP | Leave a comment

Hibernate with the NetBeans Platform

I’ve had some difficulties using Hibernate in my NetBeans Platform application… so here is a quick summary of what I did. I created 4 NetBeans modules:

  • Derby
  • Hibernate
  • DataModel
  • Entities

Derby and Hibernate are library wrapper modules that contain JAR files.

modules

  • Hibernate depends on Entities and on Derby
  • DataModel depends on Entities and Hibernate

I added some files in the Hibernate module:

  • log4j.properties
  • org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer (for the correct initialization of the module)

hibernate

In Entities, I created the object “Imports” that needs to be stored in the DB:

  • hibernate.cfg.xml
  • Imports.hbm.xml
  • Imports.java

entities

In DataModel, I have an installer (extends ModuleInstall) class that creates the connection to the DB:

  • sessionFactory = new Configuration().configure().buildSessionFactory();

Finally, I modified the project.properties file of the application to ignore some messages:

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

And there we are, the application is connected to the Derby database when it is started !

April 8, 2009 Posted by | NetBeans RCP | 5 Comments

Adding explorer components into the NetBeans palette

To add explorer components (such as BeanTreeView or OutlineView) from the package “org.openide.explorer.view” into the palette (NetBeans 6.5):

  • Right click on the palette, select Palette Manager
  • Click Add from JAR
  • Select <path to NetBeans 6.5>\platform9\modules\org-openide-explorer.jar
  • Select the components that you want to add into the palette, click Next
  • Select a catetegory, click Finish

April 1, 2009 Posted by | NetBeans RCP | Leave a comment