📄 connectionpanel.java
字号:
/* * ConnectionPanel.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.executequery.gui.browser;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.sql.Connection;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.table.AbstractTableModel;import org.executequery.ConnectionProperties;import org.executequery.Constants;import org.executequery.GUIUtilities;import org.executequery.JDBCProperties;import org.executequery.SystemUtilities;import org.executequery.ValidationException;import org.underworldlabs.swing.actions.ActionUtilities;import org.executequery.databasemediators.DatabaseConnection;import org.executequery.databasemediators.DatabaseDriver;import org.executequery.datasource.ConnectionManager;import org.underworldlabs.jdbc.DataSourceException;import org.underworldlabs.swing.ActionPanel;import org.underworldlabs.swing.DynamicComboBoxModel;import org.underworldlabs.swing.NumberTextField;import org.executequery.components.TextFieldPanel;import org.executequery.gui.DefaultTable;import org.underworldlabs.swing.GUIUtils;import org.underworldlabs.util.MiscUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author Takis Diakoumis * @version $Revision: 1.10 $ * @date $Date: 2006/09/21 13:31:24 $ */public class ConnectionPanel extends ActionPanel implements FocusListener { //implements ConnectionFunction { // ------------------------------- // text fields and combos private JComboBox driverCombo; private JCheckBox encryptPwdCheck; private JCheckBox savePwdCheck; private JTextField nameField; private JTextField userField; private JPasswordField passwordField; private JTextField hostField; private NumberTextField portField; private JTextField sourceField; private JTextField urlField; private JLabel statusLabel; private JComboBox txCombo; private JButton txApplyButton; // ------------------------------- /** table model for jdbc properties key/values */ private JdbcPropertiesTableModel model; /** connect button */ private JButton connectButton; /** disconnect button */ private JButton disconnectButton; /** the saved jdbc drivers */ private Vector jdbcDrivers; /** any advanced property keys/values */ private String[][] advancedProperties; /** the tab basic/advanced tab pane */ private JTabbedPane tabPane; /** the connection properties displayed */ private DatabaseConnection databaseConnection; /** the selected meta object representing this connection */ private ConnectionObject metaObject; /** the browser's control object */ private BrowserController controller; /** Creates a new instance of ConnectionPanel */ public ConnectionPanel(BrowserController controller) { super(new BorderLayout()); this.controller = controller; init(); } private void init() { // --------------------------------- // create the basic props panel // initialise the fields nameField = new JTextField(); passwordField = new JPasswordField(); hostField = new JTextField(); portField = new NumberTextField(); sourceField = new JTextField(); userField = new JTextField(); urlField = new JTextField(); nameField.addFocusListener(this); savePwdCheck = ActionUtilities.createCheckBox("Store Password", "setStorePassword"); encryptPwdCheck = ActionUtilities.createCheckBox("Encrypt Password", "setEncryptPassword"); savePwdCheck.addActionListener(this); encryptPwdCheck.addActionListener(this); // retrieve the drivers buildDriversList(); // --------------------------------- // add the basic connection fields TextFieldPanel mainPanel = new TextFieldPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(10,10,5,10); gbc.gridy = 0; gbc.gridx = 0; statusLabel = new JLabel(); addLabelFieldPair(mainPanel, "Status:", statusLabel, "Current connection status", gbc); addLabelFieldPair(mainPanel, "Connection Name:", nameField, "A friendly name for this connection", gbc); addLabelFieldPair(mainPanel, "User Name:", userField, "Login user name", gbc); addLabelFieldPair(mainPanel, "Password:", passwordField, "Login password", gbc); addComponents(mainPanel, savePwdCheck, "Store the password with the connection information", encryptPwdCheck, "Encrypt the password when saving", gbc); addLabelFieldPair(mainPanel, "Host Name:", hostField, "Server host name or IP address", gbc); addLabelFieldPair(mainPanel, "Port:", portField, "Database port number", gbc); addLabelFieldPair(mainPanel, "Data Source:", sourceField, "Data source name", gbc); addLabelFieldPair(mainPanel, "JDBC URL:", urlField, "The full JDBC URL for this connection (optional)", gbc); addLabelFieldPair(mainPanel, "JDBC Driver:", driverCombo, "The JDBC driver for this database", gbc); connectButton = ActionUtilities.createButton("Connect", "connect"); disconnectButton = ActionUtilities.createButton("Disconnect", "disconnect"); connectButton.setPreferredSize(Constants.FORM_BUTTON_SIZE); disconnectButton.setPreferredSize(Constants.FORM_BUTTON_SIZE); Insets buttonInsets = new Insets(1,4,1,4); connectButton.setMargin(buttonInsets); disconnectButton.setMargin(buttonInsets); connectButton.addActionListener(this); disconnectButton.addActionListener(this); gbc.gridy++; gbc.gridx = 1; gbc.insets.top = 0; gbc.insets.left = 0; gbc.insets.right = 10; gbc.gridwidth = 1; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.anchor = GridBagConstraints.NORTHEAST; gbc.fill = GridBagConstraints.NONE; mainPanel.add(connectButton, gbc); gbc.gridx++; gbc.weightx = 0; mainPanel.add(disconnectButton, gbc); // --------------------------------- // create the advanced panel model = new JdbcPropertiesTableModel(); JTable table = new DefaultTable(model); table.getTableHeader().setReorderingAllowed(false); JScrollPane scroller = new JScrollPane(table); //scroller.setPreferredSize(new Dimension(200, 300)); // advanced jdbc properties JPanel advPropsPanel = new JPanel(new GridBagLayout()); advPropsPanel.setBorder(BorderFactory.createTitledBorder("JDBC Properties")); gbc.gridx = 0; gbc.gridy = 0; gbc.insets.top = 0; gbc.insets.left = 10; gbc.insets.right = 10; gbc.weighty = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTHWEST; advPropsPanel.add( new JLabel("Enter any key/value pair properties for this connection"), gbc); gbc.gridy++; advPropsPanel.add( new JLabel("Refer to the relevant JDBC driver documentation for possible entries"), gbc); gbc.gridy++; gbc.insets.bottom = 10; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; advPropsPanel.add(scroller, gbc); // transaction isolation txApplyButton = ActionUtilities.createButton("Apply", "transactionLevelChanged"); txApplyButton.setToolTipText("Apply this level to all open connections of this type"); txApplyButton.setEnabled(false); txApplyButton.addActionListener(this); // add a dummy select value to the tx levels String[] txLevels = new String[Constants.TRANSACTION_LEVELS.length + 1]; txLevels[0] = "Database Default"; for (int i = 1; i < txLevels.length; i++) { txLevels[i] = Constants.TRANSACTION_LEVELS[i - 1]; } txCombo = new JComboBox(txLevels); JPanel advTxPanel = new JPanel(new GridBagLayout()); advTxPanel.setBorder(BorderFactory.createTitledBorder("Transaction Isolation")); gbc.gridx = 0; gbc.gridy = 0; gbc.insets.top = 0; gbc.insets.left = 10; gbc.insets.right = 10; gbc.insets.bottom = 5; gbc.weighty = 0; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHWEST; advTxPanel.add( new JLabel("Default transaction isolation level for this connection"), gbc); gbc.gridy++; gbc.insets.bottom = 10; advTxPanel.add( new JLabel("Note: the selected isolation level " + "will apply to ALL open connections of this type."), gbc); gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 1; gbc.insets.top = 0; gbc.insets.left = 10; gbc.weightx = 0; advTxPanel.add(new JLabel("Isolation Level:"), gbc); gbc.gridx = 1; gbc.insets.left = 5; gbc.weightx = 1.0; gbc.insets.right = 5; gbc.fill = GridBagConstraints.BOTH; advTxPanel.add(txCombo, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.insets.left = 0; gbc.insets.right = 10; advTxPanel.add(txApplyButton, gbc); JPanel advancedPanel = new JPanel(new BorderLayout()); advancedPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); advancedPanel.add(advPropsPanel, BorderLayout.CENTER);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -