001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.importer;
024:
025: // ToolBox imports
026: import org.enhydra.tool.common.PathHandle;
027: import org.enhydra.tool.common.SwingUtil;
028:
029: // Kelp imports
030: import org.enhydra.kelp.common.PathUtil;
031: import org.enhydra.kelp.common.ValidationException;
032: import org.enhydra.kelp.common.ValidationUtil;
033:
034: // Standard imports
035: import javax.swing.*;
036: import javax.swing.border.*;
037: import java.awt.*;
038: import java.awt.event.ActionEvent;
039: import java.awt.event.ActionListener;
040: import java.beans.*;
041: import java.io.File;
042: import java.util.ResourceBundle;
043:
044: /**
045: * Panel for entering the default options: project name, package
046: * and destination.
047: *
048: * @author Paul Mahar
049: */
050: public class PathPanel extends ImporterPanel {
051: static ResourceBundle res = ResourceBundle
052: .getBundle("org.enhydra.kelp.common.Res"); // nores
053: transient private JPanel panelSource;
054: transient private JTextField textSource;
055: transient private JButton buttonSource;
056: transient private JPanel panelResource;
057: transient private JTextField textResource;
058: transient private JButton buttonResource;
059:
060: //
061: transient private JPanel panelFiller;
062: transient private GridBagLayout layoutMain;
063: transient private GridBagLayout layoutSource;
064: transient private GridBagLayout layoutResource;
065: transient private LocalButtonListener buttonListener;
066: transient private TitledBorder borderSource;
067: transient private TitledBorder borderResource;
068:
069: /**
070: * Create default option panel 1 for entering the
071: * following default options: project name, package and
072: * destination.
073: */
074: public PathPanel() {
075: try {
076: jbInit();
077: pmInit();
078: } catch (Exception ex) {
079: ex.printStackTrace();
080: }
081: }
082:
083: /**
084: * Read project name, package and destination values from the
085: * option set into the swing controls.
086: *
087: * @exception GeneratorException
088: * Thrown if unable to update Swing controls with option set values.
089: */
090: public void readOptions() {
091:
092: // wait till activated to to any real reading
093: }
094:
095: /**
096: * Write project name, package and destination values from the
097: * swing controls into the option set.
098: *
099: * @exception GeneratorException
100: * Thrown if unable to update option set from Swing control values.
101: */
102: public void writeOptions() throws ValidationException {
103: String value = new String();
104:
105: if (getPaths() == null) {
106: throw new ValidationException(res
107: .getString("Import_paths_not_set"));
108: }
109:
110: // source
111: value = textSource.getText().trim();
112: getPaths().setSourcePath(value);
113:
114: // resource
115: value = textResource.getText().trim();
116: getPaths().setResourcePath(value);
117: }
118:
119: /**
120: * Validate project name, package and destination values
121: * in the swing controls.
122: *
123: * @exception ValidationException
124: * Thrown if swing control values are not valid for the
125: * current option set.
126: */
127: public void validateOptions() throws ValidationException {
128: String value = new String();
129:
130: // package
131: value = textSource.getText().trim();
132: if (!ValidationUtil.isDirectory(value)) {
133: throw new ValidationException(res
134: .getString("SourcePathInvalid")
135: + res.getString("DirectoryNotFound"));
136: }
137:
138: // destination
139: value = textResource.getText().trim();
140: if (!ValidationUtil.isDirectory(value)) {
141: throw new ValidationException(res
142: .getString("ResourcePathInvalid")
143: + res.getString("DirectoryNotFound"));
144: }
145: }
146:
147: /**
148: * Get the title to use on the current page.
149: *
150: * @return
151: * A string to place at the top of a CodeGen wizard panel.
152: */
153: public String getPageTitle() {
154: return res.getString("Path_details");
155: }
156:
157: /**
158: * Get the instructions for entering option values for the
159: * current page.
160: *
161: * @return
162: * A string to place below the page title.
163: */
164: public String getInstructions() {
165: StringBuffer buf = new StringBuffer();
166:
167: buf.append(res.getString("PathInstruct1"));
168: buf.append(res.getString("PathInstruct2"));
169: buf.append(res.getString("PathInstruct3"));
170: buf.append(res.getString("PathInstruct4"));
171: buf.append(res.getString("PathInstruct5"));
172: buf.append(res.getString("PathInstruct6"));
173: buf.append(res.getString("PathInstruct7"));
174: buf.append(res.getString("PathInstruct8"));
175: buf.append(res.getString("PathInstruct9"));
176: return buf.toString();
177: }
178:
179: public void activated() {
180: initPaths();
181: }
182:
183: private void initPaths() {
184: String path = null;
185:
186: // source path
187: path = getPaths().getSourcePath();
188: if (path == null) {
189: textSource.setText(getPaths().getDefaultSourcePath());
190: } else {
191: textSource.setText(path);
192: }
193:
194: // resource path
195: path = getPaths().getResourcePath();
196: if (path == null) {
197: textResource.setText(getPaths().getDefaultResourcePath());
198: } else {
199: textResource.setText(path);
200: }
201: }
202:
203: // /
204: // /
205:
206: /**
207: * Method declaration
208: *
209: *
210: * @exception Exception
211: *
212: * @see
213: */
214: private void jbInit() throws Exception {
215: textSource = (JTextField) Beans.instantiate(getClass()
216: .getClassLoader(), JTextField.class.getName());
217: panelSource = (JPanel) Beans.instantiate(getClass()
218: .getClassLoader(), JPanel.class.getName());
219: panelResource = (JPanel) Beans.instantiate(getClass()
220: .getClassLoader(), JPanel.class.getName());
221: layoutSource = (GridBagLayout) Beans.instantiate(getClass()
222: .getClassLoader(), GridBagLayout.class.getName());
223: layoutResource = (GridBagLayout) Beans.instantiate(getClass()
224: .getClassLoader(), GridBagLayout.class.getName());
225: buttonSource = (JButton) Beans.instantiate(getClass()
226: .getClassLoader(), JButton.class.getName());
227: buttonResource = (JButton) Beans.instantiate(getClass()
228: .getClassLoader(), JButton.class.getName());
229: textResource = (JTextField) Beans.instantiate(getClass()
230: .getClassLoader(), JTextField.class.getName());
231: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
232: .getClassLoader(), GridBagLayout.class.getName());
233: panelFiller = (JPanel) Beans.instantiate(getClass()
234: .getClassLoader(), JPanel.class.getName());
235: buttonSource.setText("..."); // nores
236: buttonResource.setText("..."); // nores
237: panelSource.setLayout(layoutSource);
238: panelSource.add(textSource, new GridBagConstraints(0, 0, 1, 1,
239: 0.1, 0.1, GridBagConstraints.WEST,
240: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
241: 0, 0));
242: panelSource
243: .add(buttonSource, new GridBagConstraints(1, 0, 1, 2,
244: 0.0, 0.0, GridBagConstraints.CENTER,
245: GridBagConstraints.NONE,
246: new Insets(5, 5, 5, 20), 0, 0));
247: panelResource.setLayout(layoutResource);
248: panelResource.add(textResource, new GridBagConstraints(0, 0, 1,
249: 1, 0.1, 0.1, GridBagConstraints.WEST,
250: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
251: 0, 0));
252: panelResource
253: .add(buttonResource, new GridBagConstraints(1, 0, 1, 2,
254: 0.0, 0.0, GridBagConstraints.CENTER,
255: GridBagConstraints.NONE,
256: new Insets(5, 5, 5, 20), 0, 0));
257: this .setLayout(layoutMain);
258: this .add(panelSource, new GridBagConstraints(0, 0, 1, 1, 0.1,
259: 0.1, GridBagConstraints.CENTER,
260: GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
261: this .add(panelResource, new GridBagConstraints(0, 1, 1, 1, 0.1,
262: 0.1, GridBagConstraints.CENTER,
263: GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
264: }
265:
266: /**
267: * Method declaration
268: *
269: *
270: * @see
271: */
272: private void pmInit() {
273: Border border = BorderFactory.createEtchedBorder();
274:
275: borderSource = BorderFactory.createTitledBorder(border);
276: borderSource.setTitle(res.getString("borderSource_Title"));
277: borderResource = BorderFactory.createTitledBorder(border);
278: borderResource.setTitle(res.getString("borderResource_Title"));
279: panelSource.setBorder(borderSource);
280: panelResource.setBorder(borderResource);
281: buttonListener = new LocalButtonListener();
282: buttonResource.addActionListener(buttonListener);
283: buttonSource.addActionListener(buttonListener);
284: textResource.setText(new String());
285: textSource.setText(new String());
286: }
287:
288: /**
289: * Method declaration
290: *
291: *
292: * @see
293: */
294: private void browseForFile(JTextField field, String title) {
295: File destDir = null;
296:
297: destDir = SwingUtil.getDirectoryChoice(this , field.getText(),
298: title);
299: if (destDir != null) {
300: field.setText(PathHandle.createPathString(destDir));
301: }
302: }
303:
304: /**
305: * Class declaration
306: *
307: *
308: * @author Paul Mahar
309: */
310: private class LocalButtonListener implements ActionListener {
311:
312: public void actionPerformed(ActionEvent event) {
313: Object source = event.getSource();
314:
315: if (source == buttonSource) {
316: browseForFile(textSource, res
317: .getString("Select_source_path"));
318: } else {
319: browseForFile(textResource, res
320: .getString("Select_resource_path"));
321: }
322: }
323:
324: }
325: }
|