001: package com.salmonllc.ideTools.eclipse;
002:
003: import java.io.File;
004: import java.util.Properties;
005:
006: import org.eclipse.jface.wizard.WizardPage;
007: import org.eclipse.swt.SWT;
008: import org.eclipse.swt.events.ModifyEvent;
009: import org.eclipse.swt.events.ModifyListener;
010: import org.eclipse.swt.events.MouseEvent;
011: import org.eclipse.swt.events.MouseListener;
012: import org.eclipse.swt.layout.GridData;
013: import org.eclipse.swt.layout.GridLayout;
014: import org.eclipse.swt.widgets.Button;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.DirectoryDialog;
017: import org.eclipse.swt.widgets.FileDialog;
018: import org.eclipse.swt.widgets.Label;
019: import org.eclipse.swt.widgets.Text;
020:
021: /**
022: * @author Administrator
023: *
024: * To change this generated comment edit the template variable "typecomment":
025: * Window>Preferences>Java>Templates.
026: * To enable and disable the creation of type comments go to
027: * Window>Preferences>Java>Code Generation.
028: */
029: public class SalmonFrameworkCreationWizardPage extends WizardPage
030: implements MouseListener, ModifyListener {
031:
032: Text _tomcatHome;
033: Text _sofiaHome;
034: Text _jdbcJar;
035: boolean _askForJar, _finishedCreating;
036:
037: public SalmonFrameworkCreationWizardPage(String pageName,
038: boolean askForJar) {
039: super (pageName);
040: _askForJar = askForJar;
041: _finishedCreating = false;
042: }
043:
044: public void createControl(Composite parent) {
045: Composite composite = new Composite(parent, SWT.NULL);
046:
047: GridLayout l = new GridLayout();
048: composite.setLayout(l);
049: composite.setLayoutData(new GridData(GridData.FILL_BOTH));
050: l.numColumns = 2;
051:
052: _sofiaHome = createFileChooser(composite,
053: "SOFIA install directory:");
054: _tomcatHome = createFileChooser(composite,
055: "Tomcat install directory:");
056:
057: Properties installProps = SalmonPlugin.getPlugInInstallProps();
058: _tomcatHome.setText(installProps.getProperty("TomcatHome", ""));
059: _sofiaHome.setText(installProps.getProperty("SofiaHome", ""));
060:
061: if (_askForJar) {
062: _jdbcJar = createFileChooser(composite,
063: "JDBC Driver Jar File");
064: _jdbcJar.setText(installProps.getProperty(
065: "JDBCDriverJarFile", ""));
066: }
067:
068: setControl(composite);
069: _finishedCreating = true;
070: validate();
071: }
072:
073: public Text createFileChooser(Composite parent, String labelText) {
074:
075: Label label = new Label(parent, SWT.NONE);
076: label.setText(labelText);
077: label.setEnabled(true);
078:
079: Composite c = new Composite(parent, SWT.NONE);
080: GridLayout l = new GridLayout();
081: c.setLayout(l);
082: c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
083: l.numColumns = 2;
084:
085: Text t = new Text(c, SWT.BORDER);
086: GridData data = new GridData(GridData.FILL_HORIZONTAL);
087: t.setLayoutData(data);
088: t.setEnabled(true);
089: t.addModifyListener(this );
090:
091: Button b = new Button(c, SWT.NONE);
092: b.setText("Browse...");
093: b.addMouseListener(this );
094: b.setData(t);
095: return t;
096: }
097:
098: /**
099: * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(MouseEvent)
100: */
101: public void mouseDoubleClick(MouseEvent e) {
102: }
103:
104: /**
105: * @see org.eclipse.swt.events.MouseListener#mouseDown(MouseEvent)
106: */
107: public void mouseDown(MouseEvent e) {
108: }
109:
110: /**
111: * @see org.eclipse.swt.events.MouseListener#mouseUp(MouseEvent)
112: */
113: public void mouseUp(MouseEvent e) {
114: Button b = (Button) e.getSource();
115: Text t = (Text) b.getData();
116: if (t == _jdbcJar) {
117: FileDialog f = new FileDialog(b.getShell());
118: String fileName = f.open();
119: if (fileName != null && fileName.trim().length() > 0)
120: t.setText(fileName);
121:
122: } else {
123: DirectoryDialog f = new DirectoryDialog(b.getShell());
124: String fileName = f.open();
125: if (fileName != null && fileName.trim().length() > 0)
126: t.setText(fileName);
127: }
128:
129: }
130:
131: /**
132: * @see org.eclipse.swt.events.ModifyListener#modifyText(ModifyEvent)
133: */
134: public void modifyText(ModifyEvent e) {
135: if (_finishedCreating)
136: validate();
137: }
138:
139: private void validate() {
140: setPageComplete(false);
141:
142: String sofiaHome = _sofiaHome.getText();
143: setErrorMessage("Invalid SOFIA home directory");
144: if (sofiaHome == null)
145: return;
146: File f = new File(cleanDirName(sofiaHome) + File.separatorChar
147: + "SourceCode" + File.separatorChar + "Framework");
148: if (!f.exists())
149: return;
150:
151: String tomcatHome = _tomcatHome.getText();
152: setErrorMessage("Invalid Tomcat home directory");
153: if (tomcatHome == null)
154: return;
155: if ((!SalmonPlugin
156: .arePropsInSourceApplicationPaths(cleanDirName(tomcatHome)))
157: && (!SalmonPlugin
158: .arePropsInSourceFrameworkPath(tomcatHome)))
159: return;
160:
161: if (_askForJar) {
162: String jdbcJar = _jdbcJar.getText();
163: setErrorMessage("Invalid JDBC Jar File");
164: if (jdbcJar != null && jdbcJar.trim().length() > 0) {
165: f = new File(cleanDirName(jdbcJar));
166: if (!f.exists())
167: return;
168: }
169: }
170:
171: setErrorMessage(null);
172: setPageComplete(true);
173: }
174:
175: public String getTomcatHome() {
176: return cleanDirName(_tomcatHome.getText());
177: }
178:
179: public String getSOFIAHome() {
180: return cleanDirName(_sofiaHome.getText());
181: }
182:
183: public String getJDBCJar() {
184: return cleanDirName(_jdbcJar.getText());
185: }
186:
187: private String cleanDirName(String dir) {
188: if (dir == null)
189: return "";
190: dir = dir.trim();
191: if (dir.endsWith(File.separator))
192: dir = dir.substring(0, dir.length() - 1);
193: return dir;
194: }
195: }
|