Geertjan's Blog

  • June 4, 2007

Sample for Registering Palettes in Layers

Geertjan Wielenga
Product Manager
There've been lots of questions recently about the new 6.0 functionality that allows you to register palettes in the layer file. Previously, the palette had to be created in the editor's constructor. Now, since it can be registered in the layer file, you can create a palette in a different module to where the target editor is found. The most applicable scenario seems to me to be the one where you want to create palette items for Java source files. In the past, you'd have to patch the NetBeans sources that define the Java editor. Now, you can just register the palette in the text/x-java folder and it will appear, as if by magic, when a Java source file is open.

To see the mechanics of the above, go here:

Java Source File Palette Sample

Install the NBM you get there, open the New Project wizard, and then you'll have this new sample, which is self-explanatory:

Once the sample is installed, you get a palette with the one 'Main Method' item:

Then, once you've established that it works (i.e, drag and drop an item, type in a comment, and note the code that's generated when you click OK) you can inspect the sample's code and learn from it, and adapt it for your own purposes. Make very sure you have the latest build you can get, because bugs have been fixed in this area very recently. If the sample doesn't work for you, the chances are that the reason is that you don't have the latest build.

Join the discussion

Comments ( 4 )
  • Sandip Monday, June 4, 2007
    Will it be possible to hook the insertion of palette item text with the CodeTemplate APIs so that CodeTemplate Parameters could be substituted. Then one could take advantage of the parameters handled by the CodeTemplateProcessors such as ${selection}, ${Identifier} and so on...




    Just an idea :)

  • Sandip Monday, June 4, 2007
    And one more API to create your code template on the fly using the text of your palette item:
  • Youmna Wednesday, August 8, 2007

    the above link is not working. It takes me to the plug-ins main page. I cannot download the example.

  • Geertjan Wednesday, August 8, 2007
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.