Ruben Laguna’s blog

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

1

1
<span class='line'>&lt;state opened="false" /></span>

with

1

1
<span class='line'>&lt;state opened="true" /></span>

So the layer.xml in the module ended like this

1
2
3
4
5
6
7
8
9
10
11

1
2
3
4
5
6
7
8
9
10
11
<span class='line'>&lt;?xml version="1.0" encoding="UTF-8"?>
</span><span class='line'>&lt;!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
</span><span class='line'>&lt;filesystem>
</span><span class='line'>    &lt;folder name="Windows2">
</span><span class='line'>        &lt;folder name="Modes">
</span><span class='line'>            &lt;folder name="explorer">
</span><span class='line'>                &lt;file name="favorites.wstcref" url="favoritesWstcref.xml"/>
</span><span class='line'>            &lt;/folder>
</span><span class='line'>        &lt;/folder>
</span><span class='line'>    &lt;/folder>
</span><span class='line'>&lt;/filesystem></span>

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

1
2
3
4
5
6
7
8
9
10
11

1
2
3
4
5
6
7
8
9
10
11
<span class='line'>&lt;?xml version="1.0" encoding="UTF-8"?>
</span><span class='line'>
</span><span class='line'>&lt;!DOCTYPE tc-ref PUBLIC
</span><span class='line'>          "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN"
</span><span class='line'>          "http://www.netbeans.org/dtds/tc-ref2_0.dtd">
</span><span class='line'>
</span><span class='line'>&lt;tc-ref version="2.0">
</span><span class='line'>    &lt;module name="org.netbeans.modules.favorites/1" spec="1.1" />
</span><span class='line'>    &lt;tc-id id="favorites" />
</span><span class='line'>    &lt;state opened="true" />
</span><span class='line'>&lt;/tc-ref></span>

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).

Comments

Copyright © 2015 - Ruben Laguna - Powered by Octopress