X

Geertjan's Blog

  • June 26, 2007

Validation for Visual Editors

Geertjan Wielenga
Product Manager
Made some progress but still quite a long way to go. Below you see an XML file that conforms to the Palette Editor Item DTD, which is the DTD that defines the XML files that are used to display items in the palette. For example, the HTML code snippets in NetBeans IDE are defined by means of this XML file. Of course, a visual view for this XML file is completely superfluous, because one would never edit these by hand. A developer would let the user perform actions to generate these, without the user even knowing that this is happening. The user would never have any direct interaction with this XML file. However, it's interesting for purposes of playing with the XML Multiview API. Here's the current status of the editor:

One interesting thing is that this API comes with its own validation framework. The "WARNING" dialog box that you see above was not created by me. Instead, the API comes with a listener that you can set on a text component and then, whenever a change is made to the text component, the API's documentChanged() method is called, which returns an error message (that can be seen in the bottom left corner above), as well as the WARNING dialog box. Here's an example of this documentChanged() method, filled out for the first text field above:

public void documentChanged(javax.swing.text.JTextComponent comp, String value) {
if (comp == jTextField1) {
String val = value;
if (val.length() == 0) {
getSectionView().getErrorPanel().setError(new Error(Error.MISSING_VALUE_MESSAGE, "class", comp));
return;
}
getSectionView().getErrorPanel().clearError();
}
}

However, since this API isn't 'stable', it isn't officially supported, and I couldn't even find official Javadoc for it. I'm hoping we'll either accept this API, even though it is complex, or create a new simple one. Either way, many developers want an API that provides a visual editor such as the above and the current complexity of the API shouldn't result in developers not being able to use it at all.

I still have various problems with the editor. Although, thanks to Vadiraj, the visual part works better than before, it doesn't work correctly yet. The source view correctly updates the visual view. But when the visual view changes, weird things happen in the source view, such as the fact that the entire DOCTYPE declaration disappears! And so do the comments near the top of the XML file. And only sometimes is the source correctly updated. On the other hand, the "Save" button is always correctly enabled, whenever I make a change to the visual side (as well as to the source). But these weirdnesses just indicate that I have some more work to do.

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.