Skip to content

Commit abaa3c8

Browse files
authored
Merge pull request #179 from Springrbua/master
Change the AbstractWizardNewTypeScriptProjectCreationPage API
2 parents 0c55baf + aaa93b0 commit abaa3c8

File tree

3 files changed

+67
-62
lines changed

3 files changed

+67
-62
lines changed

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/widgets/NpmInstallWidget.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
/**
5151
* NPM install widget provides :
52-
*
52+
*
5353
* <ul>
5454
* <li>a text field to fill a NPM module version</li>
5555
* <li>a "Browse..." button to search available versions for the given node
@@ -226,7 +226,7 @@ private void addContentProposal(Text text) {
226226
/**
227227
* Validate the given version and update the status of the
228228
* {@link IStatusChangeListener}.
229-
*
229+
*
230230
* @param version
231231
*/
232232
private void validateVersion(String version) {
@@ -259,7 +259,7 @@ private void validateVersionSynch(NpmModule module) {
259259
}
260260

261261
private void validateVersionASynch(NpmModule module) {
262-
statusChanged(new StatusInfo(IStatus.WARNING,
262+
statusChanged(new StatusInfo(IStatus.ERROR,
263263
NLS.bind(TypeScriptUIMessages.NPMInstallWidget_SearchingVersions_status, module.getName())));
264264
if (validateVersionJob == null) {
265265
validateVersionJob = new ValidateVersionJob();
@@ -297,7 +297,7 @@ public void setEnabled(boolean enabled) {
297297

298298
/**
299299
* Returns the npm install command.
300-
*
300+
*
301301
* @return the npm install command.
302302
*/
303303
public String getNpmInstallCommand() {

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/wizards/AbstractWizardNewTypeScriptProjectCreationPage.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
package ts.eclipse.ide.ui.wizards;
1212

1313
import java.io.File;
14-
import java.util.ArrayList;
1514
import java.util.List;
1615

1716
import org.eclipse.core.resources.IResource;
1817
import org.eclipse.core.runtime.IStatus;
19-
import org.eclipse.core.runtime.Status;
2018
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2119
import org.eclipse.jface.dialogs.Dialog;
2220
import org.eclipse.jface.resource.JFaceResources;
@@ -38,6 +36,7 @@
3836
import org.eclipse.swt.widgets.Label;
3937
import org.eclipse.swt.widgets.Listener;
4038
import org.eclipse.swt.widgets.Text;
39+
import org.eclipse.swt.widgets.Widget;
4140
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
4241
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
4342

@@ -98,6 +97,9 @@ public final void createControl(Composite parent) {
9897
// initialize page with default values
9998
initializeDefaultValues();
10099

100+
// Updates the state of the components
101+
updateComponents(null);
102+
101103
}
102104

103105
/**
@@ -134,18 +136,12 @@ private void createNodejsBody(Composite parent) {
134136
createNodePathInfo(group);
135137
}
136138

137-
/** Creates the Filed for the embedded Node.js. */
139+
/** Creates the field for the embedded Node.js. */
138140
private void createEmbeddedNodejsField(Composite parent, IEmbeddedNodejs[] installs) {
139141
useEmbeddedNodeJsButton = new Button(parent, SWT.RADIO);
140142
useEmbeddedNodeJsButton
141143
.setText(TypeScriptUIMessages.AbstractWizardNewTypeScriptProjectCreationPage_useEmbeddedNodeJs_label);
142144
useEmbeddedNodeJsButton.addListener(SWT.Selection, this);
143-
useEmbeddedNodeJsButton.addSelectionListener(new SelectionAdapter() {
144-
@Override
145-
public void widgetSelected(SelectionEvent e) {
146-
updateNodeJsMode();
147-
}
148-
});
149145

150146
embeddedNodeJs = new Combo(parent, SWT.READ_ONLY);
151147
embeddedNodeJs.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -236,7 +232,7 @@ public void widgetSelected(SelectionEvent e) {
236232
});
237233
}
238234

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. */
240236
private void createNodePathInfo(Composite parent) {
241237
Composite composite = new Composite(parent, SWT.NONE);
242238
composite.setLayout(new GridLayout());
@@ -283,39 +279,22 @@ protected void initializeDefaultValues() {
283279
installedNodeJs.select(0);
284280
}
285281
}
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);
299282
}
300283

301284
@Override
302285
protected boolean validatePage() {
303286
boolean valid = super.validatePage();
304287
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);
311291
}
312292
return valid;
313293
}
314294

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();
319298
}
320299

321300
/**
@@ -397,17 +376,36 @@ public void updateNodeJSPreferences(IEclipsePreferences preferences) {
397376
}
398377

399378
@Override
400-
public void statusChanged(IStatus status) {
401-
if (isPageComplete())
402-
setPageComplete(!status.matches(IStatus.ERROR));
379+
public final void statusChanged(IStatus status) {
403380
StatusUtil.applyToStatusLine(this, status);
404381
}
405382

406383
@Override
407384
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);
409406
}
410407

408+
/** Updates the Commands, which should be executed after creating the Project. */
411409
public void updateCommand(List<LineCommand> commands, final IEclipsePreferences preferences) {
412410
}
413411

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/wizards/WizardNewTypeScriptProjectCreationPage.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ts.eclipse.ide.ui.wizards;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54

65
import org.eclipse.core.runtime.IStatus;
@@ -17,7 +16,9 @@
1716
import org.eclipse.swt.widgets.Combo;
1817
import org.eclipse.swt.widgets.Composite;
1918
import org.eclipse.swt.widgets.Display;
19+
import org.eclipse.swt.widgets.Event;
2020
import org.eclipse.swt.widgets.Group;
21+
import org.eclipse.swt.widgets.Widget;
2122
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
2223
import org.osgi.service.prefs.BackingStoreException;
2324

@@ -27,6 +28,7 @@
2728
import ts.eclipse.ide.internal.ui.wizards.TypeScriptRepositoryLabelProvider;
2829
import ts.eclipse.ide.terminal.interpreter.LineCommand;
2930
import ts.eclipse.ide.terminal.interpreter.TerminalCommandAdapter;
31+
import ts.eclipse.ide.ui.utils.StatusUtil;
3032
import ts.eclipse.ide.ui.widgets.NpmInstallWidget;
3133
import ts.repository.ITypeScriptRepository;
3234

@@ -103,6 +105,25 @@ public void widgetSelected(SelectionEvent e) {
103105
installTsRuntime.getVersionText().addListener(SWT.Modify, this);
104106
}
105107

108+
@Override
109+
protected void initializeDefaultValues() {
110+
super.initializeDefaultValues();
111+
112+
// Default values for TypeScript runtime
113+
if (hasEmbeddedTsRuntime) {
114+
embeddedTsRuntime.select(0);
115+
useEmbeddedTsRuntimeButton.setSelection(true);
116+
}
117+
}
118+
119+
@Override
120+
protected void updateComponents(Event event) {
121+
super.updateComponents(event);
122+
Widget item = event != null ? event.item : null;
123+
if (item == null || item == useEmbeddedTsRuntimeButton)
124+
updateTsRuntimeMode();
125+
}
126+
106127
private void updateTsRuntimeMode() {
107128
if (!hasEmbeddedTsRuntime) {
108129
return;
@@ -112,6 +133,12 @@ private void updateTsRuntimeMode() {
112133
installTsRuntime.setEnabled(!useEmbeddedTsRuntime);
113134
}
114135

136+
@Override
137+
protected IStatus validatePageImpl() {
138+
return StatusUtil.getMoreSevere(super.validatePageImpl(), validateTypeScriptRuntime());
139+
}
140+
141+
/** Validates the selected TypeScript Runtime. */
115142
private IStatus validateTypeScriptRuntime() {
116143
if (hasEmbeddedTsRuntime && useEmbeddedTsRuntimeButton.getSelection()) {
117144
return Status.OK_STATUS;
@@ -120,26 +147,6 @@ private IStatus validateTypeScriptRuntime() {
120147
}
121148

122149
@Override
123-
protected void initializeDefaultValues() {
124-
super.initializeDefaultValues();
125-
126-
// Default values for TypeScript runtime
127-
if (hasEmbeddedTsRuntime) {
128-
embeddedTsRuntime.select(0);
129-
useEmbeddedTsRuntimeButton.setSelection(true);
130-
}
131-
updateTsRuntimeMode();
132-
}
133-
134-
@Override
135-
protected ArrayList<IStatus> validatePageImpl() {
136-
ArrayList<IStatus> status = super.validatePageImpl();
137-
if (status == null)
138-
status = new ArrayList<>();
139-
status.add(validateTypeScriptRuntime());
140-
return status;
141-
}
142-
143150
public void updateCommand(List<LineCommand> commands, final IEclipsePreferences preferences) {
144151
if (!useEmbeddedTsRuntime) {
145152
// when TypeScript is installed when "npm install typescript"

0 commit comments

Comments
 (0)