Just An Application

October 30, 2009

An Extended NewAnnotation Wizard For Eclipse: Implementing A Wizard Page

Filed under: Eclipse, Eclipse Plugins, Eclipse Wizards, Java — Tags: , , , — Simon Lewis @ 12:41 pm

The new wizard page is implemented by the class

    xper.eclipse.plugin.jdt.ui.annotation.NewAnnotationWizardPage

which sub-classes

    org.eclipse.jdt.ui.wizards.NewTypeWizardPage

following the example in JDT Plug-in Developer Guide:Programmer’s Guide:JDT UI: Java wizard pages

The constructor is based on that from the equivalent Eclipse supplied class as follows


        NewAnnotationWizardPage() 
        {
            super(ANNOTATION_TYPE, "NewAnnotationWizardPage");
            setTitle(NewWizardMessages.NewAnnotationWizardPage_title);
            setDescription(NewWizardMessages.NewAnnotationWizardPage_description);
            retention = RetentionPolicy.CLASS;
            targets   = EnumSet.noneOf(ElementType.class);
        }

as is the initialization method

        void init(IStructuredSelection theSelection) 
        {
            IJavaElement element= getInitialJavaElement(theSelection);

            initContainerPage(element);
            initTypePage(element);
            retention = RetentionPolicy.CLASS;
            targets.clear();
            updateStatus();
        }

The initContainerPage(IJavaElement) method is inherited from

    org.eclipse.jdt.ui.wizards.NewContainerWizardPage

which is the super-class of NewTypeWizardPage.

The initTypePage(IJavaElement) method is inherited from NewTypeWizardPage.

You might expect that this method would invoke initContainerPage(IJavaElement) itself but apparently not.

The updateStatus() method is as follows.


        private void updateStatus()
        {
            updateStatus(
                new IStatus[] 
                {
                    fContainerStatus,
                    isEnclosingTypeSelected() 
                        ? 
                        fEnclosingTypeStatus 
                        : 
                        fPackageStatus,
                    fTypeNameStatus,
                    fModifierStatus,
                });
        }

It is responsible for collecting together the statuses of all the data required to construct the Annotation
and passing them to the updateStatus(IStatus[]) method inherited from the

    org.eclipse.jdt.ui.wizards.NewElementWizardPage

class.

This method then updates the status of the wizard page as appropriate.

For example, if all the necessary data is present and there are no problems with it then the ‘Finish’ or ‘Next’ button will be enabled.

Alternatively if, for example, a name for the Annotation has been entered and then deleted then fTypeNameStatus has an IStatus value with a severity of ERROR and the message

    Type name is empty.

which is duly displayed by the wizard as shown below.

TypeNameIsEmpty

Since an Annotation can legally be defined without any annotation this method is the same as that of the equivalent Eclipse supplied class.


Copyright (c) 2009 By Simon Lewis. All Rights Reserved

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: