ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Eclipse Plugins Exposed, Part 3: Customizing a Wizard
Pages: 1, 2, 3, 4, 5, 6

Validation Classes

Validation can be done in any part of the plugin with which the user enters data. Thus, it makes sense to put the validation code in reusable classes, rather than having multiple copies all over the place. The following is an example of a validation class.

public class InterfacesValidator implements ICellEditorValidator
{
    public String isValid(Object value)
    {
        if( !( value instanceof String) )
            return null;

        String interfaces = ((String)value).trim();
        if( interfaces.equals(""))
            return null;

        String[] interfaceArray = interfaces.split(",");
        for (int i = 0; i < interfaceArray.length; i++)
        {
            IStatus status = JavaConventions
                    .validateJavaTypeName(interfaceArray[i]);
            if (status.getCode() != IStatus.OK)
                return "Validation of interface " + interfaceArray[i]
                        + ": " + status.getMessage();
        }
        return null;
    }
}

The other validation classes are very similar to this one--refer to the source code at the end of the article.

Another nifty class in the Eclipse arsenal is JavaConventions, which validates this data for us! It contains many validation methods, such as:

  • validateJavaTypeName() to check class and interface names.
  • validatePackageName() to check package names.
  • validateFieldName() to check data member names.
  • validateMethodName() to check method names.
  • validateIdentifierName() to check variable names.

The interface ICellEditorValidator is not needed right now, but we will need it in the next article.

The Result

At this point, we have a working wizard with a graphic and a second page, which creates our initial Invokatron document. Figure 2 shows the result:

Customized Wizard

Figure 2. Customized wizard

Shiny Gizmo

As we've seen, it is data that often drives applications. Presentation is important, too. An ugly gizmo won't sell; a shiny one may. But data is the very nature of what we, programmers, do.

In this article, we first decided on the data we would process. Secondly, we captured visually this data in the form of a customized wizard. The next article will continue on the presentation side, with a customized editor and property page.

Resources

Emmanuel Proulx is an expert in J2EE and Enterprise JavaBeans, and is a certified WebLogic Server 7.0 engineer. He works in the fields of telecommunications and web development.


Return to ONJava.com.