Geertjan's Blog

  • October 12, 2006

Initialize the Palette!

Geertjan Wielenga
Product Manager
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 name="Expert"><attr name="isReadonly" stringvalue="false"/>
<file name="PaletteItem_2.myitem" url="palette/jackOfDiamonds.myitem"><attr name="isReadonly" stringvalue="true"/>
<file name="PaletteItem_3.myitem" url="palette/kingOfDiamonds.myitem"/>

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");

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.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.