|
11 | 11 | package ts.eclipse.ide.ui.wizards;
|
12 | 12 |
|
13 | 13 | import java.io.File;
|
14 |
| -import java.util.ArrayList; |
15 | 14 | import java.util.List;
|
16 | 15 |
|
17 | 16 | import org.eclipse.core.resources.IResource;
|
18 | 17 | import org.eclipse.core.runtime.IStatus;
|
19 |
| -import org.eclipse.core.runtime.Status; |
20 | 18 | import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
21 | 19 | import org.eclipse.jface.dialogs.Dialog;
|
22 | 20 | import org.eclipse.jface.resource.JFaceResources;
|
|
38 | 36 | import org.eclipse.swt.widgets.Label;
|
39 | 37 | import org.eclipse.swt.widgets.Listener;
|
40 | 38 | import org.eclipse.swt.widgets.Text;
|
| 39 | +import org.eclipse.swt.widgets.Widget; |
41 | 40 | import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
|
42 | 41 | import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
43 | 42 |
|
@@ -98,6 +97,9 @@ public final void createControl(Composite parent) {
|
98 | 97 | // initialize page with default values
|
99 | 98 | initializeDefaultValues();
|
100 | 99 |
|
| 100 | + // Updates the state of the components |
| 101 | + updateComponents(null); |
| 102 | + |
101 | 103 | }
|
102 | 104 |
|
103 | 105 | /**
|
@@ -134,18 +136,12 @@ private void createNodejsBody(Composite parent) {
|
134 | 136 | createNodePathInfo(group);
|
135 | 137 | }
|
136 | 138 |
|
137 |
| - /** Creates the Filed for the embedded Node.js. */ |
| 139 | + /** Creates the field for the embedded Node.js. */ |
138 | 140 | private void createEmbeddedNodejsField(Composite parent, IEmbeddedNodejs[] installs) {
|
139 | 141 | useEmbeddedNodeJsButton = new Button(parent, SWT.RADIO);
|
140 | 142 | useEmbeddedNodeJsButton
|
141 | 143 | .setText(TypeScriptUIMessages.AbstractWizardNewTypeScriptProjectCreationPage_useEmbeddedNodeJs_label);
|
142 | 144 | useEmbeddedNodeJsButton.addListener(SWT.Selection, this);
|
143 |
| - useEmbeddedNodeJsButton.addSelectionListener(new SelectionAdapter() { |
144 |
| - @Override |
145 |
| - public void widgetSelected(SelectionEvent e) { |
146 |
| - updateNodeJsMode(); |
147 |
| - } |
148 |
| - }); |
149 | 145 |
|
150 | 146 | embeddedNodeJs = new Combo(parent, SWT.READ_ONLY);
|
151 | 147 | embeddedNodeJs.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
@@ -236,7 +232,7 @@ public void widgetSelected(SelectionEvent e) {
|
236 | 232 | });
|
237 | 233 | }
|
238 | 234 |
|
239 |
| - /** Creates the Info part, wehre Node.js path and version is shown. */ |
| 235 | + /** Creates the Info part, where Node.js path and version is shown. */ |
240 | 236 | private void createNodePathInfo(Composite parent) {
|
241 | 237 | Composite composite = new Composite(parent, SWT.NONE);
|
242 | 238 | composite.setLayout(new GridLayout());
|
@@ -283,39 +279,22 @@ protected void initializeDefaultValues() {
|
283 | 279 | installedNodeJs.select(0);
|
284 | 280 | }
|
285 | 281 | }
|
286 |
| - updateNodeJsMode(); |
287 |
| - } |
288 |
| - |
289 |
| - /** Updates the Node.js mode and enables/disables the widgets accordingly. */ |
290 |
| - private void updateNodeJsMode() { |
291 |
| - if (!hasEmbeddedNodeJs) { |
292 |
| - return; |
293 |
| - } |
294 |
| - useEmbeddedNodeJs = useEmbeddedNodeJsButton.getSelection(); |
295 |
| - embeddedNodeJs.setEnabled(useEmbeddedNodeJs); |
296 |
| - installedNodeJs.setEnabled(!useEmbeddedNodeJs); |
297 |
| - browseFileSystemButton.setEnabled(!useEmbeddedNodeJs); |
298 |
| - browseWorkspaceButton.setEnabled(!useEmbeddedNodeJs); |
299 | 282 | }
|
300 | 283 |
|
301 | 284 | @Override
|
302 | 285 | protected boolean validatePage() {
|
303 | 286 | boolean valid = super.validatePage();
|
304 | 287 | if (valid) {
|
305 |
| - ArrayList<IStatus> status = validatePageImpl(); |
306 |
| - IStatus currStatus; |
307 |
| - if (status == null || (currStatus = StatusUtil.getMostSevere(status.toArray(new IStatus[] {}))) == null) |
308 |
| - currStatus = Status.OK_STATUS; |
309 |
| - statusChanged(currStatus); |
310 |
| - valid = !currStatus.matches(IStatus.ERROR); |
| 288 | + IStatus status = validatePageImpl(); |
| 289 | + statusChanged(status); |
| 290 | + valid = !status.matches(IStatus.ERROR); |
311 | 291 | }
|
312 | 292 | return valid;
|
313 | 293 | }
|
314 | 294 |
|
315 |
| - protected ArrayList<IStatus> validatePageImpl() { |
316 |
| - ArrayList<IStatus> status = new ArrayList<>(); |
317 |
| - status.add(validateAndUpdateNodejsPath()); |
318 |
| - return status; |
| 295 | + /** Validates the Page and returns the most severe status. */ |
| 296 | + protected IStatus validatePageImpl() { |
| 297 | + return validateAndUpdateNodejsPath(); |
319 | 298 | }
|
320 | 299 |
|
321 | 300 | /**
|
@@ -397,17 +376,36 @@ public void updateNodeJSPreferences(IEclipsePreferences preferences) {
|
397 | 376 | }
|
398 | 377 |
|
399 | 378 | @Override
|
400 |
| - public void statusChanged(IStatus status) { |
401 |
| - if (isPageComplete()) |
402 |
| - setPageComplete(!status.matches(IStatus.ERROR)); |
| 379 | + public final void statusChanged(IStatus status) { |
403 | 380 | StatusUtil.applyToStatusLine(this, status);
|
404 | 381 | }
|
405 | 382 |
|
406 | 383 | @Override
|
407 | 384 | public void handleEvent(Event event) {
|
408 |
| - validatePage(); |
| 385 | + setPageComplete(validatePage()); |
| 386 | + updateComponents(event); |
| 387 | + } |
| 388 | + |
| 389 | + /** Updates the state of the components. */ |
| 390 | + protected void updateComponents(Event event) { |
| 391 | + Widget item = event != null ? event.item : null; |
| 392 | + if (item == null || item == useEmbeddedNodeJsButton) |
| 393 | + updateNodeJsMode(); |
| 394 | + } |
| 395 | + |
| 396 | + /** Updates the Node.js mode and enables/disables the widgets accordingly. */ |
| 397 | + private void updateNodeJsMode() { |
| 398 | + if (!hasEmbeddedNodeJs) { |
| 399 | + return; |
| 400 | + } |
| 401 | + useEmbeddedNodeJs = useEmbeddedNodeJsButton.getSelection(); |
| 402 | + embeddedNodeJs.setEnabled(useEmbeddedNodeJs); |
| 403 | + installedNodeJs.setEnabled(!useEmbeddedNodeJs); |
| 404 | + browseFileSystemButton.setEnabled(!useEmbeddedNodeJs); |
| 405 | + browseWorkspaceButton.setEnabled(!useEmbeddedNodeJs); |
409 | 406 | }
|
410 | 407 |
|
| 408 | + /** Updates the Commands, which should be executed after creating the Project. */ |
411 | 409 | public void updateCommand(List<LineCommand> commands, final IEclipsePreferences preferences) {
|
412 | 410 | }
|
413 | 411 |
|
|
0 commit comments