Skip to content

Commit 446ef9e

Browse files
committed
preference to add JSDT nature (default false)
1 parent a87a1b4 commit 446ef9e

6 files changed

Lines changed: 47 additions & 21 deletions

File tree

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class NodePreferencePage extends FieldEditorPreferencePage implements IWo
4545
private StringFieldEditor nodeApplicationArguments;
4646
private BooleanFieldEditor nodeAllowMany;
4747
private BooleanFieldEditor nodePassAllEnvVars;
48+
private BooleanFieldEditor addJsdtNature;
4849
private BooleanFieldEditor addTernNature;
4950
private DirectoryFieldEditor nodeSourcesPath;
5051
private BooleanFieldEditor useNodejsBaseModuleDefinitions;
@@ -149,6 +150,9 @@ protected void createFieldEditors() {
149150
"pass all environment variables of Eclipse to launched Node.js app", getFieldEditorParent());
150151
addField(nodePassAllEnvVars);
151152

153+
addJsdtNature = new BooleanFieldEditor(PreferenceConstants.ADD_JSDT_NATURE,
154+
"add JSDT nature to newly created projects", getFieldEditorParent());
155+
addField(addJsdtNature);
152156
addTernNature = new BooleanFieldEditor(PreferenceConstants.ADD_TERN_NATURE,
153157
"add Tern nature to newly created projects", getFieldEditorParent());
154158
addField(addTernNature);

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.nodeclipse.ui.preferences;
22

3+
import org.eclipse.wst.jsdt.core.JavaScriptCore;
4+
35
/**
46
* Constant definitions for plug-in preferences
57
*
@@ -15,6 +17,8 @@ public class PreferenceConstants {
1517
public static final String NODE_APPLICATION_ARGUMENTS = "node_application_arguments";
1618
public static final String NODE_ALLOW_MANY = "node_allow_many";
1719
public static final String NODE_PASS_ALL_ENVIRONMENT_VARIABLES = "node_pass_all_environment_variables";
20+
public static final String ADD_JSDT_NATURE = "add_jsdt_nature";
21+
//public static final String ADD_JSDT_NATURE_VALUE = JavaScriptCore.NATURE_ID; //"org.eclipse.wst.jsdt.core.jsNature";
1822
public static final String ADD_TERN_NATURE = "add_tern_nature";
1923
public static final String ADD_TERN_NATURE_VALUE = "tern.eclipse.ide.core.ternnature";
2024
public static final String NODE_SOURCES_PATH = "node_sources_lib_path";

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void initializeDefaultPreferences() {
3434

3535
store.setDefault(PreferenceConstants.NODE_ALLOW_MANY, true);
3636

37+
store.setDefault(PreferenceConstants.ADD_JSDT_NATURE, false);
3738
store.setDefault(PreferenceConstants.ADD_TERN_NATURE, true);
3839

3940
store.setDefault(PreferenceConstants.USE_NODEJS_BASE_MODULE_DEFINITIONS, true);

org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/AbstractNodeProjectWizard.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import java.io.InputStreamReader;
88
import java.net.URI;
99
import java.net.URL;
10+
import java.text.DateFormat;
11+
import java.text.SimpleDateFormat;
12+
import java.util.Date;
1013

1114
import org.eclipse.core.internal.resources.Workspace;
1215
import org.eclipse.core.internal.utils.FileUtil;
@@ -41,6 +44,7 @@
4144
import org.nodeclipse.ui.perspectives.NodePerspective;
4245
import org.nodeclipse.ui.preferences.PreferenceConstants;
4346
import org.nodeclipse.ui.util.LogUtil;
47+
import org.nodeclipse.ui.util.VersionUtil;
4448
import org.osgi.framework.Bundle;
4549

4650
/**
@@ -92,36 +96,49 @@ public boolean performFinish() {
9296

9397
//+ to let overriding
9498
protected String getProjectNature(){
95-
return NodeNature.NATURE_ID;
99+
return NodeNature.NATURE_ID;
96100
}
97101

98102
/**
99-
* Set project natures to current type + JavaScriptCore nature
103+
* Set project natures to current type + optionally JSDT/Tern nature
100104
* @param newProjectHandle IProject
101105
* @param location URI
102106
* @return
103107
*/
104108
protected IProjectDescription createProjectDescription(IProject newProjectHandle, URI location) {
105-
IWorkspace workspace = ResourcesPlugin.getWorkspace();
106-
final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
107-
description.setLocationURI(location);
108-
String[] natures = description.getNatureIds();
109-
int numberOfAddedNatures = 2;
110-
boolean addTernNature = store.getBoolean(PreferenceConstants.ADD_TERN_NATURE);
109+
boolean addJsdtNature = store.getBoolean(PreferenceConstants.ADD_JSDT_NATURE);
110+
boolean addTernNature = store.getBoolean(PreferenceConstants.ADD_TERN_NATURE);
111+
int numberOfAddedNatures = 1; //always at least 1
112+
if (addJsdtNature){
113+
numberOfAddedNatures++;
114+
}
111115
if (addTernNature){
112116
numberOfAddedNatures++;
113117
}
118+
119+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
120+
final IProjectDescription pd = workspace.newProjectDescription(newProjectHandle.getName());
121+
pd.setLocationURI(location);
122+
String[] natures = pd.getNatureIds();
114123
String[] newNatures = new String[natures.length + numberOfAddedNatures];
115124
System.arraycopy(natures, 0, newNatures, 0, natures.length);
116-
newNatures[natures.length] = getProjectNature();
117-
newNatures[natures.length+1] = JavaScriptCore.NATURE_ID;
125+
126+
int newNaturesIndex = natures.length;
127+
newNatures[newNaturesIndex] = getProjectNature();
128+
if (addJsdtNature){
129+
newNatures[++newNaturesIndex] = JavaScriptCore.NATURE_ID;
130+
}
118131
if (addTernNature){
119-
newNatures[natures.length+2] = PreferenceConstants.ADD_TERN_NATURE_VALUE;
132+
newNatures[++newNaturesIndex] = PreferenceConstants.ADD_TERN_NATURE_VALUE;
120133
}
121-
description.setNatureIds(newNatures);
134+
pd.setNatureIds(newNatures);
122135

123-
return description;
136+
pd.setComment("Created with Nodeclipse "+VersionUtil.versionString+" at "+DATE_FORMAT.format(new Date()));
137+
return pd;
124138
}
139+
140+
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
141+
125142

126143
protected void generateTemplates(String path, IProject projectHandle) throws CoreException {
127144
Bundle bundle = Activator.getDefault().getBundle();

org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/ExpressProjectWizard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ protected IProject createNewProject() {
9595
newNatures[natures.length] = NodeNature.NATURE_ID;
9696
description.setNatureIds(newNatures);
9797
*/
98-
final IProjectDescription description = createProjectDescription(newProjectHandle, location);
99-
final boolean exists = isExistingProjectFolder(description);
98+
final IProjectDescription pd = createProjectDescription(newProjectHandle, location);
99+
final boolean exists = isExistingProjectFolder(pd);
100100
final String projectName = mainPage.getProjectName();
101101
final String templateEngine = mainPage.getSelectedTemplateEngine();
102102
final String stylesheetEngine = mainPage.getSelectedStylesheetEngine();
@@ -105,7 +105,7 @@ protected IProject createNewProject() {
105105
@Override
106106
public void run(IProgressMonitor monitor)
107107
throws InvocationTargetException, InterruptedException {
108-
createProject(description, monitor);
108+
createProject(pd, monitor);
109109
if(exists == true) {
110110
return;
111111
}

org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/NodeProjectWizard.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ protected IProject createNewProject() {
8383
newNatures[natures.length] = NodeNature.NATURE_ID;
8484
description.setNatureIds(newNatures);
8585
*/
86-
final IProjectDescription description = createProjectDescription(newProjectHandle, location);
87-
final boolean existingProjectFolder = isExistingProjectFolder(description);
86+
final IProjectDescription pd = createProjectDescription(newProjectHandle, location);
87+
final boolean existingProjectFolder = isExistingProjectFolder(pd);
8888
final String template = mainPage.getSelectedTemplate();
8989

90-
IRunnableWithProgress op = new IRunnableWithProgress() {
90+
IRunnableWithProgress runnable = new IRunnableWithProgress() {
9191
@Override
9292
public void run(IProgressMonitor monitor)
9393
throws InvocationTargetException, InterruptedException {
9494
CreateProjectOperation op = new CreateProjectOperation(
95-
description, WINDOW_TITLE);
95+
pd, WINDOW_TITLE);
9696
try {
9797
op.execute(monitor,
9898
WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
@@ -135,7 +135,7 @@ public void run(IProgressMonitor monitor)
135135
};
136136

137137
try {
138-
getContainer().run(true, true, op);
138+
getContainer().run(true, true, runnable);
139139
} catch (InvocationTargetException e) {
140140
LogUtil.error(e);
141141
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)