Lines 13-20
Link Here
|
13 |
*/ |
13 |
*/ |
14 |
package org.eclipse.mtj.ui.internal.wizards; |
14 |
package org.eclipse.mtj.ui.internal.wizards; |
15 |
|
15 |
|
|
|
16 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.CoreException; |
|
|
19 |
import org.eclipse.core.runtime.IPath; |
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
21 |
import org.eclipse.core.runtime.IStatus; |
22 |
import org.eclipse.core.runtime.Path; |
18 |
import org.eclipse.core.runtime.SubProgressMonitor; |
23 |
import org.eclipse.core.runtime.SubProgressMonitor; |
19 |
import org.eclipse.jdt.core.IJavaElement; |
24 |
import org.eclipse.jdt.core.IJavaElement; |
20 |
import org.eclipse.jdt.core.IType; |
25 |
import org.eclipse.jdt.core.IType; |
Lines 23-28
Link Here
|
23 |
import org.eclipse.jface.dialogs.IDialogSettings; |
28 |
import org.eclipse.jface.dialogs.IDialogSettings; |
24 |
import org.eclipse.jface.viewers.IStructuredSelection; |
29 |
import org.eclipse.jface.viewers.IStructuredSelection; |
25 |
import org.eclipse.mtj.core.IMTJCoreConstants; |
30 |
import org.eclipse.mtj.core.IMTJCoreConstants; |
|
|
31 |
import org.eclipse.mtj.core.internal.MTJCorePlugin; |
26 |
import org.eclipse.mtj.ui.MTJUIStrings; |
32 |
import org.eclipse.mtj.ui.MTJUIStrings; |
27 |
import org.eclipse.mtj.ui.internal.MTJUIPlugin; |
33 |
import org.eclipse.mtj.ui.internal.MTJUIPlugin; |
28 |
import org.eclipse.swt.SWT; |
34 |
import org.eclipse.swt.SWT; |
Lines 38-221
Link Here
|
38 |
* @author Craig Setera |
44 |
* @author Craig Setera |
39 |
*/ |
45 |
*/ |
40 |
public class NewMidletWizardPage extends NewTypeWizardPage { |
46 |
public class NewMidletWizardPage extends NewTypeWizardPage { |
41 |
/** The name this page is registered as within the wizard */ |
47 |
/** The name this page is registered as within the wizard */ |
42 |
public static final String PAGE_NAME = "NewMidletClass"; |
48 |
public static final String PAGE_NAME = "NewMidletClass"; |
|
|
49 |
|
50 |
// Dialog settings constants |
51 |
private static final String SETTINGS_ADD_TO_JAD = "addToJad"; |
52 |
private static final String SETTINGS_CONSTRUCTORS = "constructors"; |
53 |
private static final String SETTINGS_UNIMPLEMENTED = "unimplemented"; |
43 |
|
54 |
|
44 |
// Dialog settings constants |
55 |
// Controls |
45 |
private static final String SETTINGS_ADD_TO_JAD = "addToJad"; |
56 |
private Button addToJadButton; |
46 |
private static final String SETTINGS_CONSTRUCTORS = "constructors"; |
57 |
private Button constructorsButton; |
47 |
private static final String SETTINGS_UNIMPLEMENTED = "unimplemented"; |
58 |
private Button unimplementedButton; |
48 |
|
59 |
|
49 |
// Controls |
60 |
/** |
50 |
private Button addToJadButton; |
61 |
* @param isClass |
51 |
private Button constructorsButton; |
62 |
* @param pageName |
52 |
private Button unimplementedButton; |
63 |
*/ |
|
|
64 |
public NewMidletWizardPage() { |
65 |
super(true, PAGE_NAME); |
53 |
|
66 |
|
54 |
/** |
67 |
setTitle(MTJUIStrings.getString("wiz.newmidlet.title")); |
55 |
* @param isClass |
68 |
setDescription(MTJUIStrings.getString("wiz.newmidlet.description")); |
56 |
* @param pageName |
69 |
} |
57 |
*/ |
|
|
58 |
public NewMidletWizardPage() { |
59 |
super(true, PAGE_NAME); |
60 |
|
70 |
|
61 |
setTitle(MTJUIStrings.getString("wiz.newmidlet.title")); |
71 |
/** |
62 |
setDescription(MTJUIStrings.getString("wiz.newmidlet.description")); |
72 |
* The wizard owning this page is responsible for calling this method with |
63 |
} |
73 |
* the current selection. The selection is used to initialize the fields of |
|
|
74 |
* the wizard page. |
75 |
* |
76 |
* @param selection |
77 |
* used to initialize the fields |
78 |
*/ |
79 |
public void init(IStructuredSelection selection) { |
80 |
IJavaElement jelem = getInitialJavaElement(selection); |
81 |
initContainerPage(jelem); |
82 |
initTypePage(jelem); |
83 |
setSuperClass(IMTJCoreConstants.MIDLET_SUPERCLASS, true); |
84 |
} |
64 |
|
85 |
|
65 |
/** |
86 |
// ------ validation -------- |
66 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
87 |
/* |
67 |
*/ |
88 |
* @see org.eclipse.jdt.ui.wizards.NewClassWizardPage#doStatusUpdate |
68 |
public void createControl(Composite parent) { |
89 |
*/ |
69 |
initializeDialogUnits(parent); |
90 |
private void doStatusUpdate() { |
|
|
91 |
// status of all used components |
92 |
IStatus[] status = new IStatus[] { |
93 |
fContainerStatus, |
94 |
isEnclosingTypeSelected() ? fEnclosingTypeStatus |
95 |
: fPackageStatus, fTypeNameStatus, fModifierStatus, |
96 |
fSuperClassStatus, fSuperInterfacesStatus }; |
97 |
// the mode severe status will be displayed and the OK button |
98 |
// enabled/disabled. |
99 |
updateStatus(status); |
100 |
} |
70 |
|
101 |
|
71 |
Composite composite = new Composite(parent, SWT.NONE); |
102 |
/* |
|
|
103 |
* @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#handleFieldChanged |
104 |
*/ |
105 |
protected void handleFieldChanged(String fieldName) { |
106 |
super.handleFieldChanged(fieldName); |
107 |
doStatusUpdate(); |
108 |
} |
72 |
|
109 |
|
73 |
int nColumns = 4; |
110 |
/* |
|
|
111 |
* @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#containerChanged() |
112 |
*/ |
113 |
@Override |
114 |
protected IStatus containerChanged() { |
115 |
IStatus containerStatus = super.containerChanged(); |
116 |
String str = getPackageFragmentRootText(); |
117 |
IPath path = new Path(str); |
118 |
IResource res = getWorkspaceRoot().findMember(path); |
119 |
if (res != null) { |
120 |
int resType = res.getType(); |
121 |
if (resType == IResource.PROJECT || resType == IResource.FOLDER) { |
122 |
IProject proj = res.getProject(); |
123 |
try { |
124 |
if (!proj.hasNature(MTJCorePlugin.J2ME_NATURE_ID)) { |
125 |
if (res.exists()) { |
126 |
if (resType == IResource.PROJECT) { |
127 |
return new StatusInfo( |
128 |
IStatus.ERROR, |
129 |
MTJUIStrings |
130 |
.getString("wiz.newmidlet.warning.NotAMidletProject")); |
131 |
} else { |
132 |
return new StatusInfo( |
133 |
IStatus.ERROR, |
134 |
MTJUIStrings |
135 |
.getString("wiz.newmidlet.warning.NotInAMidletProject")); |
136 |
} |
137 |
} |
138 |
} |
139 |
} catch (CoreException e) { |
140 |
return new StatusInfo( |
141 |
IStatus.ERROR, |
142 |
MTJUIStrings |
143 |
.getString("wiz.newmidlet.warning.NotAMidletProject")); |
144 |
} |
145 |
} |
146 |
} |
147 |
return containerStatus; |
148 |
} |
74 |
|
149 |
|
75 |
GridLayout layout = new GridLayout(); |
150 |
// ------ UI -------- |
76 |
layout.numColumns = nColumns; |
151 |
/** |
77 |
composite.setLayout(layout); |
152 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
|
153 |
*/ |
154 |
public void createControl(Composite parent) { |
155 |
initializeDialogUnits(parent); |
78 |
|
156 |
|
79 |
// pick & choose the wanted UI components |
157 |
Composite composite = new Composite(parent, SWT.NONE); |
80 |
|
158 |
|
81 |
createContainerControls(composite, nColumns); |
159 |
int nColumns = 4; |
82 |
createPackageControls(composite, nColumns); |
|
|
83 |
createEnclosingTypeControls(composite, nColumns); |
84 |
|
160 |
|
85 |
createSeparator(composite, nColumns); |
161 |
GridLayout layout = new GridLayout(); |
|
|
162 |
layout.numColumns = nColumns; |
163 |
composite.setLayout(layout); |
86 |
|
164 |
|
87 |
createTypeNameControls(composite, nColumns); |
165 |
// pick & choose the wanted UI components |
88 |
createModifierControls(composite, nColumns); |
|
|
89 |
|
166 |
|
90 |
createSuperClassControls(composite, nColumns); |
167 |
createContainerControls(composite, nColumns); |
91 |
createSuperInterfacesControls(composite, nColumns); |
168 |
createPackageControls(composite, nColumns); |
92 |
createMethodStubSelectionControls(composite, nColumns); |
169 |
createEnclosingTypeControls(composite, nColumns); |
93 |
createAddToJADSelectionControl(composite, nColumns); |
|
|
94 |
|
170 |
|
95 |
boolean addToJad = true; |
171 |
createSeparator(composite, nColumns); |
96 |
boolean constructors = true; |
|
|
97 |
boolean unimplemented = true; |
98 |
|
172 |
|
99 |
IDialogSettings section = getDialogSettings().getSection(PAGE_NAME); |
173 |
createTypeNameControls(composite, nColumns); |
100 |
if (section != null) { |
174 |
createModifierControls(composite, nColumns); |
101 |
addToJad = section.getBoolean(SETTINGS_ADD_TO_JAD); |
|
|
102 |
constructors = section.getBoolean(SETTINGS_CONSTRUCTORS); |
103 |
unimplemented = section.getBoolean(SETTINGS_UNIMPLEMENTED); |
104 |
} |
105 |
|
175 |
|
106 |
addToJadButton.setSelection(addToJad); |
176 |
createSuperClassControls(composite, nColumns); |
107 |
constructorsButton.setSelection(constructors); |
177 |
createSuperInterfacesControls(composite, nColumns); |
108 |
unimplementedButton.setSelection(unimplemented); |
178 |
createMethodStubSelectionControls(composite, nColumns); |
|
|
179 |
createAddToJADSelectionControl(composite, nColumns); |
109 |
|
180 |
|
110 |
setControl(composite); |
181 |
boolean addToJad = true; |
|
|
182 |
boolean constructors = true; |
183 |
boolean unimplemented = true; |
111 |
|
184 |
|
112 |
Dialog.applyDialogFont(composite); |
185 |
IDialogSettings section = getDialogSettings().getSection(PAGE_NAME); |
113 |
} |
186 |
if (section != null) { |
|
|
187 |
addToJad = section.getBoolean(SETTINGS_ADD_TO_JAD); |
188 |
constructors = section.getBoolean(SETTINGS_CONSTRUCTORS); |
189 |
unimplemented = section.getBoolean(SETTINGS_UNIMPLEMENTED); |
190 |
} |
114 |
|
191 |
|
115 |
/** |
192 |
addToJadButton.setSelection(addToJad); |
116 |
* The wizard owning this page is responsible for calling this method with |
193 |
constructorsButton.setSelection(constructors); |
117 |
* the current selection. The selection is used to initialize the fields of |
194 |
unimplementedButton.setSelection(unimplemented); |
118 |
* the wizard page. |
|
|
119 |
* |
120 |
* @param selection used to initialize the fields |
121 |
*/ |
122 |
public void init(IStructuredSelection selection) { |
123 |
IJavaElement jelem = getInitialJavaElement(selection); |
124 |
initContainerPage(jelem); |
125 |
initTypePage(jelem); |
126 |
setSuperClass(IMTJCoreConstants.MIDLET_SUPERCLASS, true); |
127 |
} |
128 |
|
195 |
|
129 |
/** |
196 |
setControl(composite); |
130 |
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) |
|
|
131 |
*/ |
132 |
public void setVisible(boolean visible) { |
133 |
super.setVisible(visible); |
134 |
if (visible) { |
135 |
setFocus(); |
136 |
} |
137 |
} |
138 |
|
197 |
|
139 |
/** |
198 |
Dialog.applyDialogFont(composite); |
140 |
* Return a boolean indicating whether the "add to jad" button was selected. |
199 |
} |
141 |
* |
|
|
142 |
* @return |
143 |
*/ |
144 |
boolean isAddToJadSelected() { |
145 |
return addToJadButton.getSelection(); |
146 |
} |
147 |
|
200 |
|
148 |
/** |
201 |
/** |
149 |
* @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#createTypeMembers(org.eclipse.jdt.core.IType, |
202 |
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) |
150 |
* org.eclipse.jdt.ui.wizards.NewTypeWizardPage.ImportsManager, |
203 |
*/ |
151 |
* org.eclipse.core.runtime.IProgressMonitor) |
204 |
public void setVisible(boolean visible) { |
152 |
*/ |
205 |
super.setVisible(visible); |
153 |
protected void createTypeMembers(IType newType, ImportsManager imports, |
206 |
if (visible) { |
154 |
IProgressMonitor monitor) throws CoreException { |
207 |
setFocus(); |
155 |
createInheritedMethods(newType, constructorsButton.getSelection(), |
208 |
} |
156 |
unimplementedButton.getSelection(), imports, |
209 |
} |
157 |
new SubProgressMonitor(monitor, 1)); |
|
|
158 |
|
210 |
|
159 |
IDialogSettings section = MTJUIPlugin.getDialogSettings( |
211 |
/** |
160 |
getDialogSettings(), PAGE_NAME); |
212 |
* Return a boolean indicating whether the "add to jad" button was selected. |
161 |
section.put(SETTINGS_ADD_TO_JAD, addToJadButton.getSelection()); |
213 |
* |
162 |
section.put(SETTINGS_CONSTRUCTORS, constructorsButton.getSelection()); |
214 |
* @return |
163 |
section.put(SETTINGS_UNIMPLEMENTED, unimplementedButton.getSelection()); |
215 |
*/ |
164 |
} |
216 |
boolean isAddToJadSelected() { |
|
|
217 |
return addToJadButton.getSelection(); |
218 |
} |
165 |
|
219 |
|
166 |
/** |
220 |
/** |
167 |
* Create the "Add to JAD" selection control. |
221 |
* @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#createTypeMembers(org.eclipse.jdt.core.IType, |
168 |
* |
222 |
* org.eclipse.jdt.ui.wizards.NewTypeWizardPage.ImportsManager, |
169 |
* @param parent |
223 |
* org.eclipse.core.runtime.IProgressMonitor) |
170 |
* @param numColumns |
224 |
*/ |
171 |
*/ |
225 |
protected void createTypeMembers(IType newType, ImportsManager imports, |
172 |
private void createAddToJADSelectionControl(Composite parent, int numColumns) { |
226 |
IProgressMonitor monitor) throws CoreException { |
173 |
new Label(parent, SWT.NONE); |
227 |
createInheritedMethods(newType, constructorsButton.getSelection(), |
174 |
Composite composite = new Composite(parent, SWT.NONE); |
228 |
unimplementedButton.getSelection(), imports, |
|
|
229 |
new SubProgressMonitor(monitor, 1)); |
175 |
|
230 |
|
176 |
GridLayout layout = new GridLayout(); |
231 |
IDialogSettings section = MTJUIPlugin.getDialogSettings( |
177 |
layout.numColumns = 1; |
232 |
getDialogSettings(), PAGE_NAME); |
178 |
composite.setLayout(layout); |
233 |
section.put(SETTINGS_ADD_TO_JAD, addToJadButton.getSelection()); |
|
|
234 |
section.put(SETTINGS_CONSTRUCTORS, constructorsButton.getSelection()); |
235 |
section.put(SETTINGS_UNIMPLEMENTED, unimplementedButton.getSelection()); |
236 |
} |
179 |
|
237 |
|
180 |
GridData gridData = new GridData(); |
238 |
/** |
181 |
gridData.grabExcessHorizontalSpace = true; |
239 |
* Create the "Add to JAD" selection control. |
182 |
gridData.horizontalSpan = numColumns - 1; |
240 |
* |
183 |
composite.setLayoutData(gridData); |
241 |
* @param parent |
|
|
242 |
* @param numColumns |
243 |
*/ |
244 |
private void createAddToJADSelectionControl(Composite parent, int numColumns) { |
245 |
new Label(parent, SWT.NONE); |
246 |
Composite composite = new Composite(parent, SWT.NONE); |
184 |
|
247 |
|
185 |
addToJadButton = new Button(composite, SWT.CHECK); |
248 |
GridLayout layout = new GridLayout(); |
186 |
addToJadButton.setText("Add To Application Descriptor?"); |
249 |
layout.numColumns = 1; |
187 |
} |
250 |
composite.setLayout(layout); |
188 |
|
251 |
|
189 |
/** |
252 |
GridData gridData = new GridData(); |
190 |
* Create the controls for method stub selection. |
253 |
gridData.grabExcessHorizontalSpace = true; |
191 |
* |
254 |
gridData.horizontalSpan = numColumns - 1; |
192 |
* @param composite |
255 |
composite.setLayoutData(gridData); |
193 |
*/ |
|
|
194 |
private void createMethodStubSelectionControls(Composite parent, |
195 |
int numColumns) { |
196 |
new Label(parent, SWT.NONE); |
197 |
Composite composite = new Composite(parent, SWT.NONE); |
198 |
|
256 |
|
199 |
GridLayout layout = new GridLayout(); |
257 |
addToJadButton = new Button(composite, SWT.CHECK); |
200 |
layout.numColumns = 1; |
258 |
addToJadButton.setText("Add To Application Descriptor?"); |
201 |
composite.setLayout(layout); |
259 |
} |
202 |
|
260 |
|
203 |
GridData gridData = new GridData(); |
261 |
/** |
204 |
gridData.grabExcessHorizontalSpace = true; |
262 |
* Create the controls for method stub selection. |
205 |
gridData.horizontalSpan = numColumns - 1; |
263 |
* |
206 |
composite.setLayoutData(gridData); |
264 |
* @param composite |
|
|
265 |
*/ |
266 |
private void createMethodStubSelectionControls(Composite parent, |
267 |
int numColumns) { |
268 |
new Label(parent, SWT.NONE); |
269 |
Composite composite = new Composite(parent, SWT.NONE); |
207 |
|
270 |
|
208 |
Label l = new Label(composite, SWT.NONE); |
271 |
GridLayout layout = new GridLayout(); |
209 |
l.setText(MTJUIStrings.getString("wiz.newmidlet.which_methods")); |
272 |
layout.numColumns = 1; |
|
|
273 |
composite.setLayout(layout); |
210 |
|
274 |
|
211 |
constructorsButton = new Button(composite, SWT.CHECK); |
275 |
GridData gridData = new GridData(); |
212 |
constructorsButton.setText(MTJUIStrings |
276 |
gridData.grabExcessHorizontalSpace = true; |
213 |
.getString("wiz.newmidlet.super_const")); |
277 |
gridData.horizontalSpan = numColumns - 1; |
214 |
constructorsButton.setSelection(true); |
278 |
composite.setLayoutData(gridData); |
215 |
|
279 |
|
216 |
unimplementedButton = new Button(composite, SWT.CHECK); |
280 |
Label l = new Label(composite, SWT.NONE); |
217 |
unimplementedButton.setText(MTJUIStrings |
281 |
l.setText(MTJUIStrings.getString("wiz.newmidlet.which_methods")); |
218 |
.getString("wiz.newmidlet.unimplemented")); |
282 |
|
219 |
unimplementedButton.setSelection(true); |
283 |
constructorsButton = new Button(composite, SWT.CHECK); |
220 |
} |
284 |
constructorsButton.setText(MTJUIStrings |
|
|
285 |
.getString("wiz.newmidlet.super_const")); |
286 |
constructorsButton.setSelection(true); |
287 |
|
288 |
unimplementedButton = new Button(composite, SWT.CHECK); |
289 |
unimplementedButton.setText(MTJUIStrings |
290 |
.getString("wiz.newmidlet.unimplemented")); |
291 |
unimplementedButton.setSelection(true); |
292 |
} |
221 |
} |
293 |
} |