001: package com.salmonllc.ideTools.eclipse;
002:
003: import java.io.File;
004: import java.io.FileOutputStream;
005: import java.io.PrintWriter;
006:
007: import org.eclipse.core.resources.IFolder;
008: import org.eclipse.core.resources.IProject;
009: import org.eclipse.core.resources.IResource;
010: import org.eclipse.core.resources.IWorkspaceRoot;
011: import org.eclipse.core.runtime.CoreException;
012: import org.eclipse.core.runtime.IExecutableExtension;
013: import org.eclipse.core.runtime.IProgressMonitor;
014: import org.eclipse.jdt.core.IJavaProject;
015: import org.eclipse.jdt.internal.ui.JavaPlugin;
016: import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPage;
017: import org.eclipse.jface.operation.IRunnableWithProgress;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.widgets.MessageBox;
020: import org.eclipse.swt.widgets.Shell;
021: import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
022: import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
023:
024: import com.salmonllc.ideTools.IDETool;
025: import com.salmonllc.properties.Props;
026:
027: /**
028: * @author Administrator
029: *
030: * To change this generated comment edit the template variable "typecomment":
031: * Window>Preferences>Java>Templates.
032: * To enable and disable the creation of type comments go to
033: * Window>Preferences>Java>Code Generation.
034: */
035: public class SalmonProjectCreationWizard extends
036: SalmonProjectCreationWizardBase implements IExecutableExtension {
037:
038: private WizardNewProjectCreationPage _mainPage;
039: private SalmonProjectCreationWizardPage _sofiaPage;
040: private NewJavaProjectWizardPage _javaPage;
041:
042: /**
043: * Constructor for SalmonProjectCreationWizard.
044: */
045: public SalmonProjectCreationWizard() {
046: super ();
047: }
048:
049: /**
050: * @see org.eclipse.jface.wizard.IWizard#performFinish()
051: */
052: public boolean performFinish() {
053: IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(
054: _javaPage.getRunnable());
055: try {
056: getContainer().run(false, true, op);
057: IJavaProject javaProj = _javaPage.getNewJavaProject();
058: IProject proj = javaProj.getProject();
059: Props pr = SalmonPlugin.getSystemProps();
060: boolean propsInWebApp = pr.getBooleanProperty(
061: Props.IDE_USE_APP_PROPERTIES, false);
062: //First clear out the old source entries. There is a blank one that causes a lot of trouble
063: clearSourceEntries(javaProj);
064:
065: //Create a JSP folder for the JSP
066: IFolder jspFolder = createFolder(proj, "Jsp");
067:
068: //Create a WEB-INF folder
069: IFolder webInf = createFolder(proj, "WEB-INF");
070: IFolder propsFolder = null;
071: createFolder(webInf, "XML");
072: if (propsInWebApp)
073: propsFolder = createFolder(webInf, "properties");
074:
075: //Create a bin folder for the output
076: IFolder binFolder = createFolder(proj, "bin");
077: javaProj.setOutputLocation(binFolder.getFullPath(), null);
078:
079: //Create a Java folder for the Java source
080: IFolder javaFolder = createFolder(proj, "Java");
081: addSourceEntry(javaProj, javaFolder);
082:
083: //Add the Salmon Project Nature to the project and add the Salmon project to the classpath
084: addNatureEntry(proj);
085: addReferencedProjectToClasspath(proj, javaProj);
086:
087: //Add the proper jars for the server type to the classpath
088: addServerJarsToClassPath(javaProj, pr);
089:
090: //Copy the WEB-INF files from the resources directory
091: copyWEBINFFiles(webInf, pr);
092:
093: //Copy Hello.jsp
094: copyHelloJSP(jspFolder, pr);
095:
096: //Add stuff to the salmon System.properties file for this project
097: updateSystemProps(proj, binFolder, javaFolder, jspFolder,
098: propsFolder, _sofiaPage.getJDBCJar(), pr,
099: "hello.jsp");
100:
101: //Create the property file for the project
102: String projectPropertyPath = SalmonPlugin
103: .getSalmonPropsPath();
104: String projectPropsName = proj.getDescription().getName();
105: boolean full = false;
106: if (propsInWebApp) {
107: projectPropertyPath = propsFolder.getLocation()
108: .toOSString();
109: projectPropsName = "System";
110: full = true;
111: }
112: createProjectPropertyFile(proj, webInf, _sofiaPage,
113: projectPropertyPath, projectPropsName, full, pr);
114:
115: //Create a dreamweaver project
116: if (_sofiaPage.getMakeDefault())
117: createDreamweaverProject(proj, pr);
118:
119: //Make this the default project
120: SalmonPlugin.getDefault().getPreferenceStore().setValue(
121: SalmonPlugin.PREF_DEFAULT_PROJECT,
122: proj.getDescription().getName());
123:
124: //Refresh the project to get all the copied files
125: proj.refreshLocal(IResource.DEPTH_INFINITE, null);
126:
127: //Set up the configuration file for Weblogic or tomcat
128: String type = SalmonPlugin.getServerType();
129: if (type != null) {
130: if (type == IDETool.SERVER_TOMCAT40
131: || type == IDETool.SERVER_TOMCAT41)
132: setupTomcatConfigFile(pr
133: .getProperty(Props.IDE_SERVER_CONFIG_FILE),
134: proj);
135: else if (type.equals(IDETool.SERVER_WEBLOGIC6))
136: setupWeblogicConfigFile(pr
137: .getProperty(Props.IDE_SERVER_CONFIG_FILE),
138: proj);
139: }
140:
141: //update the perspective
142: updatePerspective();
143:
144: } catch (Exception e) {
145: MessageBox box = new MessageBox(new Shell(), SWT.ICON_ERROR
146: | SWT.OK | SWT.SYSTEM_MODAL);
147: box.setText("Error Creating Project.");
148: box.setMessage(e.getMessage());
149: box.open();
150: e.printStackTrace();
151: }
152:
153: return true;
154: }
155:
156: public void addPages() {
157: if (isInError())
158: return;
159:
160: super .addPages();
161:
162: _mainPage = new WizardNewProjectCreationPage("Page 1");
163: _mainPage.setTitle("New SOFIA Project");
164: _mainPage
165: .setDescription("Create a new project using the Salmon Open Framework");
166: addPage(_mainPage);
167:
168: _sofiaPage = new SalmonProjectCreationWizardPage(this , "Page 2");
169: _sofiaPage.setTitle("SOFIA project Options");
170: _sofiaPage
171: .setDescription("SOFIA JDBC and Dreamweaver Settings");
172: addPage(_sofiaPage);
173:
174: IWorkspaceRoot root = JavaPlugin.getWorkspace().getRoot();
175: _javaPage = new NewJavaProjectWizardPage(root, _mainPage);
176: }
177:
178: public void createProjectPropertyFile(IProject project,
179: IFolder webFolder, SalmonProjectCreationWizardPage page,
180: String propsPath, String propsName, boolean full, Props pr) {
181: try {
182: String resourcePath = pr
183: .getProperty(Props.IDE_FRAMEWORK_RESOURCES_PATH);
184: File f = new File(resourcePath
185: + File.separator
186: + "salmonprops"
187: + File.separator
188: + (full ? "eclipseFull.properties"
189: : "eclipse.properties"));
190: String text = IDETool.readFile(f);
191:
192: text = replace(text, "$PROJECTNAME$", project
193: .getDescription().getName());
194: text = replace(text, "$DRIVER$", page.getDriver());
195: text = replace(text, "$DBUSER$", page.getDBUser());
196: text = replace(text, "$DBPASSWORD$", page.getDBPassword());
197: text = replace(text, "$CONNECTURL$", page.getDBURL());
198: text = replace(text, "$WEBINF$", doubleSlash(webFolder
199: .getLocation().toOSString()));
200:
201: f = new File(propsPath + File.separatorChar + propsName
202: + ".properties");
203: PrintWriter pw = new PrintWriter(new FileOutputStream(f));
204: pw.print(text);
205: pw.close();
206: } catch (Exception e) {
207: e.printStackTrace();
208: }
209:
210: }
211:
212: /* (non-Javadoc)
213: * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
214: */
215: protected void finishPage(IProgressMonitor monitor)
216: throws InterruptedException, CoreException {
217:
218: }
219:
220: }
|