001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.ideTools;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/ProjectDialog.java $
024: //$Author: Dan $
025: //$Revision: 33 $
026: //$Modtime: 9/24/04 3:51p $
027: /////////////////////////
028:
029: import java.awt.*;
030: import java.awt.event.*;
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.swing.*;
035:
036: import org.w3c.dom.*;
037:
038: import com.salmonllc.properties.Props;
039: import com.salmonllc.xml.DOMParser;
040:
041: public class ProjectDialog extends JDialog implements ActionListener,
042: WindowListener {
043:
044: boolean _cancelClicked = true;
045: JButton _create;
046: JButton _cancel;
047: JCheckBox _includeFrameworkSource;
048: JCheckBox _includeTomcatSource;
049: JCheckBox _setAsDefaultProject;
050: JCheckBox _specifyDBSettings;
051: JFrame _owner;
052: Props _props;
053: int _fieldIndex = 0;
054: int _noFields = 10;
055: Field _fields[];
056: Box _mainGrid;
057: String _currentSourceDir;
058: String _intelliJDir;
059: String _intelliJDirFwd;
060: String _tomcatDir;
061: String _tomcatFwdDir;
062: String _jdkdir;
063: String _jdkname;
064: String _projectname;
065: String _frameworkSourceDir;
066: String _frameworkResourcesDir;
067: String _dreamweaverDir;
068: File[] _jarFiles;
069: File[] _salmonTemplates;
070: File _resourcesDir;
071: String _runInBrowser;
072: Hashtable _dbsettings;
073: int _intelliJVersion = 2;
074:
075: private static String _tomcatsource2 = "<root file=\"file://$TOMCATFWD$/src/jasper/src/share\">\r\n <property name=\"type\" value=\"sourcePathEntry\" />\r\n</root>\r\n<root file=\"file://$TOMCATFWD$/src/catalina/src/share\">\r\n <property name=\"type\" value=\"sourcePathEntry\" />\r\n</root>";
076: private static String _frameworksource2 = "<root file=\"file://$FRAMEWORKSOURCEDIR$\">\r\n <property name=\"type\" value=\"projectFiles\" />\r\n</root>\r\n<root file=\"file://$FRAMEWORKSOURCEDIR$\">\r\n <property name=\"type\" value=\"sourcePathEntry\" />\r\n</root>";
077: private static String _browserconfiguration2 = "<configuration name=\"Run in $BROWSER$\" type=\"Application\" default=\"false\" selected=\"true\">\r\n <option name=\"MAIN_CLASS_NAME\" value=\"com.salmonllc.ideTools.IDETool\" />\r\n <option name=\"VM_PARAMETERS\" value=\"-Dcatalina.home="$TOMCAT$" -Djava.io.tmpdir="$TOMCAT$\\temp" -Dsalmon.props.path="$TOMCAT$\\salmonprops"\" />\r\n <option name=\"PROGRAM_PARAMETERS\" value=\"-RESTART -RUNBROWSER $BROWSER$ -PROJECT $PROJECT$\" />\r\n <option name=\"WORKING_DIRECTORY\" value=\"$PROJECT_DIR$\" />\r\n</configuration>\r\n";
078: private static String _jdbcjarclasspathentry2 = "<root file=\"jar://$JDBCJARFILE$!/\">\r\n <property name=\"type\" value=\"classPathEntry\" />\r\n</root>";
079: private static String _jdbcdirclasspathentry2 = "<root file=\"file://$JDBCJARFILE$/\">\r\n <property name=\"type\" value=\"classPathEntry\" />\r\n</root>";
080:
081: private static String _browserconfiguration34 = "<configuration name=\"Run in $BROWSER$\" type=\"Application\" default=\"false\" selected=\"true\">\r\n <option name=\"MAIN_CLASS_NAME\" value=\"com.salmonllc.ideTools.IDETool\" />\r\n <option name=\"VM_PARAMETERS\" value=\"-Dcatalina.home="$TOMCAT$" -Djava.io.tmpdir="$TOMCAT$\\temp" -Dsalmon.props.path="$TOMCAT$\\salmonprops"\" />\r\n <option name=\"PROGRAM_PARAMETERS\" value=\"-RESTART -RUNBROWSER $BROWSER$ -PROJECT $PROJECT$\" />\r\n <option name=\"WORKING_DIRECTORY\" value=\"$PROJECT_DIR$\" />\r\n</configuration>\r\n";
082: private static String _frameworksource3 = "<root type=\"simple\" url=\"file://$FRAMEWORKSOURCEDIR$\" />";
083: private static String _tomcatsource3 = "<root type=\"simple\" url=\"file://$TOMCATFWD$/src/jasper/src/share\" />\r\n<root type=\"simple\" url=\"file://$TOMCATFWD$/src/catalina/src/share\" />\r\n";
084: private static String _jdbcjarclasspathentry3 = "<root type=\"simple\" url=\"jar://$JDBCJARFILE$!/\" />\r\n";
085: private static String _jdbcdirclasspathentry3 = "<root type=\"simple\" url=\"file://$JDBCJARFILE$/\" />\r\n";
086:
087: private static String _frameworksource4 = " <content url=\"file://$FRAMEWORKSOURCEDIR$\">\n"
088: + " <sourceFolder url=\"file://$FRAMEWORKSOURCEDIR$\" isTestSource=\"false\" />\n"
089: + " </content>";
090: private static String _tomcatsource4 = "<content url=\"file://$TOMCATFWD$/src/jasper/src/share\" />\r\n<content url=\"file://$TOMCATFWD$/src/catalina/src/share\" />\r\n";
091: private static String _jdbcjarclasspathentry4 = "<root url=\"jar://$JDBCJARFILE$!/\" />\r\n";
092: private static String _jdbcdirclasspathentry4 = "<root url=\"file://$JDBCJARFILE$/\" />\r\n";
093:
094: private static String _tomcatsource = null;
095: private static String _frameworksource = null;
096: private static String _browserconfiguration = null;
097: private static String _jdbcjarclasspathentry = null;
098: private static String _jdbcdirclasspathentry = null;
099:
100: public static final int TYPE_TEXT = 0;
101: public static final int TYPE_PW = 1;
102: public static final int TYPE_FILE = 2;
103: public static final int TYPE_DIR = 3;
104: public static final int TYPE_DIR_FILE = 4;
105: public static final int TYPE_CHECKBOX = 5;
106: public static final int TYPE_CHECKBOXWITHACTION = 6;
107:
108: private class Field {
109: public JLabel caption;
110: public JComponent field;
111: public String property;
112: public JComponent lookup;
113: public int type;
114: }
115:
116: public ProjectDialog(JFrame owner, Props p) {
117: super (owner, "Create Project", true);
118: _owner = owner;
119: _props = p;
120:
121: _intelliJDir = p.getProperty(Props.IDE_INTELLIJ_PATH);
122: _intelliJDir.replace('/', File.separatorChar);
123: if (!_intelliJDir.endsWith(File.separator))
124: _intelliJDir = _intelliJDir + File.separator;
125: _intelliJDirFwd = _intelliJDir;
126: _intelliJDirFwd.replace(File.separatorChar, '/');
127: getJDKInformation();
128: if (_intelliJVersion == 2) {
129: _tomcatsource = _tomcatsource2;
130: _frameworksource = _frameworksource2;
131: _browserconfiguration = _browserconfiguration2;
132: _jdbcjarclasspathentry = _jdbcjarclasspathentry2;
133: _jdbcdirclasspathentry = _jdbcdirclasspathentry2;
134: } else if (_intelliJVersion == 3) {
135: _tomcatsource = _tomcatsource3;
136: _frameworksource = _frameworksource3;
137: _browserconfiguration = _browserconfiguration34;
138: _jdbcjarclasspathentry = _jdbcjarclasspathentry3;
139: _jdbcdirclasspathentry = _jdbcdirclasspathentry3;
140: } else if (_intelliJVersion == 4) {
141: _tomcatsource = _tomcatsource4;
142: _frameworksource = _frameworksource4;
143: _browserconfiguration = _browserconfiguration34;
144: _jdbcjarclasspathentry = _jdbcjarclasspathentry4;
145: _jdbcdirclasspathentry = _jdbcdirclasspathentry4;
146: }
147:
148: Vector browserProps = new Vector();
149: Enumeration en = p.getKeys();
150: while (en.hasMoreElements()) {
151: String key = (String) en.nextElement();
152: if (key.startsWith(Props.IDE_BROWSER_PATH + ".")) {
153: browserProps.add(key);
154: _noFields++;
155: }
156: }
157:
158: StringBuffer sbRunInBrowsers = new StringBuffer();
159: for (int i = 0; i < browserProps.size(); i++) {
160: String key = (String) browserProps.elementAt(i);
161: String browser = key.substring(Props.IDE_BROWSER_PATH
162: .length() + 1);
163: StringBuffer sbBrowser = new StringBuffer(
164: _browserconfiguration);
165: while (true) {
166: int iBrowserIndex = sbBrowser.toString().indexOf(
167: "$BROWSER$");
168: if (iBrowserIndex < 0)
169: break;
170: sbBrowser.replace(iBrowserIndex, iBrowserIndex + 9,
171: browser);
172: }
173: sbRunInBrowsers.append(sbBrowser);
174: }
175: _runInBrowser = sbRunInBrowsers.toString();
176:
177: _tomcatDir = p.getProperty(Props.IDE_TOMCAT_PATH);
178: _tomcatDir = _tomcatDir.replace('/', File.separatorChar);
179: if (_tomcatDir.endsWith(File.separator)) {
180: _tomcatDir = _tomcatDir.substring(0,
181: _tomcatDir.length() - 1);
182: }
183: _tomcatFwdDir = _tomcatDir.replace(File.separatorChar, '/');
184: _frameworkSourceDir = p
185: .getProperty(Props.IDE_FRAMEWORK_SOURCE_PATH);
186: _frameworkSourceDir = _frameworkSourceDir.replace('/',
187: File.separatorChar);
188: if (_frameworkSourceDir.endsWith(File.separator)) {
189: _frameworkSourceDir = _frameworkSourceDir.substring(0,
190: _frameworkSourceDir.length() - 1);
191: }
192: _frameworkSourceDir = _frameworkSourceDir.replace(
193: File.separatorChar, '/');
194: _frameworkResourcesDir = p
195: .getProperty(Props.IDE_FRAMEWORK_RESOURCES_PATH);
196: _resourcesDir = new File(_frameworkResourcesDir);
197: if (!_resourcesDir.exists()) {
198: displayError("Framework has not been properly installed. Missing Resources Directory "
199: + _resourcesDir.getAbsolutePath() + ".");
200: return;
201: }
202:
203: if (_intelliJVersion == 2) {
204: _salmonTemplates = new File[1];
205: _salmonTemplates[0] = new File(_resourcesDir
206: + File.separator + "IntelliJ" + File.separator
207: + "salmon.ipr");
208: if (!_salmonTemplates[0].exists()) {
209: displayError("Framework has not been properly installed. Missing Salmon Template "
210: + _salmonTemplates[0].getAbsolutePath() + ".");
211: return;
212: }
213: } else if (_intelliJVersion == 3) {
214: _salmonTemplates = new File[2];
215: _salmonTemplates[0] = new File(_resourcesDir
216: + File.separator + "IntelliJ" + File.separator
217: + "salmon3.ipr");
218: _salmonTemplates[1] = new File(_resourcesDir
219: + File.separator + "IntelliJ" + File.separator
220: + "salmon3.iws");
221: if (!_salmonTemplates[0].exists()) {
222: displayError("Framework has not been properly installed. Missing Salmon Template "
223: + _salmonTemplates[0].getAbsolutePath() + ".");
224: return;
225: }
226: if (!_salmonTemplates[1].exists()) {
227: displayError("Framework has not been properly installed. Missing Salmon Template "
228: + _salmonTemplates[1].getAbsolutePath() + ".");
229: return;
230: }
231:
232: } else if (_intelliJVersion == 4) {
233: _salmonTemplates = new File[3];
234: _salmonTemplates[0] = new File(_resourcesDir
235: + File.separator + "IntelliJ" + File.separator
236: + "salmon4.ipr");
237: _salmonTemplates[1] = new File(_resourcesDir
238: + File.separator + "IntelliJ" + File.separator
239: + "salmon4.iws");
240: _salmonTemplates[2] = new File(_resourcesDir
241: + File.separator + "IntelliJ" + File.separator
242: + "salmon4.iml");
243:
244: if (!_salmonTemplates[0].exists()) {
245: displayError("Framework has not been properly installed. Missing Salmon Template "
246: + _salmonTemplates[0].getAbsolutePath() + ".");
247: return;
248: }
249: if (!_salmonTemplates[1].exists()) {
250: displayError("Framework has not been properly installed. Missing Salmon Template "
251: + _salmonTemplates[1].getAbsolutePath() + ".");
252: return;
253: }
254: if (!_salmonTemplates[2].exists()) {
255: displayError("Framework has not been properly installed. Missing Salmon Template "
256: + _salmonTemplates[2].getAbsolutePath() + ".");
257: return;
258: }
259: }
260:
261: _dreamweaverDir = p.getProperty(Props.IDE_DREAMWEAVER_PATH);
262: _dreamweaverDir.replace('/', File.separatorChar);
263: int iSlashIndex = _dreamweaverDir.lastIndexOf(File.separator);
264: _dreamweaverDir = _dreamweaverDir.substring(0, iSlashIndex);
265:
266: int width = 600;
267: int height = 150 + (30 * 3);
268: Dimension frameBounds = Toolkit.getDefaultToolkit()
269: .getScreenSize();
270: int x = (frameBounds.width - width) / 2;
271: int y = (frameBounds.height - height) / 2;
272: setBounds(x, y, width, height);
273:
274: _fields = new Field[_noFields];
275: _mainGrid = Box.createVerticalBox();
276:
277: addFieldToGrid("ProjectName", "Project Name", TYPE_TEXT);
278: addFieldToGrid(Props.IDE_DEFAULT_SOURCE_PATH,
279: "Source Code Path", TYPE_DIR);
280: _includeFrameworkSource = (JCheckBox) addFieldToGrid(
281: "IncludeFrameworkSource", "Include Framework Source",
282: TYPE_CHECKBOX);
283: // _mainGrid.add("IncludeFrameworkSource",_includeFrameworkSource=new JCheckBox("Include Framework Source",false));
284: _includeTomcatSource = (JCheckBox) addFieldToGrid(
285: "IncludeTomcatSource", "Include Tomcat Source",
286: TYPE_CHECKBOX);
287: // _mainGrid.add("IncludeTomcatSource",_includeTomcatSource=new JCheckBox("Include Tomcat Source",false));
288: _setAsDefaultProject = (JCheckBox) addFieldToGrid(
289: "SetAsDefaultProject", "Set As Default Project",
290: TYPE_CHECKBOX);
291: _specifyDBSettings = (JCheckBox) addFieldToGrid(
292: "SpecifyDBSettings", "Specify Database Settings",
293: TYPE_CHECKBOXWITHACTION);
294: _specifyDBSettings.addActionListener(this );
295: _create = new JButton("Create");
296: _create.addActionListener(this );
297: _cancel = new JButton("Cancel");
298: _cancel.addActionListener(this );
299: JPanel buttonBar = new JPanel(new FlowLayout());
300: buttonBar.add(_create);
301: buttonBar.add(_cancel);
302: buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT);
303: Box box = Box.createVerticalBox();
304:
305: box.add(Box.createRigidArea(new Dimension(100, 10)));
306: box.add(_mainGrid);
307: box.add(Box.createRigidArea(new Dimension(100, 5)));
308: box.add(buttonBar);
309:
310: getContentPane().add(box);
311:
312: addWindowListener(this );
313: setVisible(true);
314: }
315:
316: public void actionPerformed(ActionEvent e) {
317: if (e.getSource() == _cancel) {
318: _cancelClicked = true;
319: setVisible(false);
320: } else if (e.getSource() == _create) {
321: boolean propsInApp = Props.getSystemProps()
322: .getBooleanProperty(Props.IDE_USE_APP_PROPERTIES,
323: false);
324: Field fProjectName = _fields[0];
325: _projectname = ((JTextField) fProjectName.field).getText();
326: if (_projectname == null || _projectname.trim().equals("")) {
327: displayError("Project Name must have a value.");
328: return;
329: } else {
330: File fProject = new File(_intelliJDir + _projectname
331: + ".ipr");
332: if (fProject.exists()) {
333: displayError("Project " + _projectname
334: + " already exists.");
335: return;
336: }
337: }
338: Field fSourceDir = _fields[1];
339: _currentSourceDir = ((JTextField) fSourceDir.field)
340: .getText();
341: if (_currentSourceDir == null
342: || _currentSourceDir.trim().equals("")) {
343: displayError("Source Code Path must have a value.");
344: return;
345: } else {
346: _currentSourceDir = new File(_currentSourceDir)
347: .getAbsolutePath();
348: File fProjectDir = new File(_currentSourceDir
349: + File.separator + _projectname);
350: System.out.println(_currentSourceDir);
351: if (fProjectDir.exists()) {
352: if (!fProjectDir.isDirectory()) {
353: displayError("Cannot create a directory for Project "
354: + _projectname
355: + " because a file with that name exists.");
356: return;
357: }
358: ;
359: } else {
360: fProjectDir.mkdirs();
361: }
362: }
363: _currentSourceDir = _currentSourceDir.replace('/',
364: File.separatorChar);
365: if (_currentSourceDir.endsWith(File.separator))
366: _currentSourceDir = _currentSourceDir.substring(0,
367: _currentSourceDir.length() - 1);
368: _currentSourceDir = _currentSourceDir.replace(
369: File.separatorChar, '/');
370: if (_specifyDBSettings.isSelected()) {
371: if (_dbsettings == null) {
372: displayError("Database Settings were not specified.");
373: return;
374: }
375: _jarFiles = (File[]) _dbsettings.get("JDBCJarFile");
376: } else
377: _jarFiles = null;
378:
379: //do a serach replace of the template files
380:
381: for (int j = 0; j < _salmonTemplates.length; j++) {
382: byte[] baSalmonTemplate = new byte[(int) _salmonTemplates[j]
383: .length()];
384: try {
385: FileInputStream fisSalmonTemplate = new FileInputStream(
386: _salmonTemplates[j]);
387: fisSalmonTemplate.read(baSalmonTemplate);
388: fisSalmonTemplate.close();
389: } catch (Exception ex) {
390: displayError("Framework has not been properly installed. Missing "
391: + _salmonTemplates[j].getAbsolutePath()
392: + ".");
393: return;
394: }
395: String sTemplate = new String(baSalmonTemplate);
396: if (_jarFiles != null) {
397: StringBuffer sbClassPathEntries = new StringBuffer();
398: for (int i = 0; i < _jarFiles.length; i++) {
399: String sFile = _jarFiles[i].getAbsolutePath();
400: sFile.replace(File.separatorChar, '/');
401: if (sFile.toLowerCase().endsWith(".jar")
402: || sFile.toLowerCase().endsWith(".zip")) {
403: String sJarEntry = _jdbcjarclasspathentry;
404: sJarEntry = replace(sJarEntry,
405: "$JDBCJARFILE$", sFile);
406: sbClassPathEntries.append(sJarEntry);
407: sbClassPathEntries.append("\r\n");
408: } else {
409: String sDirEntry = _jdbcdirclasspathentry;
410: sDirEntry = replace(sDirEntry,
411: "$JDBCJARFILE$", sFile);
412: sbClassPathEntries.append(sDirEntry);
413: sbClassPathEntries.append("\r\n");
414: }
415: }
416: sTemplate = replace(sTemplate,
417: "$JDBCCLASSPATHENTRY$", sbClassPathEntries
418: .toString());
419: } else {
420: sTemplate = replace(sTemplate,
421: "$JDBCCLASSPATHENTRY$", "");
422: }
423: if (_runInBrowser != null
424: && !_runInBrowser.trim().equals("")) {
425: int pos = _runInBrowser.indexOf("$PROJECT$");
426: while (pos > -1) {
427: _runInBrowser = replace(_runInBrowser,
428: "$PROJECT$", _projectname);
429: pos = _runInBrowser.indexOf("$PROJECT$");
430: }
431: sTemplate = replace(sTemplate, "$RUNINBROWSERS$",
432: _runInBrowser);
433: } else {
434: sTemplate = replace(sTemplate, "$RUNINBROWSERS$",
435: "");
436: }
437: if (_includeTomcatSource.isSelected()) {
438: sTemplate = replace(sTemplate, "$TOMCATSOURCE$",
439: _tomcatsource);
440: } else {
441: sTemplate = replace(sTemplate, "$TOMCATSOURCE$", "");
442: }
443: if (_includeFrameworkSource.isSelected()) {
444: sTemplate = replace(sTemplate, "$FRAMEWORKSOURCE$",
445: _frameworksource);
446: } else {
447: sTemplate = replace(sTemplate, "$FRAMEWORKSOURCE$",
448: "");
449: }
450: sTemplate = replace(sTemplate, "$TOMCAT$", _tomcatDir);
451: sTemplate = replace(sTemplate, "$JDKNAME$", _jdkname);
452: sTemplate = replace(sTemplate, "$TOMCATFWD$",
453: _tomcatFwdDir);
454: sTemplate = replace(sTemplate, "$JDKPATH$", _jdkdir);
455: sTemplate = replace(sTemplate, "$SOURCEDIR$",
456: _currentSourceDir);
457: sTemplate = replace(sTemplate, "$PROJECTNAME$",
458: _projectname);
459: sTemplate = replace(sTemplate, "$FRAMEWORKSOURCEDIR$",
460: _frameworkSourceDir);
461: sTemplate = replace(sTemplate, "$INTELLIJDIR$",
462: _intelliJDirFwd);
463: try {
464: String ext = _salmonTemplates[j].getName();
465: int pos = ext.indexOf(".");
466: ext = ext.substring(pos);
467: FileOutputStream fosProject = new FileOutputStream(
468: _intelliJDir + _projectname + ext);
469: fosProject.write(sTemplate.getBytes());
470: fosProject.close();
471: } catch (Exception ex) {
472: displayError("Unable to create project "
473: + _projectname);
474: return;
475: }
476: }
477:
478: File fTomcatProjectJspDir = new File(_tomcatDir
479: + File.separator + "webapps" + File.separator
480: + _projectname + File.separator + "Jsp");
481: File fTomcatProjectWebInfDir = new File(_tomcatDir
482: + File.separator + "webapps" + File.separator
483: + _projectname + File.separator + "WEB-INF");
484: File fTomcatProjectWebInfClassesDir = new File(_tomcatDir
485: + File.separator + "webapps" + File.separator
486: + _projectname + File.separator + "WEB-INF"
487: + File.separator + "classes");
488: File fTomcatProjectWebInfPropsDir = new File(_tomcatDir
489: + File.separator + "webapps" + File.separator
490: + _projectname + File.separator + "WEB-INF"
491: + File.separator + "properties");
492: if (!fTomcatProjectJspDir.exists())
493: fTomcatProjectJspDir.mkdirs();
494: if (!fTomcatProjectWebInfDir.exists())
495: fTomcatProjectWebInfDir.mkdirs();
496: if (!fTomcatProjectWebInfClassesDir.exists())
497: fTomcatProjectWebInfClassesDir.mkdirs();
498: if (propsInApp) {
499: if (!fTomcatProjectWebInfPropsDir.exists())
500: fTomcatProjectWebInfPropsDir.mkdirs();
501: }
502: File fTomcatResources = new File(_resourcesDir
503: .getAbsolutePath()
504: + File.separator + "Tomcat");
505:
506: File fJsp = new File(_resourcesDir.getAbsolutePath()
507: + File.separator + "jsp");
508: try {
509: copyFiles(fTomcatResources, fTomcatProjectWebInfDir);
510: copyFiles(fJsp, fTomcatProjectJspDir);
511: } catch (Exception ex) {
512: displayError("Unable to create resources.");
513: return;
514: }
515: if (_setAsDefaultProject.isSelected()) {
516: try {
517: IDETool.createDreamweaverProject(_resourcesDir
518: .getAbsolutePath(), _projectname,
519: _dreamweaverDir, "localhost:8080",
520: _tomcatDir + File.separator + "webapps"
521: + File.separator + _projectname);
522: } catch (Exception ex) {
523: displayError("Error creating Dreamweaver project"
524: + ex.getMessage());
525: }
526: }
527:
528: Hashtable htPropChanges = new Hashtable();
529: htPropChanges.put(_projectname + "."
530: + Props.IDE_DEFAULT_FRAMEWORK_APP, _projectname);
531: htPropChanges.put(_projectname + "." + Props.IDE_WEB_APP,
532: _projectname);
533: htPropChanges.put(_projectname + "."
534: + Props.IDE_DEFAULT_RUN_URL,
535: "http://localhost:8080/" + _projectname
536: + "/Jsp/hello.jsp");
537: if (propsInApp)
538: htPropChanges.put(_projectname + "."
539: + Props.IDE_APP_PROPS_PATH,
540: fTomcatProjectWebInfPropsDir.getAbsolutePath());
541: changeProperties(htPropChanges);
542:
543: String sDriver = "";
544: String sConnectURL = "";
545: String sUser = "";
546: String sPassword = "";
547: if (_specifyDBSettings.isSelected()) {
548: sDriver = (String) _dbsettings.get("JDBCDriver");
549: sConnectURL = (String) _dbsettings
550: .get("JDBCConnectUrl");
551: sUser = (String) _dbsettings.get("JDBCUser");
552: sPassword = (String) _dbsettings.get("JDBCPassword");
553: }
554: File fSalmonProperties = null;
555: if (propsInApp)
556: fSalmonProperties = new File(_resourcesDir
557: .getAbsolutePath()
558: + File.separator
559: + "salmonprops"
560: + File.separator + "salmonFull.properties");
561: else
562: fSalmonProperties = new File(_resourcesDir
563: .getAbsolutePath()
564: + File.separator
565: + "salmonprops"
566: + File.separator + "salmon.properties");
567: byte[] baPropertiesTemplate = new byte[(int) fSalmonProperties
568: .length()];
569: try {
570: FileInputStream fisProperties = new FileInputStream(
571: fSalmonProperties);
572: fisProperties.read(baPropertiesTemplate);
573: fisProperties.close();
574: } catch (Exception ex) {
575: displayError("Framework has not been properly installed. Missing "
576: + fSalmonProperties.getAbsolutePath() + ".");
577: return;
578: }
579: String sProperties = new String(baPropertiesTemplate);
580: sProperties = replace(sProperties, "$DRIVER$", sDriver);
581: sProperties = replace(sProperties, "$CONNECTURL$",
582: sConnectURL);
583: sProperties = replace(sProperties, "$DBUSER$", sUser);
584: sProperties = replace(sProperties, "$DBPASSWORD$",
585: sPassword);
586: sProperties = replace(sProperties, "$TOMCAT$",
587: fixSlashes(_tomcatDir));
588: sProperties = replace(sProperties, "$PROJECTNAME$",
589: _projectname);
590: try {
591: String propName = propsInApp ? "System" : _projectname;
592: String propPath = propsInApp ? fTomcatProjectWebInfPropsDir
593: .getAbsolutePath()
594: : Props.getPropsPath();
595: File fWritePropertiesFile = new File(propPath
596: + File.separator + propName + ".properties");
597: FileOutputStream fosProperties = new FileOutputStream(
598: fWritePropertiesFile);
599: fosProperties.write(sProperties.getBytes());
600: fosProperties.close();
601: } catch (Exception ex) {
602: displayError("Unable to create properties file.");
603: return;
604: }
605: _cancelClicked = false;
606: displayMessage("Use File->Open Project to open "
607: + _projectname + " project.");
608: setVisible(false);
609: } else if (e.getSource() == _specifyDBSettings) {
610: _fields[5].lookup.setEnabled(_specifyDBSettings
611: .isSelected());
612: } else {
613: Field f = null;
614: for (int i = 0; i < _noFields; i++) {
615: if (_fields[i].lookup != null
616: && _fields[i].lookup == e.getSource()) {
617: f = _fields[i];
618: break;
619: }
620: }
621: if (f != null) {
622: if (f.field instanceof JCheckBox) {
623: JFrame frame = new JFrame();
624: DatabaseDialog dd = new DatabaseDialog(frame,
625: _dbsettings);
626: _dbsettings = dd.getDBSettings();
627: } else {
628: String fileName = ((JTextField) f.field).getText();
629: JFileChooser c = new JFileChooser();
630: if (f.type == TYPE_FILE)
631: c.setFileSelectionMode(JFileChooser.FILES_ONLY);
632: else if (f.type == TYPE_DIR)
633: c
634: .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
635: else
636: c
637: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
638: c.setCurrentDirectory(new File(fileName));
639: if (c.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
640: if (c.getSelectedFile().exists())
641: ((JTextField) f.field).setText(c
642: .getSelectedFile()
643: .getAbsolutePath());
644: else {
645: String sFile = c.getSelectedFile()
646: .getAbsolutePath();
647: int iSlashIndex = sFile
648: .lastIndexOf(File.separator);
649: sFile = sFile.substring(0, iSlashIndex);
650: ((JTextField) f.field).setText(sFile);
651: }
652: }
653: }
654: }
655: }
656: }
657:
658: private JComponent addFieldToGrid(String property, String label,
659: int type) {
660: Field f = new Field();
661: f.property = property;
662: Dimension capSize = new Dimension(180, 25);
663: Dimension fieldSize = new Dimension(350, 25);
664: Dimension buttonSize = new Dimension(30, 25);
665: Dimension lookupSize = new Dimension(320, 25);
666: Dimension actionSize = new Dimension(290, 25);
667:
668: f.type = type;
669: if (type != TYPE_CHECKBOX && type != TYPE_CHECKBOXWITHACTION)
670: f.caption = DialogComponentFactory.makeLabel(label + ":");
671: else
672: f.caption = DialogComponentFactory.makeLabel("");
673: f.caption.setMaximumSize(capSize);
674: f.caption.setMinimumSize(capSize);
675: Box b = Box.createHorizontalBox();
676: b.add(f.caption);
677:
678: if (type == TYPE_TEXT) {
679: f.field = new JTextField(_props.getProperty(property));
680: f.field.setMaximumSize(fieldSize);
681: f.field.setMinimumSize(fieldSize);
682: b.add(f.field);
683: _mainGrid.add(b);
684: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
685: } else if (type == TYPE_PW) {
686: f.field = new JPasswordField(_props.getProperty(property));
687: f.field.setMaximumSize(fieldSize);
688: f.field.setMinimumSize(fieldSize);
689: b.add(f.field);
690: _mainGrid.add(b);
691: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
692: } else if (type == TYPE_FILE || type == TYPE_DIR) {
693: f.field = new JTextField(_props.getProperty(property));
694: f.field.setMaximumSize(lookupSize);
695: f.field.setMinimumSize(lookupSize);
696:
697: f.lookup = new JButton("..");
698: ((JButton) f.lookup).addActionListener(this );
699: ((JButton) f.lookup).setMaximumSize(buttonSize);
700: ((JButton) f.lookup).setMinimumSize(buttonSize);
701: b.add(f.field);
702: b.add(f.lookup);
703: _mainGrid.add(b);
704: } else if (type == TYPE_CHECKBOX) {
705: f.field = new JCheckBox(label);
706: f.field.setMaximumSize(lookupSize);
707: f.field.setMinimumSize(lookupSize);
708: b.add(f.field);
709: b.add(Box.createRigidArea(buttonSize));
710: _mainGrid.add(b);
711: } else if (type == TYPE_CHECKBOXWITHACTION) {
712: f.field = new JCheckBox(label);
713: f.field.setMaximumSize(actionSize);
714: f.field.setMinimumSize(actionSize);
715: f.lookup = new JButton("Set");
716: f.lookup.setEnabled(false);
717: // ((JButton)f.lookup).setBorder(new LineBorder(java.awt.Color.black,1));
718: // ((JButton)f.lookup).setBorder(new BevelBorder(BevelBorder.LOWERED));
719: // ((JButton)f.lookup).getBorder().getBorderInsets((JButton)f.lookup).bottom=0;
720: // ((JButton)f.lookup).getBorder().getBorderInsets((JButton)f.lookup).left=0;
721: // ((JButton)f.lookup).getBorder().getBorderInsets((JButton)f.lookup).right=0;
722: // ((JButton)f.lookup).getBorder().getBorderInsets((JButton)f.lookup).top=0;
723: ((JButton) f.lookup).addActionListener(this );
724: ((JButton) f.lookup).setMaximumSize(new Dimension(60, 25));
725: ((JButton) f.lookup).setMinimumSize(new Dimension(60, 25));
726: b.add(f.field);
727: b.add(f.lookup);
728: _mainGrid.add(b);
729: }
730:
731: _fields[_fieldIndex++] = f;
732: return f.field;
733: }
734:
735: /**
736: * Pops up a change dialog and saves changes to the System.properties file
737: */
738: protected static void changeProperties(Hashtable changes) {
739:
740: if (changes != null) {
741: try {
742: File outFile = new File(Props.getPropsPath()
743: + File.separator + "System$temp.properties");
744: File inFile = new File(Props.getPropsPath()
745: + File.separator + "System.properties");
746: PrintWriter out = new PrintWriter(new FileOutputStream(
747: outFile));
748: BufferedReader in = new BufferedReader(
749: new InputStreamReader(new FileInputStream(
750: inFile)));
751: String s = in.readLine();
752: while (s != null) {
753: int ndx = s.indexOf('=');
754: if (ndx == -1)
755: out.println(s);
756: else {
757: String key = s.substring(0, ndx).trim();
758: if (changes.containsKey(key)) {
759: out.println(key
760: + "="
761: + fixSlashes((String) changes
762: .get(key)));
763: changes.remove(key);
764: } else
765: out.println(s);
766: }
767: s = in.readLine();
768: }
769:
770: Enumeration e = changes.keys();
771: while (e.hasMoreElements()) {
772: String key = (String) e.nextElement();
773: String val = (String) changes.get(key);
774: out.println(key + "=" + fixSlashes(val));
775: }
776:
777: in.close();
778: out.close();
779: inFile.delete();
780: outFile.renameTo(inFile);
781: } catch (Exception e) {
782: }
783:
784: }
785:
786: }
787:
788: private void copyFiles(File fFromDir, File fToDir) throws Exception {
789: if (!fToDir.exists())
790: fToDir.mkdirs();
791: File[] fFiles = fFromDir.listFiles();
792: for (int i = 0; i < fFiles.length; i++) {
793: if (fFiles[i].isDirectory()) {
794: File fDestTo = new File(fToDir.getAbsolutePath()
795: + File.separator + fFiles[i].getName());
796: copyFiles(fFiles[i], fDestTo);
797: } else {
798: byte[] baFile = new byte[(int) fFiles[i].length()];
799: FileInputStream fis = new FileInputStream(fFiles[i]);
800: fis.read(baFile);
801: fis.close();
802: File fDestFile = new File(fToDir.getAbsolutePath()
803: + File.separator + fFiles[i].getName());
804: FileOutputStream fos = new FileOutputStream(fDestFile);
805: fos.write(baFile);
806: }
807: }
808: }
809:
810: private static void displayError(String error) {
811: System.out.println("Error Display:" + error);
812: JFrame f = new JFrame();
813: JOptionPane.showMessageDialog(f, error, "Error",
814: JOptionPane.ERROR_MESSAGE);
815: f.dispose();
816: }
817:
818: private static void displayMessage(String message) {
819: JFrame f = new JFrame();
820: JOptionPane.showMessageDialog(f, message, "Information",
821: JOptionPane.INFORMATION_MESSAGE);
822: f.dispose();
823: }
824:
825: private static String fixSlashes(String in) {
826: StringBuffer ret = new StringBuffer(in.length());
827: for (int i = 0; i < in.length(); i++) {
828: char c = in.charAt(i);
829: if (c == '\\')
830: ret.append("\\\\");
831: else
832: ret.append(c);
833: }
834: return ret.toString();
835: }
836:
837: /**
838: * Returns true if the user clicked the cancel button to exit the dialog
839: */
840: public boolean getCancel() {
841: return _cancelClicked;
842: }
843:
844: private void getJDKInformation() {
845: String sJdkXml = _intelliJDir + "config" + File.separator
846: + "options" + File.separator + "jdk.table.xml";
847: String sKeyFile = _intelliJDir + "config" + File.separator
848: + "idea40.key";
849: DOMParser dp = new DOMParser();
850: try {
851: Document doc = dp.parse(sJdkXml);
852: NodeList nlApplications = doc.getChildNodes();
853: Node nApplication = nlApplications.item(0);
854: NodeList nlComponents = nApplication.getChildNodes();
855: Node nComponent = nlComponents.item(1);
856: NodeList nlJDK = nComponent.getChildNodes();
857: for (int i = 1; i < nlJDK.getLength(); i++) {
858: Node nJDK = nlJDK.item(i);
859: if (nJDK.hasAttributes()) {
860: NamedNodeMap nnm = nJDK.getAttributes();
861: Node nDefault = nnm.getNamedItem("default");
862: // String sValue=nDefault.getFirstChild().getNodeValue();
863: String sValue = "true";
864: if (nDefault != null)
865: sValue = nDefault.getNodeValue();
866: System.out.println(sValue);
867: if (sValue.equals("true")) {
868: NodeList nlJdkNodes = nJDK.getChildNodes();
869: for (int k = 1; k < nlJdkNodes.getLength(); k++) {
870: Node nJdkNode = nlJdkNodes.item(k);
871: if (nJdkNode.getNodeName().equals("name")) {
872: NamedNodeMap nnmJdkName = nJdkNode
873: .getAttributes();
874: Node nValue = nnmJdkName
875: .getNamedItem("value");
876: // _jdkname=nValue.getFirstChild().getNodeValue();
877: _jdkname = nValue.getNodeValue();
878: _jdkname = replace(_jdkname, "\"",
879: """);
880: }
881: if (nJdkNode.getNodeName().equals(
882: "homePath")) {
883: NamedNodeMap nnmHomePath = nJdkNode
884: .getAttributes();
885: Node nValue = nnmHomePath
886: .getNamedItem("value");
887: _jdkdir = nValue.getNodeValue();
888: if (_jdkdir.endsWith(File.separator))
889: _jdkdir = _jdkdir.substring(0,
890: _jdkdir.length() - 1);
891: _jdkdir = _jdkdir.replace(
892: File.separatorChar, '/');
893: _intelliJVersion = 3;
894: File f = new File(sKeyFile);
895: if (f.exists())
896: _intelliJVersion = 4;
897: }
898: if (nJdkNode.getNodeName().equals("roots")) {
899: NodeList nlRoot = nJdkNode
900: .getChildNodes();
901: Node nRoot = nlRoot.item(1);
902: NamedNodeMap nnmRoot = nRoot
903: .getAttributes();
904: Node nFile = nnmRoot
905: .getNamedItem("file");
906: // _jdkdir=nFile.getFirstChild().getNodeValue();
907: if (nFile != null) {
908: _jdkdir = nFile.getNodeValue();
909: _jdkdir = _jdkdir.substring(7);
910: _jdkdir = _jdkdir.replace('/',
911: File.separatorChar);
912: if (_jdkdir
913: .endsWith(File.separator))
914: _jdkdir = _jdkdir.substring(0,
915: _jdkdir.length() - 1);
916: _jdkdir = _jdkdir.replace(
917: File.separatorChar, '/');
918: _intelliJVersion = 2;
919: }
920: }
921: }
922: }
923: }
924: }
925: } catch (Exception e) {
926: e.printStackTrace();
927: }
928: System.out.println(_intelliJVersion + " " + _jdkname + " "
929: + _jdkdir);
930: }
931:
932: /**
933: * Returns a Hashtable of items changed by the user
934: */
935: public String getSourceDir() {
936: return _currentSourceDir;
937: }
938:
939: private String replace(String sString, String sOldString,
940: String sNewString) {
941: StringBuffer sbString = new StringBuffer(sString);
942: while (true) {
943: int iIndex = sbString.toString().indexOf(sOldString);
944: if (iIndex < 0)
945: break;
946: sbString.replace(iIndex, iIndex + sOldString.length(),
947: sNewString);
948: }
949: return sbString.toString();
950: }
951:
952: public void windowActivated(WindowEvent e) {
953:
954: }
955:
956: public void windowClosed(WindowEvent e) {
957: }
958:
959: public void windowClosing(WindowEvent e) {
960: }
961:
962: public void windowDeactivated(WindowEvent e) {
963: }
964:
965: public void windowDeiconified(WindowEvent e) {
966: }
967:
968: public void windowIconified(WindowEvent e) {
969: }
970:
971: public void windowOpened(WindowEvent e) {
972: }
973: }
|