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.SwingUtil;
027: import org.enhydra.tool.common.PathHandle;
028:
029: // Kelp imports
030: import org.enhydra.kelp.common.ValidationUtil;
031: import org.enhydra.kelp.common.ValidationException;
032:
033: // Standard imports
034: import javax.swing.*;
035: import javax.swing.border.*;
036: import java.awt.*;
037: import java.awt.event.ActionEvent;
038: import java.awt.event.ActionListener;
039: import java.beans.*;
040: import java.io.File;
041: import java.util.ResourceBundle;
042:
043: /**
044: * Panel for entering the default options: project name, package
045: * and destination.
046: *
047: * @author Paul Mahar
048: */
049: public class RootPanel extends ImporterPanel {
050: static ResourceBundle res = ResourceBundle
051: .getBundle("org.enhydra.kelp.common.Res"); // nores
052: transient private JPanel panelRoot;
053: transient private JTextField textRoot;
054: transient private JButton buttonRoot;
055:
056: //
057: transient private JPanel panelFiller;
058: transient private GridBagLayout layoutMain;
059: transient private GridBagLayout layoutRoot;
060: transient private LocalButtonListener buttonListener;
061: transient private TitledBorder borderRoot;
062:
063: /**
064: * Create default option panel 1 for entering the
065: * following default options: project name, package and
066: * destination.
067: */
068: public RootPanel() {
069: try {
070: jbInit();
071: pmInit();
072: } catch (Exception ex) {
073: ex.printStackTrace();
074: }
075: }
076:
077: /**
078: * Read project name, package and destination values from the
079: * option set into the swing controls.
080: *
081: * @exception GeneratorException
082: * Thrown if unable to update Swing controls with option set values.
083: */
084: public void readOptions() {
085: String path;
086:
087: // project root
088: path = getPaths().getRootPath();
089: if (path == null) {
090: textRoot.setText(new String());
091: } else {
092: textRoot.setText(path);
093: }
094: }
095:
096: /**
097: * Write project name, package and destination values from the
098: * swing controls into the option set.
099: *
100: * @exception GeneratorException
101: * Thrown if unable to update option set from Swing control values.
102: */
103: public void writeOptions() throws ValidationException {
104: String path = null;
105:
106: if (getPaths() == null) {
107: throw new ValidationException(res
108: .getString("Import_paths_not_set1"));
109: }
110:
111: // root
112: path = textRoot.getText();
113: getPaths().setRootPath(path);
114: }
115:
116: /**
117: * Validate project name, package and destination values
118: * in the swing controls.
119: *
120: * @exception ValidationException
121: * Thrown if swing control values are not valid for the
122: * current option set.
123: */
124: public void validateOptions() throws ValidationException {
125: String value = new String();
126:
127: // project name
128: value = textRoot.getText().trim();
129: if (!ValidationUtil.isDirectory(value)) {
130: throw new ValidationException(res
131: .getString("Project_directory_is")
132: + res.getString("Directory_not_found_"));
133: }
134: }
135:
136: /**
137: * Get the title to use on the current page.
138: *
139: * @return
140: * A string to place at the top of a CodeGen wizard panel.
141: */
142: public String getPageTitle() {
143: return res.getString("Project_Directory");
144: }
145:
146: /**
147: * Get the instructions for entering option values for the
148: * current page.
149: *
150: * @return
151: * A string to place below the page title.
152: */
153: public String getInstructions() {
154: StringBuffer buf = new StringBuffer();
155:
156: buf.append(res.getString("RootInstruct1"));
157: buf.append(res.getString("RootInstruct2"));
158: buf.append(res.getString("RootInstruct3"));
159: return buf.toString();
160: }
161:
162: //
163: // PRIVATE
164: //
165:
166: /**
167: * Method declaration
168: *
169: *
170: * @exception Exception
171: */
172: private void jbInit() throws Exception {
173: textRoot = (JTextField) Beans.instantiate(getClass()
174: .getClassLoader(), JTextField.class.getName());
175: panelRoot = (JPanel) Beans.instantiate(getClass()
176: .getClassLoader(), JPanel.class.getName());
177: layoutRoot = (GridBagLayout) Beans.instantiate(getClass()
178: .getClassLoader(), GridBagLayout.class.getName());
179: buttonRoot = (JButton) Beans.instantiate(getClass()
180: .getClassLoader(), JButton.class.getName());
181: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
182: .getClassLoader(), GridBagLayout.class.getName());
183: panelFiller = (JPanel) Beans.instantiate(getClass()
184: .getClassLoader(), JPanel.class.getName());
185: buttonRoot.setText("..."); // nores
186: panelRoot.setLayout(layoutRoot);
187: panelRoot.add(textRoot, new GridBagConstraints(0, 0, 1, 1, 0.1,
188: 0.1, GridBagConstraints.WEST,
189: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
190: 0, 0));
191: panelRoot
192: .add(buttonRoot, new GridBagConstraints(1, 0, 1, 2,
193: 0.0, 0.0, GridBagConstraints.CENTER,
194: GridBagConstraints.NONE,
195: new Insets(5, 5, 5, 20), 0, 0));
196: this .setLayout(layoutMain);
197: this .add(panelRoot, new GridBagConstraints(0, 0, 1, 1, 0.1,
198: 0.1, GridBagConstraints.CENTER,
199: GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
200: }
201:
202: /**
203: */
204: private void pmInit() {
205: Border border = BorderFactory.createEtchedBorder();
206:
207: borderRoot = BorderFactory.createTitledBorder(border);
208: borderRoot.setTitle(res.getString("borderRoot_Title"));
209: panelRoot.setBorder(borderRoot);
210: buttonListener = new LocalButtonListener();
211: buttonRoot.addActionListener(buttonListener);
212: textRoot.setText(new String());
213: }
214:
215: /**
216: */
217: private void browseForDirectory() {
218: File dir = null;
219:
220: dir = SwingUtil.getDirectoryChoice(this , textRoot.getText(),
221: res.getString("Choose_the_project"));
222: if (dir != null) {
223: textRoot.setText(PathHandle.createPathString(dir));
224: }
225: }
226:
227: /**
228: */
229: private class LocalButtonListener implements ActionListener {
230: public void actionPerformed(ActionEvent event) {
231: browseForDirectory();
232: }
233:
234: }
235: }
|