KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > wizards > NewAnnotationWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.ui.wizards;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21
22 import org.eclipse.ui.PlatformUI;
23
24 import org.eclipse.jdt.core.IJavaElement;
25
26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
28
29 /**
30  * Wizard page to create a new annotation type.
31  * <p>
32  * Note: This class is not intended to be subclassed, but clients can instantiate.
33  * To implement a different kind of a new annotation wizard page, extend <code>NewTypeWizardPage</code>.
34  * </p>
35  *
36  * @since 3.1
37  */

38 public class NewAnnotationWizardPage extends NewTypeWizardPage {
39
40     private final static String JavaDoc PAGE_NAME= "NewAnnotationWizardPage"; //$NON-NLS-1$
41
private final static int TYPE = NewTypeWizardPage.ANNOTATION_TYPE;
42     
43     /**
44      * Create a new <code>NewAnnotationWizardPage</code>
45      */

46     public NewAnnotationWizardPage() {
47         super(TYPE, PAGE_NAME);
48         
49         setTitle(NewWizardMessages.NewAnnotationWizardPage_title);
50         setDescription(NewWizardMessages.NewAnnotationWizardPage_description);
51     }
52
53     // -------- Initialization ---------
54

55     /**
56      * The wizard owning this page is responsible for calling this method with the
57      * current selection. The selection is used to initialize the fields of the wizard
58      * page.
59      *
60      * @param selection used to initialize the fields
61      */

62     public void init(IStructuredSelection selection) {
63         IJavaElement jelem= getInitialJavaElement(selection);
64             
65         initContainerPage(jelem);
66         initTypePage(jelem);
67         doStatusUpdate();
68     }
69     
70     // ------ validation --------
71

72     private void doStatusUpdate() {
73         // all used component status
74
IStatus[] status= new IStatus[] {
75             fContainerStatus,
76             isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
77             fTypeNameStatus,
78             fModifierStatus,
79         };
80         
81         // the mode severe status will be displayed and the OK button enabled/disabled.
82
updateStatus(status);
83     }
84
85             
86     /*
87      * @see NewContainerWizardPage#handleFieldChanged
88      */

89     protected void handleFieldChanged(String JavaDoc fieldName) {
90         super.handleFieldChanged(fieldName);
91         
92         doStatusUpdate();
93     }
94     
95     
96     // ------ UI --------
97

98     /*
99      * @see WizardPage#createControl
100      */

101     public void createControl(Composite parent) {
102         initializeDialogUnits(parent);
103         
104         Composite composite= new Composite(parent, SWT.NONE);
105         
106         int nColumns= 4;
107         
108         GridLayout layout= new GridLayout();
109         layout.numColumns= nColumns;
110         composite.setLayout(layout);
111         
112         createContainerControls(composite, nColumns);
113         createPackageControls(composite, nColumns);
114         createEnclosingTypeControls(composite, nColumns);
115                 
116         createSeparator(composite, nColumns);
117         
118         createTypeNameControls(composite, nColumns);
119         createModifierControls(composite, nColumns);
120         
121         createCommentControls(composite, nColumns);
122         enableCommentControl(true);
123         
124         setControl(composite);
125         
126         Dialog.applyDialogFont(composite);
127         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.NEW_ANNOTATION_WIZARD_PAGE);
128     }
129
130     /*
131      * @see WizardPage#becomesVisible
132      */

133     public void setVisible(boolean visible) {
134         super.setVisible(visible);
135         if (visible) {
136             setFocus();
137         }
138     }
139 }
140
Popular Tags