Geertjan's Blog

  • December 10, 2005

Create a Multiview Editor in NetBeans IDE 5.0 (Part 2)

Geertjan Wielenga
Product Manager
I've applied Dave Havrda's (see yesterday's blog entry) multiview editor to my own data object—one that I made for the JBoss deployment descriptor (jboss-web.xml). Earlier, I made a component palette for this file type (see the NetBeans Component Palette Module Tutorial), and now it has a multiview editor, as you can see when you click the images below to enlarge them (however, the multiview editor seems to cancel out the component palette, which is one of several issues I need to resolve):

While working on this multiview editor (a.k.a. Visual Editor in the NetBeans help files, tutorials, and other documentation), I encountered a lot of "boilerplate code". I find this pretty disturbing. I mean, if there are very large chunks of code that I need to simply copy and paste from one implementation of an API to another, doesn't that mean that there's something wrong with the API? One culprit in this department is the DataEditorSupport class. To me, this just seems like a big container for anything that an editor might need. It's potentially massive, with inner classes such as DataEditorSupport.Env, which I always have to use, but never have to modify. (This is also a big problem in the NetBeans module tutorials—if I know that people don't need to know all the details of what a class is for, because they're simply going to copy and paste it, then there's no need to describe it. But then, it looks really odd to have big chunks of unexplained code in a tutorial.) If we really want people to quickly pick up and use the NetBeans APIs, I think we should hide as much of these things as possible and only force developers to implement the methods that need to be customized. If a method or inner class does not need to be customized, why do I need to include it in my implementation?! I mean, I copied masses of stuff from Dave's simple implementation (shown yesterday) and then adapted it for my own purposes. I know that that's how it's always done, but still think that a lot of it shouldn't be necessary. So, to make things a bit more workable, I used a lot of code folds (I created a code template for these). That makes a huge difference, of course, as you can see below (click to enlarge):

Many cool things flow from using code folds—for example, when you hover your mouse over a code fold, a big pop-up appears with the content of the fold, so that you don't need to open the fold to see what's in it.

Interestingly, adding a multiview editor for a file type is really not very difficult (apart from the aforementioned massive blocks of boilerplate code). And the IDE is very helpful when you're making multiview editors—it provides the New Window Component wizard, which generates the window and all accompanying serialization files all in one go. (And, earlier on, the file type is also recognized by the IDE thanks to files generated by a wizard, in this case the New File Type wizard.) Once you've used the New Window Component wizard, you're off to a solid start. Implement the MultiViewElement (as will be explained in an upcoming tutorial, once I resolve the issues I encountered) and work with the aforementioned implementation of DataEditorSupport, and you're done. I'm making it sound easy, but it's pretty tricky (and without Dave's example code I wouldn't have got very far).

But the end result is pretty cool! A multiview editor is basically a visual form of code completion—you don't need to know all the elements and attributes (or whatever items the file type uses), because the component provides text fields and other components, such as comboboxes and drop-downlists (enabling some properties to be pre-defined, or mandatory, or both) for you to fill in. And, for relatively little work, including a multiview editor in your module for a new file type is sure to be an impressive extra to the more fundamental editor features, such as syntax highlighting. So, watch this space for the announcement of a new tutorial!

Join the discussion

Comments ( 5 )
  • Vivek Saturday, October 7, 2006
    Hi Geertjan,
    As referred by you, I was going through "NetBeans Component Palette Module Tutorial" (http://platform.netbeans.org/tutorials/nbm-palette-api2.html).
    I've followed all the steps and build the module. When I installed the module, I was able to see my code in "Tools"-->"Palette Manager"-->"JBoss Code Clips". But when I opened the file with the given namespace, Netbeans recognised it as a Jboss file type but didn't opened the palette for that file.
    I think we are missing something in the tutorial. There is no mapping between the new JBoss file type and the new palette. How will netbeans know that it need to open a palette for JBoss file type? Can you please tell me what you found on this.
  • Geertjan Saturday, October 7, 2006
    Hi Vivek, the sample is attached to the tutorial. Why don't you download it and install it? Then see where it is different to yours.
  • Emmanuel Thursday, January 15, 2009

    Is Copy & Paste enabled in this example? I tried the sample from the RCP Book (MULTIVIEW EDITORS) but somehow the copy&paste (Also Undo/Redo) actions don't work. How can I enable those actions without having to write that much code?


  • Geertjan Thursday, January 15, 2009

    Hi Emmanuel, this blog entry should get you started in the right direction:


  • Emmanuel Thursday, January 15, 2009

    Thanks Geertjan, your post helped me a lot to implement the UNDO and REDO actions, I found a great post on the COPY & PASTE actions, it turned out that I was overriding the transfer handler in my editor, so I had to implement the COPY & PASTE actions in the transfer handler.

    Here is the link to the page that helped me solve my problem:



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