Tuesday March 13, 2007
Palette API and 6.0, Testing the Waters... (Part 2)
Continuing with my explorations of the latest improvements for the Palette API, I've created a small module that you can use to select code in the Java editor. You select some code, right-click with the mouse, and choose "Add to Palette". Then a dialog box pops up, with a small Java editor containing your selection. Once you've set the category, display name, and tooltip (and, possibly, tweaked the code snippet that you selected), you press OK and then the snippet is added to the palette for Java files. This palette is also created by this module (ultimately it should be created conditionally, the first time the user selects a snippet from the editor). Then, you can drag the item from the palette and, on the drop, the selected code snippet is dropped in the editor. Here's how the whole story looks visually:
So, this is in a very recent 6.0 build, because I registered the palette in the layer and I'm using the 1.1 version of the palette item DTD. Here's everything I needed to create in this module to make it all possible:
Click here to download the module. Note, again, that you need a very recent daily build to use this module. I don't think it is possible to let the user choose an icon (small icon and large icon). So, in the module an icon is included (which is used both for small and large display, currently) which is used for each new palette item. Ultimately, the combo box should read the folders in the layer and display them, so that you can either choose an existing category or create your own. Currently you can only create your own.
Apart from the small/large icon issue, I think the new palette item DTD is great. Much more flexible than before, where the description and tooltip had to come from a resource bundle. Being able to register the palette in the layer is great too. Without that, the module would have been a LOT larger, because I would have had to create a new data object for Java files, and override the standard one. That's a pretty messy solution, which I've tried elsewhere in this blog. In fact, you'd have to create an entire new Java editor. MIME type registration in the layer file is the secret behind this palette for Java files.
By the way, this entire module was created on... a Sun Ray 170. Hurray for Sun Ray 170.
Update. I created issue 97812 for the icon problem discussed above.
Mar 13 2007, 12:07:36 PM PDT Permalink


