KickJava   Java API By Example, From Geeks To Geeks.

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


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 enum 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 enum wizard page, extend <code>NewTypeWizardPage</code>.
34  * </p>
35  *
36  * @since 3.1
37  */

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

46     public NewEnumWizardPage() {
47         super(TYPE, PAGE_NAME);
48         
49         setTitle(NewWizardMessages.NewEnumWizardPage_title);
50         setDescription(NewWizardMessages.NewEnumWizardPage_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
68         doStatusUpdate();
69     }
70     
71     // ------ validation --------
72

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

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

100     /*
101      * @see WizardPage#createControl
102      */

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

138     public void setVisible(boolean visible) {
139         super.setVisible(visible);
140         if (visible) {
141             setFocus();
142         }
143     }
144     
145 }
146
Popular Tags