Geertjan's Blog

  • November 27, 2005

You Too Can Make Drag-And-Drop Component Palettes

Geertjan Wielenga
Product Manager
Similar to my previous blog entry, but this time with an XML file—it's very easy to use the NetBeans Palette API together with the New File Type wizard. Here you see a palette of drag-and-drop components especially for the jboss-web.xml file:

So, the palette that you see above is only visible when a jboss-web.xml file is open in the NetBeans editor. You too can do this! Firstly, use the New Module wizard to create a NetBeans module project. Secondly, use the New File wizard to generate files for distinguishing jboss-web.xml files from all other files (i.e., via its public namespace). Thirdly, the only part that is slightly tricky (because there isn't a wizard for this yet), implement the NetBeans Palette API and associate the pallete with the new file type by implementing the associatePalette method in the XXXEditorSupport.java file. Finally, register the new component palette in the module's layer.xml file.

And that's it. Once you've done this for one file type, it's very easy to do for any/all others—a little bit of copying and pasting can go a very long way! (However, note that I need to work out how to not disable syntax highlighting when enabling the component palette...)

Postscript: Worked it out! I'm now reusing the XML editor, so I get the syntax highlighting that the XML editor provides. I've done this by making sure that the MIME type everywhere is the same (I had different MIME types in different places, which was a bit stupid) and making sure that the MIME type ends in "+XML". So, my jboss-web.xml MIME type is text/jboss+xml. However, I'm using the MIME resolver to distinguish between this type of XML file and all other XML files:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.0//EN" "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
<ext name="xml"/>
<resolver mime="text/jboss+xml">
<doctype public-id="-//JBoss//DTD Web Application 2.3//EN"/>

And so here is the result:

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.