001: /* ====================================================================
002: * The QueryForm License, Version 1.1
003: *
004: * Copyright (c) 1998 - 2003 David F. Glasser. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by
022: * David F. Glasser."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "QueryForm" and "David F. Glasser" must
027: * not be used to endorse or promote products derived from this
028: * software without prior written permission. For written
029: * permission, please contact dglasser@pobox.com.
030: *
031: * 5. Products derived from this software may not be called "QueryForm",
032: * nor may "QueryForm" appear in their name, without prior written
033: * permission of David F. Glasser.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL DAVID F. GLASSER, THE APACHE SOFTWARE
039: * FOUNDATION OR ITS CONTRIBUTORS, OR ANY AUTHORS OR DISTRIBUTORS
040: * OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This product includes software developed by the
051: * Apache Software Foundation (http://www.apache.org/).
052: *
053: * ====================================================================
054: *
055: * $Source: /cvsroot/qform/qform/src/org/glasser/swing/LocalDataSourceConfigPanel.java,v $
056: * $Revision: 1.2 $
057: * $Author: dglasser $
058: * $Date: 2003/08/23 16:15:31 $
059: *
060: * --------------------------------------------------------------------
061: */
062: package org.glasser.swing;
063:
064: import java.awt.*;
065: import java.util.*;
066: import javax.swing.*;
067:
068: import org.glasser.sql.*;
069: import org.glasser.swing.text.*;
070: import org.glasser.util.*;
071:
072: public class LocalDataSourceConfigPanel extends JPanel {
073:
074: public final JTextField txtDisplayName = new JTextField();
075:
076: public final DriverClassSelector cmbDriverClass = new DriverClassSelector();
077:
078: public final JTextField txtUrl = new JTextField();
079:
080: public final JCheckBox chkLoginRequired = new JCheckBox();
081:
082: public final JTextField txtUserName = new JTextField();
083:
084: public final JPasswordField txtPassword = new JPasswordField();
085:
086: public final JTextField txtMaxConnections = new JTextField();
087:
088: public final JTextField txtLoginTimeout = new JTextField();
089:
090: public Object[][] config = {
091: { txtDisplayName, "Display Name",
092: "Name for this connection." },
093: {
094: cmbDriverClass,
095: "Driver Class",
096: "The fully-qualified class name for the JDBC driver to be used. (Enter it manually if it does not appear in the dropdown.)" },
097: { txtUrl, "Database URL",
098: "The URL that will be used to connect to this data source." },
099: { chkLoginRequired, "Requires Login",
100: "Indicates if a user/password is needed to connect to this data source." },
101: {
102: txtUserName,
103: "User Name",
104: "If required, the user name used to connect to this data source. (Leave blank to prompt for user name.)" },
105: {
106: txtPassword,
107: "Password",
108: "If required, the password used to connect to this data source. (Leave blank to prompt for password.)" },
109: {
110: txtMaxConnections,
111: "Max Connections",
112: "The maximum number of connections that will be pooled. (Enter 0 or leave blank for no maximum.)" },
113: {
114: txtLoginTimeout,
115: "Login Timeout",
116: "The maximum time, in seconds, to wait for a successful login to this data source. (Enter 0 or leave blank for no maximum.)" } };
117:
118: public LocalDataSourceConfigPanel() {
119:
120: GUIHelper.buildFormPanel(this , config, 250, 6, null,
121: Color.black, false, -1);
122:
123: // make txtMaxConnections and txtLoginTimeout numeric-input only.
124: NumericDocument nd = new NumericDocument();
125: nd.setMinValue(0);
126: nd.setMaxValue(Integer.MAX_VALUE);
127: txtMaxConnections.setDocument(nd);
128:
129: nd = new NumericDocument();
130: nd.setMinValue(0);
131: nd.setMaxValue(Integer.MAX_VALUE);
132: txtLoginTimeout.setDocument(nd);
133:
134: }
135:
136: public void setEditable(boolean b) {
137:
138: txtDisplayName.setEditable(b);
139: cmbDriverClass.setEnabled(b);
140: txtUrl.setEditable(b);
141: chkLoginRequired.setEnabled(b);
142: txtUserName.setEditable(b);
143: txtPassword.setEditable(b);
144: txtMaxConnections.setEditable(b);
145: txtLoginTimeout.setEditable(b);
146:
147: }
148:
149: public void displayObject(LocalDataSourceConfig config) {
150:
151: txtDisplayName.setText(config.getDisplayName());
152:
153: String driverClass = config.getDriverClassName();
154: if (driverClass == null
155: || (driverClass = driverClass.trim()).length() == 0) {
156: driverClass = DriverClassSelector.EMPTY_ITEM;
157: }
158: boolean cmbState = cmbDriverClass.isEditable();
159: cmbDriverClass.setEditable(true);
160: cmbDriverClass.setSelectedItem(driverClass);
161: cmbDriverClass.setEditable(cmbState);
162:
163: txtUrl.setText(config.getUrl());
164: chkLoginRequired.setSelected(config.isLoginRequired());
165: txtUserName.setText(config.getUser());
166: txtPassword.setText(config.getPassword());
167:
168: Integer maxConnections = config.getMaxConnections();
169: String s = maxConnections == null ? null : maxConnections
170: .toString();
171: txtMaxConnections.setText(s);
172:
173: Integer loginTimeout = config.getLoginTimeout();
174: s = loginTimeout == null ? null : loginTimeout.toString();
175: txtLoginTimeout.setText(s);
176:
177: }
178:
179: public void clearFields() {
180: txtDisplayName.setText(null);
181: cmbDriverClass.setSelectedItem(cmbDriverClass.EMPTY_ITEM);
182: txtUrl.setText(null);
183: chkLoginRequired.setSelected(false);
184: txtUserName.setText(null);
185: txtPassword.setText(null);
186: txtMaxConnections.setText(null);
187: txtLoginTimeout.setText(null);
188: }
189:
190: public void updateObject(LocalDataSourceConfig config) {
191:
192: config
193: .setDisplayName(Util.trimToNull(txtDisplayName
194: .getText()));
195: config.setDriverClassName(Util
196: .trimToNull((String) cmbDriverClass.getSelectedItem()));
197: config.setUrl(Util.trimToNull(txtUrl.getText()));
198: config.setLoginRequired(chkLoginRequired.isSelected());
199:
200: config.setUser(Util.trimToNull(txtUserName.getText()));
201: config.setPassword(Util.trimToNull(txtPassword.getText()));
202:
203: String s = Util.trimToNull(txtMaxConnections.getText());
204: if (s != null)
205: config.setMaxConnections(new Integer(s));
206: else
207: config.setMaxConnections(null);
208:
209: s = Util.trimToNull(txtLoginTimeout.getText());
210: if (s != null)
211: config.setLoginTimeout(new Integer(s));
212: else
213: config.setLoginTimeout(null);
214: }
215:
216: }
|