Initialize the Palette!

I've often wondered if there was a way to influence the initial expanded/collapsed state of categories in a palette. By default, the first category is expanded, while all the others are collapsed. Well, yesterday I started learning about the NetBeans API PaletteController class's attributes. If you click the link in the previous sentence, you will see there are six attributes that can be set on a root node, category node, or item node. Here's a sneak preview from the upcoming book, a table that summarizes all the attributes:

The 6 attributes are listed above. And why do two of the cells have nothing in them? Because I don't know what those default values are... yet. And how do you set these attributes? Well, if you initialize the palette in the XML layer, this is the approach you would take:

<folder name="Cards">
    <attr name="showItemNames" stringvalue="false"/>
    <folder name="Basic">
        <file name="PaletteItem_1.myitem" url="palette/jackOfHearts.myitem"/>
    </folder>
    <folder name="Expert">
        <attr name="isReadonly" stringvalue="false"/>
        <file name="PaletteItem_2.myitem" url="palette/jackOfDiamonds.myitem">
           <attr name="isReadonly" stringvalue="true"/>
        </file>
        <file name="PaletteItem_3.myitem" url="palette/kingOfDiamonds.myitem"/>
    </folder>
</folder>
In the example above, all the item names are initially hidden (so only the icons are shown), the "Expert" category can be deleted (but not the second item within the "Expert" category).

If, on the other hand, you don't use the XML layer for initializing a palette, you would use Node.setValue() to set the attributes:

public CategoryNode( String displayName ) {
  super( new Index.ArrayChildren() );
  setValue("isExpanded","true");
  setValue("isReadonly","false");
  setDisplayName( displayName );
}

Since these are the initial values, how can they be changed? Either by you, the developer, or by the user, or both. For the developer, you could use for example, the PaletteFilter class to show items that are initially hidden (see yesterday's blog). For the user, there's got to be some user interface tools to override these values. And there are. The user can, for example, right-click the palette and choose "Show Item Names" and then the hidden item names are shown. Similar contextual menus are available on the category and on individual items. However, not all attributes can be overridden by the user. For example, if the "readonly" attribute is set to "false", the "Delete" menu item is not greyed out and can be used; however, in this case, there's no way the user can decide (or would want to decide) that the "Delete" menu item should be disabled after all.

I think these attributes are pretty cool stuff, providing exactly the kind of functionality that, if you don't know about them, can be very frustrating to work out how to implement. For example, if you don't set "isReadonly", the Delete menu items in the right-click contextual menus for categories and palette items are greyed out (that's their default state). Without knowing about these attributes, you're going to have a very hard time working out how to enable those menu items... I guess that's why we're writing the module development book, so that these little corners of the NetBeans APIs can receive the attention they deserve.

In other news. Check out this cool interview with NetBeans founder member (and one of my co-authors on the module development book) Jarda Tulach. Also, if you're a NetBeans history buff, check out A Brief History of NetBeans.

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