Geertjan's Blog

  • October 5, 2006

Extending a Component Palette. Help Needed! (Part 2)

Geertjan Wielenga
Product Manager
Since the label, tooltip, and icons for a palette item are all set within a module (rather than outside of it), so that the user (instead of the developer) cannot create them, I've worked around the issue by giving the user some options. For example, let's say the user makes a selection in an HTML file. Then the user right-clicks and chooses "Add to Palette". What the user then sees is this dialog box:

Hard coded in the dialog box are about 15 different labels and 5 different icons. The user selects one of each and tweaks the selected HTML tags, if necessary. Then the user clicks OK. Immediately the HTML category of the HTML Palette contains the new palette item:

And now, the user can drag that item and drop it in an HTML file. When he/she does so, the HTML selection made at the start is dropped in the HTML file.

And how is this possible? All because when the user clicked OK in the dialog box, the following XML file (called "header_1.xml", in the example above) was created in the user directory's HTMLPalette/HTML folder:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE editor_palette_item PUBLIC "-//NetBeans//Editor Palette Item 1.0//EN"
<editor_palette_item version="1.0">
<icon16 urlvalue="org/netbeans/modules/extendhtmlpalette/Datasource16.png" />
<icon32 urlvalue="org/netbeans/modules/extendhtmlpalette/Datasource32.png" />
<description localizing-bundle="org.netbeans.modules.extendhtmlpalette.Bundle"

Because of the DTD and root element, the Component Palette recognizes it as a palette item and displays it. The IDE also allows the user to drag and drop the tags in this file into the Source Editor. Handy, right? If you're interested in this module, you can download the NBM file here (created and built in NetBeans IDE 5.5 RC1):


Join the discussion

Comments ( 14 )
  • GP Thursday, October 19, 2006
    Not very useful since works only for HTML.
  • Geertjan Thursday, October 19, 2006
    Is a car not very useful because it can't fly? No. That's what airplanes are for. This palette does what it does and works for what it is meant to work. I also have a Java palette, for Java code snippets. If that's what you want, that's also available.
  • GP Saturday, October 21, 2006
    I mean that your car only for one kind of road ;) Seems that this plug-in does not work in jsp editor.
  • Geertjan Saturday, October 21, 2006
    That's because it is an extension to the HTML Palette, not an extension to the JSP Palette.
  • GP Saturday, October 21, 2006
    I see :) Could you extend jsp palette in this way?
    Plain html files is not often used in web development.
  • Geertjan Saturday, October 21, 2006
  • GP Saturday, October 21, 2006
    One thing - a new element appears in palette only after "Refresh Palette" (NB 5.5 RC2).
  • Geertjan Saturday, October 21, 2006
    I made it in and for 5.0. So if it works anywhere else, that's nice, but then you're on your own. (Maybe restart the IDE and see if this problem persists.)
  • GP Saturday, October 21, 2006
    Restart does not help. But anyway - it is better than nothing. ;)
  • Geertjan Saturday, October 21, 2006
    Cool. I'm sure this type of functionality will be a standard part of NetBeans 6 (not promising, just guessing, but guessing with confidence).
  • Blaise Tuesday, December 19, 2006
    Yeah great !
    But i can't change the name and the icon... And when i manually edit the .xml file NetBeans don't show 'display-name-key' and 'tooltip-key'.
    <description localizing-bundle="org.netbeans.modules.extendjsppalette.Bundle"
    tooltip-key="Hidden input"/>
  • MadSoulja Saturday, December 30, 2006
    I'm new to the whole Sun thing. Been "dabbling" around with it since ALL the universities where I live moved to Java as the main programming language to teach programming. I gotta admit, that html thing is a niffty little trick.
  • jinriver Monday, January 8, 2007
    Thank you for your plugin
  • Vladimir Thursday, May 17, 2007
    any chance to get org-netbeans-modules-extendRHTMLpalette.nbm module?
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.