Simple Component Palette

Simple code for putting Nodes into a Component Palette. Make very sure the TopComponent is in the "editor" position, otherwise the Component Palette will not be displayed.

public EditorTopComponent() {

    initComponents();

    setName(Bundle.CTL_EditorTopComponent());
    setToolTipText(Bundle.HINT_EditorTopComponent());

    Node rootNode = new AbstractNode(Children.create(new ChildFactory<String>() {
        @Override
        protected boolean createKeys(List toPopulate) {
            for (int i = 0; i < 10; i++) {
                toPopulate.add("Category " + i);
            }
            return true;
        }
        @Override
        protected Node createNodeForKey(String key) {
            AbstractNode an = new AbstractNode(Children.create(new ChildFactory<String>() {
                @Override
                protected boolean createKeys(List<String> toPopulate) {
                    for (int i = 0; i < 10; i++) {
                        toPopulate.add("Item " + i);
                    }
                    return true;
                }
                @Override
                protected Node createNodeForKey(final String key) {
                    AbstractNode an = new AbstractNode(Children.LEAF);
                    an.setDisplayName(key);
                    return an;
                }
            }, true));
            an.setDisplayName(key);
            return an;
        }
    }, true));

    associateLookup(Lookups.singleton(PaletteFactory.createPalette(rootNode, new PaletteActions() {
        @Override
        public Action[] getImportActions() {
            return null;
        }
        @Override
        public Action[] getCustomPaletteActions() {
            return null;
        }
        @Override
        public Action[] getCustomCategoryActions(Lookup category) {
            return null;
        }
        @Override
        public Action[] getCustomItemActions(Lookup item) {
            return null;
        }
        @Override
        public Action getPreferredAction(Lookup item) {
            return null;
        }
    })));

}
Comments:

What means editor position? Sorry i'm trying to learn how to use the palette in my Java SE application and i don´t look information for do that, only i find tutorial about modules applications.

Posted by guest on August 20, 2012 at 09:29 AM PDT #

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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today