001: /*
002: * Created on Jul 20, 2005
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.enhydra.base.tool;
008:
009: import java.awt.event.ActionEvent;
010: import java.awt.event.ActionListener;
011:
012: import javax.swing.JPanel;
013:
014: import javax.swing.AbstractAction;
015: import javax.swing.JCheckBox;
016: import javax.swing.JFileChooser;
017: import javax.swing.JLabel;
018: import javax.swing.JOptionPane;
019: import javax.swing.JTextField;
020: import javax.swing.JButton;
021:
022: /**
023: * @author slobodan
024: *
025: * TODO To change the template for this generated type comment go to Window -
026: * Preferences - Java - Code Style - Code Templates
027: */
028: public class EnhydraBasePanel extends JPanel {
029:
030: private JCheckBox createNew = null;
031:
032: private JLabel jLabel = null;
033:
034: private JLabel serviceLabel = null;
035:
036: private JTextField serviceText = null;
037:
038: private JLabel pathLabel = null;
039:
040: private JTextField pathText = null;
041:
042: private JButton browseButton = null;
043:
044: private JLabel jLabel2 = null;
045:
046: private JLabel jLabel1 = null;
047:
048: /**
049: * This is the default constructor
050: */
051: public EnhydraBasePanel() {
052: super ();
053: initialize();
054: }
055:
056: /**
057: * This method initializes this
058: *
059: * @return void
060: */
061: private void initialize() {
062: jLabel1 = new JLabel();
063: serviceLabel = new JLabel();
064: jLabel2 = new JLabel();
065: pathLabel = new JLabel();
066: jLabel = new JLabel();
067: this .setPreferredSize(new java.awt.Dimension(300, 150));
068: this .setSize(300, 150);
069: jLabel.setText("");
070: jLabel.setPreferredSize(new java.awt.Dimension(300, 16));
071: serviceLabel.setText("Service Name:");
072: serviceLabel.setName("serviceLabel");
073: serviceLabel.setEnabled(false);
074: pathLabel.setText("Path to Enhydra Base Directory:");
075: pathLabel.setEnabled(false);
076: pathLabel.setName("pathLabel");
077: pathLabel.setPreferredSize(new java.awt.Dimension(281, 16));
078: jLabel2.setText("");
079: jLabel2.setPreferredSize(new java.awt.Dimension(80, 10));
080: jLabel1.setText("");
081: jLabel1.setPreferredSize(new java.awt.Dimension(300, 5));
082: this .add(getCreateNew(), null);
083: this .add(jLabel, null);
084: this .add(serviceLabel, null);
085: this .add(getServiceText(), null);
086: this .add(jLabel2, null);
087: this .add(jLabel1, null);
088: this .add(pathLabel, null);
089: this .add(getPathText(), null);
090: this .add(getBrowseButton(), null);
091: }
092:
093: /**
094: * This method initializes jCheckBox
095: *
096: * @return javax.swing.JCheckBox
097: */
098: private JCheckBox getCreateNew() {
099: if (createNew == null) {
100: createNew = new JCheckBox();
101: createNew.setSelected(false);
102: createNew.setName("createNew");
103: createNew.setText("Create New Enhydra Base Directory");
104: createNew.setPreferredSize(new java.awt.Dimension(300, 24));
105: createNew.addActionListener(new CustomActionListener());
106: }
107: return createNew;
108: }
109:
110: /**
111: * This method initializes jTextField
112: *
113: * @return javax.swing.JTextField
114: */
115: private JTextField getServiceText() {
116: if (serviceText == null) {
117: serviceText = new JTextField();
118: serviceText.setName("serviceText");
119: serviceText
120: .setPreferredSize(new java.awt.Dimension(110, 20));
121: serviceText.setEnabled(false);
122: }
123: return serviceText;
124: }
125:
126: /**
127: * This method initializes jTextField
128: *
129: * @return javax.swing.JTextField
130: */
131: private JTextField getPathText() {
132: if (pathText == null) {
133: pathText = new JTextField();
134: pathText.setPreferredSize(new java.awt.Dimension(196, 20));
135: pathText.setEnabled(false);
136: pathText.setName("pathText");
137: }
138: return pathText;
139: }
140:
141: /**
142: * This method initializes jButton
143: *
144: * @return javax.swing.JButton
145: */
146: private JButton getBrowseButton() {
147: if (browseButton == null) {
148: browseButton = new JButton();
149: browseButton.setText("Browse");
150: browseButton.setEnabled(false);
151: browseButton.setName("browseButton");
152: browseButton
153: .setPreferredSize(new java.awt.Dimension(80, 26));
154: browseButton.addActionListener(new CustomActionListener());
155: }
156: return browseButton;
157: }
158:
159: public void setServiceName(String name) {
160: getServiceText().setText(name);
161: }
162:
163: public String getServiceName() {
164: return getServiceText().getText();
165: }
166:
167: public void setBasePath(String path) {
168: getPathText().setText(path);
169: }
170:
171: public String getBasePath() {
172: return getPathText().getText();
173: }
174:
175: public void setBaseChecked(boolean selected) {
176: getCreateNew().setSelected(selected);
177:
178: serviceLabel.setEnabled(getCreateNew().isSelected());
179: serviceText.setEnabled(getCreateNew().isSelected());
180: pathLabel.setEnabled(getCreateNew().isSelected());
181: pathText.setEnabled(getCreateNew().isSelected());
182: browseButton.setEnabled(getCreateNew().isSelected());
183: }
184:
185: public boolean getBaseChecked() {
186: return getCreateNew().isSelected();
187: }
188:
189: private class CustomAction extends AbstractAction {
190: public void actionPerformed(ActionEvent ae) {
191: String command = ae.getActionCommand();
192: if ("Create New Enhydra Base Directory".equals(command)) {
193: serviceLabel.setEnabled(getCreateNew().isSelected());
194: serviceText.setEnabled(getCreateNew().isSelected());
195: pathLabel.setEnabled(getCreateNew().isSelected());
196: pathText.setEnabled(getCreateNew().isSelected());
197: browseButton.setEnabled(getCreateNew().isSelected());
198: } else if ("Browse".equals(command)) {
199: JFileChooser chooser = new JFileChooser();
200: chooser.setDialogTitle("Choose Enhydra Base Path!!!");
201: chooser.setFileSelectionMode(chooser.DIRECTORIES_ONLY);
202: int returnVal = chooser.showOpenDialog(null);
203: if (returnVal == JFileChooser.APPROVE_OPTION) {
204: pathText.setText(chooser.getSelectedFile()
205: .getAbsolutePath());
206: }
207: }
208: }
209: }
210:
211: private class CustomActionListener implements ActionListener {
212:
213: protected AbstractAction action;
214:
215: public CustomActionListener() {
216: action = new CustomAction();
217: }
218:
219: public void actionPerformed(ActionEvent e) {
220: action.actionPerformed(e);
221: }
222: }
223:
224: public boolean checkEntries() {
225: boolean valid = true;
226: if (createNew.isSelected()) {
227: if ("".equals(serviceText.getText())
228: || serviceText.getText() == null) {
229: displayErrorMessage("Service Name");
230: valid = false;
231: } else {
232: serviceText.setText(serviceText.getText().replace(' ',
233: '_'));
234: }
235:
236: if ("".equals(pathText.getText())
237: || pathText.getText() == null) {
238: displayErrorMessage("Path to Enhydra Base Directory");
239: valid = false;
240: }
241: }
242: return valid;
243: }
244:
245: private void displayErrorMessage(String field) {
246: JOptionPane
247: .showMessageDialog(
248: null,
249: "Check '" + field + "' Field Setting!",
250: "Enhydra Configuration Tool - Houston, we have a problem!",
251: JOptionPane.ERROR_MESSAGE);
252: }
253:
254: }
|