Extending the NetBeans Favorites Window

URLs registered in the Favorites folder are rendered in the Favorites window. Rendering is done by the FavoritesNode, which is an internal class in the Favorites module, for each URL registered in the Favorites folder.

For example, here I've created a URL:

package org.my.fav;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openide.filesystems.FileUtil;
import org.openide.util.Utilities;

public class ConfigRootNode {

     public static URL getNetBeansUser() throws MalformedURLException {
        String s = System.getProperty("netbeans.user"); // NOI18N
        File userDir = new File(s);
        userDir = FileUtil.normalizeFile(userDir);
        return Utilities.toURI(userDir).toURL();
    }
     
}

And here the URL above is registered:

<folder name="Favorites">
    <file name="UserDir.shadow">
        <attr name="originalFile" 
                 methodvalue="org.my.fav.ConfigRootNode.getNetBeansUser"/>
        <attr name="position" intvalue="200"/>
    </file>
</folder>

Therefore, note that the only thing you can pass into the Favorites folder is a URL, nothing else, i.e., you have no control over the rendered Node, e.g., over its children. If that's what you want, either create a Node and register it in the Services window as shown here (assuming you're extending NetBeans IDE, since that's where that window comes from, not the NetBeans Platform) or simply create your own TopComponent and render your Nodes there.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today