1515
1616import org .eclipse .core .resources .IProject ;
1717import org .eclipse .core .resources .ProjectScope ;
18+ import org .eclipse .core .runtime .CoreException ;
1819import org .eclipse .core .runtime .IStatus ;
1920import org .eclipse .core .runtime .Status ;
2021import org .eclipse .core .runtime .jobs .IJobChangeEvent ;
4243import ts .eclipse .ide .angular .cli .utils .CLIStatus ;
4344import ts .eclipse .ide .angular .cli .utils .NgVersionJob ;
4445import ts .eclipse .ide .angular .internal .cli .AngularCLIMessages ;
46+ import ts .eclipse .ide .angular .internal .cli .AngularCLIProject ;
47+ import ts .eclipse .ide .angular .internal .cli .AngularCLIProjectSettings ;
48+ import ts .eclipse .ide .angular .internal .cli .Trace ;
4549import ts .eclipse .ide .core .utils .WorkbenchResourceUtil ;
4650import ts .eclipse .ide .terminal .interpreter .EnvPath ;
4751import ts .eclipse .ide .terminal .interpreter .LineCommand ;
@@ -63,12 +67,12 @@ public class WizardNewNgProjectCreationPage extends AbstractWizardNewTypeScriptP
6367 "app" };
6468
6569 // Angular CLI
66- private Boolean hasGlobalAngularCLI ;
67- private Button useGlobalAngularCLIButton ;
70+ private Boolean hasGlobalPreferencesCLI ;
71+ private Button useGlobalCLIPreferencesButton ;
6872 private Button useInstallAngularCLIButton ;
6973 private Text globalAngularCLIVersion ;
7074 private NpmInstallWidget installAngularCLI ;
71- private boolean useGlobalAngularCLI ;
75+ private boolean useGlobalCLIPreferences ;
7276
7377 private NgVersionJob ngVersionJob ;
7478
@@ -98,10 +102,10 @@ protected void createPageBody(Composite parent) {
98102
99103 /** Creates the field for install Angular CLI. */
100104 private void createGlobalAngularCLIField (Composite parent ) {
101- useGlobalAngularCLIButton = new Button (parent , SWT .RADIO );
102- useGlobalAngularCLIButton .setText (AngularCLIMessages .WizardNewNgProjectCreationPage_useGlobalAngularCLI );
103- useGlobalAngularCLIButton .addListener (SWT .Selection , this );
104- useGlobalAngularCLIButton .addSelectionListener (new SelectionAdapter () {
105+ useGlobalCLIPreferencesButton = new Button (parent , SWT .RADIO );
106+ useGlobalCLIPreferencesButton .setText (AngularCLIMessages .WizardNewNgProjectCreationPage_useGlobalPreferencesCLI );
107+ useGlobalCLIPreferencesButton .addListener (SWT .Selection , this );
108+ useGlobalCLIPreferencesButton .addSelectionListener (new SelectionAdapter () {
105109 @ Override
106110 public void widgetSelected (SelectionEvent e ) {
107111 updateAngularCLIMode ();
@@ -134,56 +138,72 @@ public void statusChanged(IStatus status) {
134138 @ Override
135139 protected void initializeDefaultValues () {
136140 super .initializeDefaultValues ();
137- useGlobalAngularCLIButton .setSelection (true );
141+ useGlobalCLIPreferencesButton .setSelection (true );
138142 }
139143
140144 @ Override
141145 protected void nodeJsChanged (File nodeFile ) {
142146 super .nodeJsChanged (nodeFile );
143- if (hasGlobalAngularCLI == null && nodeFile != null && ngVersionJob == null ) {
144- ngVersionJob = new NgVersionJob ();
145- ngVersionJob .setNodeFile (nodeFile );
146- ngVersionJob .setNgFile (CLIProcessHelper .findNg ());
147- ngVersionJob .addJobChangeListener (new JobChangeAdapter () {
148- @ Override
149- public void done (IJobChangeEvent event ) {
150- super .done (event );
151- IStatus status = event .getResult ();
152- final String version ;
153- if (status instanceof CLIStatus ) {
154- final CLIStatus s = (CLIStatus ) status ;
155- version = s .getVersion ();
156- if (s .isOK ())
157- hasGlobalAngularCLI = Boolean .TRUE ;
158- } else {
159- hasGlobalAngularCLI = Boolean .FALSE ;
160- version = "" ;
161- }
162- Display .getDefault ().asyncExec (new Runnable () {
163- @ Override
164- public void run () {
165- if (!globalAngularCLIVersion .isDisposed ())
166- globalAngularCLIVersion .setText (version );
167- validatePage ();
147+ if (hasGlobalPreferencesCLI == null && nodeFile != null && ngVersionJob == null ) {
148+ File ngFile = null ;
149+ try {
150+ AngularCLIProjectSettings settings = AngularCLIProject .getAngularCLIProject (getProjectHandle ()).getSettings ();
151+ ngFile = settings .getNgFile ();
152+ if (ngFile != null && ngFile .isDirectory ())
153+ ngFile = new File (ngFile , CLIProcessHelper .getNgFileName ());
154+ else
155+ ngFile = null ;
156+ } catch (CoreException e ) {
157+ Trace .trace (Trace .SEVERE , "Error while getting Project settings" , e );
158+ ngFile = null ;
159+ }
160+ if (ngFile == null || !ngFile .exists ())
161+ hasGlobalPreferencesCLI = Boolean .FALSE ;
162+ else {
163+ ngVersionJob = new NgVersionJob ();
164+ ngVersionJob .setNodeFile (nodeFile );
165+ ngVersionJob .setNgFile (ngFile );
166+ ngVersionJob .addJobChangeListener (new JobChangeAdapter () {
167+ @ Override
168+ public void done (IJobChangeEvent event ) {
169+ super .done (event );
170+ IStatus status = event .getResult ();
171+ final String version ;
172+ if (status instanceof CLIStatus ) {
173+ final CLIStatus s = (CLIStatus ) status ;
174+ version = s .getVersion ();
175+ if (s .isOK ())
176+ hasGlobalPreferencesCLI = Boolean .TRUE ;
177+ } else {
178+ hasGlobalPreferencesCLI = Boolean .FALSE ;
179+ version = "" ;
168180 }
169- });
170- }
171- });
172- ngVersionJob .schedule ();
181+ Display .getDefault ().asyncExec (new Runnable () {
182+ @ Override
183+ public void run () {
184+ if (!globalAngularCLIVersion .isDisposed ())
185+ globalAngularCLIVersion .setText (version );
186+ validatePage ();
187+ }
188+ });
189+ }
190+ });
191+ ngVersionJob .schedule ();
192+ }
173193 }
174194 }
175195
176196 @ Override
177197 protected void updateComponents (Event event ) {
178198 super .updateComponents (event );
179199 Widget item = event != null ? event .item : null ;
180- if (item == null || item == useGlobalAngularCLIButton )
200+ if (item == null || item == useGlobalCLIPreferencesButton )
181201 updateAngularCLIMode ();
182202 }
183203
184204 private void updateAngularCLIMode () {
185- useGlobalAngularCLI = useGlobalAngularCLIButton .getSelection ();
186- installAngularCLI .setEnabled (!useGlobalAngularCLI );
205+ useGlobalCLIPreferences = useGlobalCLIPreferencesButton .getSelection ();
206+ installAngularCLI .setEnabled (!useGlobalCLIPreferences );
187207 }
188208
189209 @ Override
@@ -217,13 +237,13 @@ private IStatus validateNgProjectName(String name) {
217237
218238 /** Validates the Angular CLI. */
219239 private IStatus validateAngularCLI () {
220- if (useGlobalAngularCLI ) {
221- if (hasGlobalAngularCLI == null )
240+ if (useGlobalCLIPreferences ) {
241+ if (hasGlobalPreferencesCLI == null )
222242 return new Status (IStatus .ERROR , AngularCLIPlugin .PLUGIN_ID ,
223- AngularCLIMessages .WizardNewNgProjectCreationPage_searchingForGlobalAngularCLI );
224- else if (!hasGlobalAngularCLI .booleanValue ())
243+ AngularCLIMessages .WizardNewNgProjectCreationPage_searchingForGlobalPreferencesCLI );
244+ else if (!hasGlobalPreferencesCLI .booleanValue ())
225245 return new Status (IStatus .ERROR , AngularCLIPlugin .PLUGIN_ID ,
226- AngularCLIMessages .WizardNewNgProjectCreationPage_noGlobalAngularCLI );
246+ AngularCLIMessages .WizardNewNgProjectCreationPage_noGlobalPreferencesCLI );
227247 else
228248 return Status .OK_STATUS ;
229249 }
@@ -232,7 +252,7 @@ else if (!hasGlobalAngularCLI.booleanValue())
232252
233253 @ Override
234254 public void updateCommand (List <LineCommand > commands , final IProject project , String nodeFilePath ) {
235- if (!useGlobalAngularCLI ) {
255+ if (!useGlobalCLIPreferences ) {
236256 // when Angular CLI is installed, update the project Eclipse preferences
237257 // to consume this installed Angular CLI.
238258 commands .add (new LineCommand (installAngularCLI .getNpmInstallCommand (), new TerminalCommandAdapter () {
@@ -257,7 +277,7 @@ public void run() {
257277 }
258278 }));
259279 commands .add (EnvPath .createSetPathCommand (EnvPath .insertToEnvPath (nodeFilePath , FileUtils
260- .getPath (WorkbenchResourceUtil .resolvePath ("${project_loc:node_modules/.bin}" , project )))));
280+ .getPath (WorkbenchResourceUtil .resolvePath ("${project_loc:node_modules/.bin}" , project )))));
261281 }
262282 }
263283
0 commit comments