Ruben Laguna's blog

Apr 28, 2009 - 2 minute read - dependency favorites layer layer.xml loading module netbeans opened order startup state

Opening Favorites window at startup in a Netbeans Platform Application

After learning about the Favorites window in the NetBeans Platform Quick Start. I wanted to use it in an application of my own.

graphbrowser3

This easy task became more difficult that I though because I was getting random results, sometimes after a clean build I got the Favorites window open and sometimes not.

But let’s start from the beginning, I put my hands at work, it was just a matter of adding the Favorites module to the Netbeans Platform Application (app’s properties ⇒ Libraries ⇒ Platform Modules ⇒ platform9 ⇒ Favorites) and edit one of my modules layer.xml to override Windows2/Modes/explorer/favorites.wstcref. Just go to Important Files ⇒ XML Layer ⇒ this layer in context ⇒ Windows2 ⇒ Modes ⇒ explore ⇒ favorites.wstcref and replace

<state opened="false" />

with

<state opened="true" />

So the layer.xml in the module ended like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
          <folder name="Windows2">
                    <folder name="Modes">
                    <folder name="explorer">
                              <file name="favorites.wstcref" url="favoritesWstcref.xml"/>
                    </folder>
                    </folder>
          </folder>
</filesystem>

and the favoritesWstcref.xml file in my module look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tc-ref PUBLIC
          "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN"
          "http://www.netbeans.org/dtds/tc-ref2_0.dtd">
<tc-ref version="2.0">
<module name="org.netbeans.modules.favorites/1" spec="1.1" />
<tc-id id="favorites" />
<state opened="true" />
</tc-ref>

But it didn’t work as expected sometimes after doing a clean & build the favorites didn’t open at startup. So I asked in the forums and I got a tip that help me to resolve the issue. It was a module loading order problem. But how do you set the module loading order, easy, just click on your module properties ⇒ Libraries ⇒ Add Dependency ⇒ Non-API module ⇒ Favorites.

brandingmoduleproperties

Adding a dependency with the Favorites modules will ensure that Favorites is loaded before your module and thus ensuring that you layer.xml changes will override the values set by Favorites module (and not the other way around).