KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > examples > jet > article2 > ui > NewTypesafeEnumCreationWizardPage


1 package org.eclipse.emf.examples.jet.article2.ui;
2
3
4
5 import org.eclipse.core.runtime.IStatus;
6 import org.eclipse.jdt.core.IJavaElement;
7 import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
8 import org.eclipse.jface.dialogs.Dialog;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.events.ModifyEvent;
12 import org.eclipse.swt.events.ModifyListener;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
18
19 import org.eclipse.emf.examples.jet.article2.model.TypesafeEnum;
20
21
22 /**
23  * Wizard page where the user can specify the class name, package, source
24  * folder, and other type-related information on the typesafe enumeration class
25  * to create.
26  *
27  * @author Remko Popma
28  * @version $Revision: 1.1 $ ($Date: 2004/05/31 21:35:35 $)
29  */

30 public class NewTypesafeEnumCreationWizardPage extends NewTypeWizardPage
31 {
32
33   protected final static String JavaDoc PAGE_NAME = "NewTypesafeEnumCreationWizardPage"; //$NON-NLS-1$
34

35   protected TypesafeEnum mTypesafeEnumModel = new TypesafeEnum();
36
37   private Text mTextAuthor = null;
38
39   private Text mTextVersion = null;
40
41   /**
42    * @param isClass
43    * @param pageName
44    */

45   public NewTypesafeEnumCreationWizardPage()
46   {
47     super(true, PAGE_NAME);
48     setTitle(WizardMessages.getString("NewEnumWizPage.title")); //$NON-NLS-1$
49
setDescription(WizardMessages.getString("NewEnumWizPage.description")); //$NON-NLS-1$
50
}
51
52   /**
53    * The wizard owning this page is responsible for calling this method with the
54    * current selection. The selection is used to initialize the fields of the
55    * wizard page.
56    *
57    * @param selection
58    * used to initialize the fields
59    */

60   public void init(IStructuredSelection selection)
61   {
62     IJavaElement jelem = getInitialJavaElement(selection);
63     initContainerPage(jelem);
64     initTypePage(jelem);
65     doStatusUpdate();
66
67     // boolean createMain= false;
68
// boolean createConstructors= false;
69
// boolean createUnimplemented= true;
70
// IDialogSettings section= getDialogSettings().getSection(PAGE_NAME);
71
// if (section != null) {
72
// createMain= section.getBoolean(SETTINGS_CREATEMAIN);
73
// createConstructors= section.getBoolean(SETTINGS_CREATECONSTR);
74
// createUnimplemented= section.getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
75
// }
76
//
77
// setMethodStubSelection(createMain, createConstructors,
78
// createUnimplemented, true);
79
}
80
81   // ------ validation --------
82
private void doStatusUpdate()
83   {
84     // status of all used components
85
IStatus[] status = new IStatus []{
86       fContainerStatus,
87       isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
88       fTypeNameStatus,
89       fModifierStatus,
90       fSuperClassStatus,
91       fSuperInterfacesStatus };
92
93     updateEnumType();
94
95     // the mode severe status will be displayed and the ok button
96
// enabled/disabled.
97
updateStatus(status);
98   }
99
100   /**
101    * Updates the <code>TypesafeEnum</code> model from the user input.
102    */

103   private void updateEnumType()
104   {
105     getTypesafeEnumModel().setClassName(getTypeName());
106     getTypesafeEnumModel().setPackageName(getPackageText());
107   }
108
109   /**
110    * @see IWizardPage#canFlipToNextPage
111    */

112   public boolean canFlipToNextPage()
113   {
114     boolean complete = isPageComplete();
115     boolean hasNext = (getNextPage() != null);
116     return complete && hasNext;
117   }
118
119   /*
120    * @see NewContainerWizardPage#handleFieldChanged
121    */

122   protected void handleFieldChanged(String JavaDoc fieldName)
123   {
124     super.handleFieldChanged(fieldName);
125
126     doStatusUpdate();
127   }
128
129   /*
130    * (non-Javadoc)
131    *
132    * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
133    */

134   public void createControl(Composite parent)
135   {
136     initializeDialogUnits(parent);
137
138     Composite composite = new Composite(parent, SWT.NONE);
139
140     int nColumns = 4;
141
142     GridLayout layout = new GridLayout();
143     layout.numColumns = nColumns;
144     composite.setLayout(layout);
145
146     // pick & choose the wanted UI components
147

148     createContainerControls(composite, nColumns);
149     createPackageControls(composite, nColumns);
150
151     createSeparator(composite, nColumns);
152
153     createTypeNameControls(composite, nColumns);
154
155     createAuthorVersionControls(composite, nColumns);
156
157     // createModifierControls(composite, nColumns);
158
// createSuperClassControls(composite, nColumns);
159
// createSuperInterfacesControls(composite, nColumns);
160

161     setSuperClass("java.lang.Object", true);
162
163     setControl(composite);
164
165     //set default and focus
166
// restoreWidgetValues();
167
Dialog.applyDialogFont(composite);
168     // WorkbenchHelp.setHelp(composite,
169
// IJUnitHelpContextIds.NEW_TESTCASE_WIZARD_PAGE);
170
}
171
172   /**
173    * @param composite
174    * @param nColumns
175    */

176   private void createAuthorVersionControls(Composite parent, int nColumns)
177   {
178     Label author = new Label(parent, SWT.NONE);
179     author.setText(WizardMessages.getString("NewEnumWizPage.author"));
180     mTextAuthor = new Text(parent, SWT.SINGLE | SWT.BORDER);
181     mTextAuthor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
182     mTextAuthor.addModifyListener(new ModifyListener()
183       {
184
185         public void modifyText(ModifyEvent e)
186         {
187           getTypesafeEnumModel().setAuthor(mTextAuthor.getText());
188         }
189       });
190     mTextAuthor.setText(System.getProperty("user.name"));
191
192     new Label(parent, SWT.NONE);
193     new Label(parent, SWT.NONE);
194
195     Label version = new Label(parent, SWT.NONE);
196     version.setText(WizardMessages.getString("NewEnumWizPage.version"));
197     mTextVersion = new Text(parent, SWT.SINGLE | SWT.BORDER);
198     mTextVersion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
199     mTextVersion.addModifyListener(new ModifyListener()
200       {
201
202         public void modifyText(ModifyEvent e)
203         {
204           getTypesafeEnumModel().setVersion(mTextVersion.getText());
205         }
206       });
207     mTextVersion.setText("1.0");
208
209     new Label(parent, SWT.NONE);
210     new Label(parent, SWT.NONE);
211   }
212
213   /**
214    * Returns the <code>TypesafeEnum</code> instance manipulated by the wizard
215    * pages.
216    *
217    * @return the <code>TypesafeEnum</code> instance
218    */

219   public TypesafeEnum getTypesafeEnumModel()
220   {
221     return mTypesafeEnumModel;
222   }
223 }
Popular Tags