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/EclipsePropertiesDialog.java $
024: //$Author: Dan $
025: //$Revision: 14 $
026: //$Modtime: 9/24/04 1:05p $
027: /////////////////////////
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.io.File;
031: import java.util.*;
032:
033: import javax.swing.*;
034:
035: import com.salmonllc.properties.Props;
036: import com.salmonllc.swing.STextField;
037:
038: public class EclipsePropertiesDialog extends JDialog implements
039: ActionListener, WindowListener {
040:
041: boolean _cancelClicked = true;
042: JButton _save;
043: JButton _cancel;
044: JFrame _owner;
045: Props _props;
046: int _fieldIndex = 0;
047: int _noFields = 18;
048: Field _fields[];
049: Box _mainGrid;
050: Hashtable _changedValues = new Hashtable();
051:
052: public static final int TYPE_TEXT = 0;
053: public static final int TYPE_PW = 1;
054: public static final int TYPE_FILE = 2;
055: public static final int TYPE_DIR = 3;
056: public static final int TYPE_DD = 4;
057: public static final int TYPE_CLASSPATH = 5;
058: public static final int TYPE_PATH = 6;
059: public static final int TYPE_TF = 7;
060:
061: private class Field {
062: public JLabel caption;
063: public JComponent field;
064: public String property;
065: public JComponent lookup;
066: public int type;
067: }
068:
069: public EclipsePropertiesDialog(JFrame owner, Props p) {
070: super (owner, "Set SOFIA Properties", true);
071: if (IDETool.getProject() != null)
072: setTitle("Set SOFIA Properties (Project:"
073: + IDETool.getProject() + ")");
074:
075: _owner = owner;
076: _props = p;
077:
078: Vector browserProps = new Vector();
079: Enumeration en = p.getKeys();
080: while (en.hasMoreElements()) {
081: String key = (String) en.nextElement();
082: if (key.startsWith(Props.IDE_BROWSER_PATH + ".")) {
083: browserProps.add(key);
084: _noFields++;
085: }
086: }
087:
088: int width = 600;
089: int height = 566 + (28 * browserProps.size());
090: Dimension frameBounds = Toolkit.getDefaultToolkit()
091: .getScreenSize();
092: int x = (frameBounds.width - width) / 2;
093: int y = (frameBounds.height - height) / 2;
094: setBounds(x, y, width, height);
095:
096: _fields = new Field[_noFields];
097: _mainGrid = Box.createVerticalBox();
098:
099: addFieldToGrid(IDETool
100: .getProjectProperty(Props.IDE_DEFAULT_RUN_URL),
101: "Default URL or JSP to Run", TYPE_FILE);
102: addFieldToGrid(IDETool.getProjectProperty(Props.IDE_WEB_APP),
103: "Default Web Application", TYPE_TEXT);
104: addFieldToGrid(IDETool
105: .getProjectProperty(Props.IDE_DEFAULT_FRAMEWORK_APP),
106: "Default Framework Application", TYPE_TEXT);
107: addFieldToGrid(IDETool
108: .getProjectProperty(Props.IDE_DEFAULT_SOURCE_PATH),
109: "Source Code Path", TYPE_DIR);
110: addFieldToGrid(Props.IDE_USE_APP_PROPERTIES,
111: "Use Prop Files from Application", TYPE_TF);
112: addFieldToGrid(IDETool
113: .getProjectProperty(Props.IDE_APP_PROPS_PATH),
114: "Properties File Path", TYPE_DIR);
115: addFieldToGrid(Props.IDE_SERVER_TYPE, "Server Type", TYPE_DD);
116: addFieldToGrid(Props.IDE_DEFAULT_HOST, "Test Server Host:Port",
117: TYPE_TEXT);
118: addFieldToGrid(Props.IDE_SERVER_MANAGER_ID,
119: "Server Manager User ID", TYPE_TEXT);
120: addFieldToGrid(Props.IDE_SERVER_MANAGER_PW,
121: "Server Manager Password", TYPE_PW);
122: addFieldToGrid(Props.IDE_CLASSPATH, "Server Class Path",
123: TYPE_CLASSPATH);
124: addFieldToGrid(Props.IDE_VMARGS, "Server VM Args", TYPE_TEXT);
125: addFieldToGrid(Props.IDE_LIBPATH, "Server Library Path",
126: TYPE_PATH);
127: addFieldToGrid(Props.IDE_WORKING_DIRECTORY,
128: "Server Working Directory", TYPE_DIR);
129: addFieldToGrid(Props.IDE_SERVER_CONFIG_FILE,
130: "Server Config File", TYPE_FILE);
131:
132: addFieldToGrid(Props.IDE_BROWSER_PATH, "Default Browser Path",
133: TYPE_FILE);
134: for (int i = 0; i < browserProps.size(); i++) {
135: String key = (String) browserProps.elementAt(i);
136: String label = key.substring(Props.IDE_BROWSER_PATH
137: .length() + 1)
138: + " Browser Path";
139: addFieldToGrid(key, label, TYPE_FILE);
140: }
141: addFieldToGrid(Props.IDE_DREAMWEAVER_PATH, "Dreamweaver Path",
142: TYPE_FILE);
143: addFieldToGrid(Props.IDE_FRAMEWORK_RESOURCES_PATH,
144: "Resources Path", TYPE_DIR);
145:
146: _save = new JButton("Save");
147: _save.addActionListener(this );
148: _cancel = new JButton("Cancel");
149: _cancel.addActionListener(this );
150: JPanel buttonBar = new JPanel(new FlowLayout());
151: buttonBar.add(_save);
152: buttonBar.add(_cancel);
153: buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT);
154: Box box = Box.createVerticalBox();
155:
156: box.add(Box.createRigidArea(new Dimension(100, 10)));
157: box.add(_mainGrid);
158: box.add(Box.createRigidArea(new Dimension(100, 5)));
159: box.add(buttonBar);
160:
161: getContentPane().add(box);
162:
163: addWindowListener(this );
164: setVisible(true);
165: }
166:
167: public void actionPerformed(ActionEvent e) {
168: if (e.getSource() == _cancel) {
169: _cancelClicked = true;
170: setVisible(false);
171: } else if (e.getSource() == _save) {
172: for (int i = 0; i < _noFields; i++) {
173: Field f = _fields[i];
174: String origProp = _props.getProperty(f.property);
175: String currentProp = null;
176: if (f.field instanceof STextField)
177: currentProp = ((STextField) f.field).getText();
178: else if (f.field instanceof JComboBox)
179: currentProp = (String) ((JComboBox) f.field)
180: .getSelectedItem();
181:
182: if (currentProp != null
183: && currentProp.trim().length() == 0)
184: currentProp = null;
185: if (!equals(origProp, currentProp)) {
186: if (currentProp == null)
187: currentProp = "";
188: _changedValues.put(f.property, currentProp);
189: }
190: }
191: _cancelClicked = false;
192: setVisible(false);
193: } else {
194: Field f = null;
195: for (int i = 0; i < _noFields; i++) {
196: if (_fields[i].lookup != null
197: && _fields[i].lookup == e.getSource()) {
198: f = _fields[i];
199: break;
200: }
201: }
202: if (f != null) {
203: if (f.type == TYPE_FILE || f.type == TYPE_DIR) {
204: String fileName = ((STextField) f.field).getText();
205: JFileChooser c = new JFileChooser();
206: if (f.type == TYPE_FILE)
207: c.setFileSelectionMode(JFileChooser.FILES_ONLY);
208: else
209: c
210: .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
211: c.setCurrentDirectory(new File(fileName));
212: if (c.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION)
213: ((STextField) f.field).setText(c
214: .getSelectedFile().getAbsolutePath());
215: } else if (f.type == TYPE_CLASSPATH
216: || f.type == TYPE_PATH) {
217: String path = ((STextField) f.field).getText();
218: ClassPathDialog d = new ClassPathDialog(_owner,
219: path, f.type == TYPE_CLASSPATH);
220: path = d.getPaths();
221: d.dispose();
222: if (path != null)
223: ((STextField) f.field).setText(path);
224: }
225: }
226: }
227: }
228:
229: private void addFieldToGrid(String property, String label, int type) {
230: Field f = new Field();
231: f.property = property;
232: Dimension capSize = new Dimension(180, 25);
233: Dimension fieldSize = new Dimension(350, 25);
234: Dimension buttonSize = new Dimension(25, 23);
235: Dimension lookupSize = new Dimension(325, 25);
236:
237: f.caption = DialogComponentFactory.makeLabel(label + ":");
238: f.caption.setMaximumSize(capSize);
239: f.caption.setMinimumSize(capSize);
240: f.type = type;
241: Box b = Box.createHorizontalBox();
242: b.add(f.caption);
243:
244: if (type == TYPE_TEXT) {
245: f.field = new STextField();
246: ((STextField) f.field)
247: .setText(_props.getProperty(property));
248: f.field.setMaximumSize(fieldSize);
249: f.field.setMinimumSize(fieldSize);
250: b.add(f.field);
251: _mainGrid.add(b);
252: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
253: } else if (type == TYPE_DD && property == Props.IDE_SERVER_TYPE) {
254: String items[] = { IDETool.SERVER_TOMCAT40,
255: IDETool.SERVER_TOMCAT41, IDETool.SERVER_TOMCAT50,
256: IDETool.SERVER_WEBLOGIC6 };
257: JComboBox box = new JComboBox(items);
258: String prop = _props.getProperty(property);
259: if (prop != null)
260: box.setSelectedItem(prop);
261: f.field = box;
262: f.field.setMaximumSize(fieldSize);
263: f.field.setMinimumSize(fieldSize);
264: b.add(f.field);
265: _mainGrid.add(b);
266: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
267: } else if (type == TYPE_PW) {
268: f.field = new JPasswordField(_props.getProperty(property));
269: f.field.setMaximumSize(fieldSize);
270: f.field.setMinimumSize(fieldSize);
271: b.add(f.field);
272: _mainGrid.add(b);
273: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
274: } else if (type == TYPE_FILE || type == TYPE_DIR
275: || type == TYPE_CLASSPATH || type == TYPE_PATH) {
276: f.field = new STextField();
277: ((STextField) f.field)
278: .setText(_props.getProperty(property));
279: f.field.setMaximumSize(lookupSize);
280: f.field.setMinimumSize(lookupSize);
281:
282: f.lookup = new JButton("..");
283: ((JButton) f.lookup).addActionListener(this );
284: f.lookup.setMaximumSize(buttonSize);
285: f.lookup.setMinimumSize(buttonSize);
286: b.add(f.field);
287: b.add(f.lookup);
288: _mainGrid.add(b);
289: } else if (type == TYPE_TF) {
290: String items[] = { "false", "true" };
291: JComboBox box = new JComboBox(items);
292: String prop = _props.getProperty(property);
293: if (prop != null)
294: box.setSelectedItem(prop);
295: f.field = box;
296: f.field.setMaximumSize(fieldSize);
297: f.field.setMinimumSize(fieldSize);
298: b.add(f.field);
299: _mainGrid.add(b);
300: _mainGrid.add(Box.createRigidArea(new Dimension(255, 3)));
301: }
302:
303: _fields[_fieldIndex++] = f;
304: }
305:
306: private boolean equals(String val1, String val2) {
307: if (val1 == null && val2 == null)
308: return true;
309: else if (val1 == null && val2 != null)
310: return false;
311: else if (val2 == null && val1 != null)
312: return false;
313: else
314: return val1.equals(val2);
315: }
316:
317: /**
318: * Returns true if the user clicked the cancel button to exit the dialog
319: */
320: public boolean getCancel() {
321: return _cancelClicked;
322: }
323:
324: /**
325: * Returns a Hashtable of items changed by the user
326: */
327: public Hashtable getChangedValues() {
328: return _changedValues;
329: }
330:
331: public void windowActivated(WindowEvent e) {
332:
333: }
334:
335: public void windowClosed(WindowEvent e) {
336: }
337:
338: public void windowClosing(WindowEvent e) {
339: }
340:
341: public void windowDeactivated(WindowEvent e) {
342: }
343:
344: public void windowDeiconified(WindowEvent e) {
345: }
346:
347: public void windowIconified(WindowEvent e) {
348: }
349:
350: public void windowOpened(WindowEvent e) {
351: }
352: }
|