⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionpanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * check box is selected.     */    public void setStorePassword() {        boolean store = savePwdCheck.isSelected();        encryptPwdCheck.setEnabled(store);    }        /**     * Sets the values for the tx level on the connection object     * based on the tx level in the tx combo.     */    private void getTransactionIsolationLevel() {        int index = txCombo.getSelectedIndex();        if (index == 0) {            databaseConnection.setTransactionIsolation(-1);            return;        }        int isolationLevel = -1;        switch (index) {            case 1:                isolationLevel = Connection.TRANSACTION_NONE;                break;            case 2:                isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;                break;            case 3:                isolationLevel = Connection.TRANSACTION_READ_COMMITTED;                break;            case 4:                isolationLevel = Connection.TRANSACTION_REPEATABLE_READ;                break;            case 5:                isolationLevel = Connection.TRANSACTION_SERIALIZABLE;                break;        }                databaseConnection.setTransactionIsolation(isolationLevel);    }    /**     * Sets the values for the tx level on the tx combo     * based on the tx level in the connection object.     */    private void setTransactionIsolationLevel() {        int index = 0;        int isolationLevel = databaseConnection.getTransactionIsolation();        switch (isolationLevel) {            case Connection.TRANSACTION_NONE:                index = 1;                break;            case Connection.TRANSACTION_READ_UNCOMMITTED:                index = 2;                break;            case Connection.TRANSACTION_READ_COMMITTED:                index = 3;                break;            case Connection.TRANSACTION_REPEATABLE_READ:                index = 4;                break;            case Connection.TRANSACTION_SERIALIZABLE:                index = 5;                break;        }        txCombo.setSelectedIndex(index);    }        /**     * Selects the driver for the current connection.     */    private void selectDriver() {        if (databaseConnection == null) {            return;        }        if (databaseConnection.getDriverId() == 0) {            driverCombo.setSelectedIndex(0);        } else {            long driverId = databaseConnection.getDriverId();            if (driverId != 0) {                DatabaseDriver driver = JDBCProperties.getDatabaseDriver(driverId);                if (driver != null) {                    driverCombo.setSelectedItem(driver.getName());                }            }        }    }        /**     * Populates the values of the fields with the values of     * the specified connection.     */    private void populateConnectionFields(DatabaseConnection databaseConnection) {        // assign as the current connection        this.databaseConnection = databaseConnection;        // rebuild the driver list        buildDriversList();                // populate the field values/selections        savePwdCheck.setSelected(databaseConnection.isPasswordStored());        encryptPwdCheck.setSelected(databaseConnection.isPasswordEncrypted());        nameField.setText(databaseConnection.getName());        userField.setText(databaseConnection.getUserName());        passwordField.setText(databaseConnection.getUnencryptedPassword());        hostField.setText(databaseConnection.getHost());        portField.setText(databaseConnection.getPort());        sourceField.setText(databaseConnection.getSourceName());        urlField.setText(databaseConnection.getURL());        // set the correct driver selected        selectDriver();        // set the jdbc properties        setJdbcProperties();                // the tx level        setTransactionIsolationLevel();                // enable/disable fields        enableFields(databaseConnection.isConnected());    }        /** Indicates whether a new connection is about to be set */    private boolean changePending;        /**     * Populates the values of the selected connection     * properties bject with the field values.     */    private void populateConnectionObject() {        databaseConnection.setPasswordStored(savePwdCheck.isSelected());        databaseConnection.setPasswordEncrypted(encryptPwdCheck.isSelected());        databaseConnection.setUserName(userField.getText());        databaseConnection.setPassword(                MiscUtils.charsToString(passwordField.getPassword()));        databaseConnection.setHost(hostField.getText());        databaseConnection.setPort(portField.getText());        databaseConnection.setSourceName(sourceField.getText());        databaseConnection.setURL(urlField.getText());        // jdbc driver selection        int driverIndex = driverCombo.getSelectedIndex();        if (driverIndex > 0) {            DatabaseDriver driver = (DatabaseDriver)                                jdbcDrivers.elementAt(driverIndex - 1);            databaseConnection.setJDBCDriver(driver);            databaseConnection.setDriverName(driver.getName());            databaseConnection.setDriverId(driver.getId());            databaseConnection.setDatabaseType(Integer.toString(driver.getType()));        }        else {            databaseConnection.setDriverId(0);            databaseConnection.setJDBCDriver(null);            databaseConnection.setDriverName(null);            databaseConnection.setDatabaseType(null);        }                // retrieve the jdbc properties        storeJdbcProperties();        // set the tx level on the connection props object        getTransactionIsolationLevel();                // check if the name has to update the tree display        checkNameUpdate();    }        /**     * Sets the connection fields on this panel to the     * values as held within the specified connection     * properties object.     *     * @param the connection to set the fields to     */    public void setConnectionValue(ConnectionObject metaObject) {        connectButton.setEnabled(false);        disconnectButton.setEnabled(false);        changePending = true;        if (databaseConnection != null) {            populateConnectionObject();        }        this.metaObject = metaObject;        populateConnectionFields(metaObject.getDatabaseConnection());        // set the focus field        nameField.requestFocusInWindow();        nameField.selectAll();        // queue a save        save();        changePending = false;    }        private void save() {        GUIUtils.startWorker(new Runnable() {            public void run() {                saveConnections();            }        });    }        /**     * Forces a repaint using paintImmediately(...) on the     * connection status label.     */    private void paintStatusLabel() {        Runnable update = new Runnable() {            public void run() {                Dimension dim = statusLabel.getSize();                statusLabel.paintImmediately(0, 0, dim.width, dim.height);            }        };        SwingUtilities.invokeLater(update);    }        private class JdbcPropertiesTableModel extends AbstractTableModel {                protected String[] header = {"Name", "Value"};                public JdbcPropertiesTableModel() {            advancedProperties = new String[20][2];        }                public int getColumnCount() {            return 2;        }                public int getRowCount() {            return advancedProperties.length;        }                public Object getValueAt(int row, int col) {            return advancedProperties[row][col];        }                public void setValueAt(Object value, int row, int col) {            advancedProperties[row][col] = (String)value;            fireTableRowsUpdated(row, row);        }                public boolean isCellEditable(int row, int col) {            return true;        }                public String getColumnName(int col) {            return header[col];        }                public Class getColumnClass(int col) {            return String.class;        }            } // AdvConnTableModel    private void addComponents(JPanel panel,                                JComponent field1, String toolTip1,                               JComponent field2, String toolTip2,                               GridBagConstraints gbc) {                gbc.gridy++;        gbc.gridx = 0;        gbc.gridwidth = 1;        gbc.insets.top = 0;        gbc.insets.left = 10;        gbc.weightx = 0;        panel.add(field1, gbc);        field1.setToolTipText(toolTip1);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.gridx = 1;        gbc.insets.left = 10;        gbc.weightx = 1.0;        panel.add(field2, gbc);        field2.setToolTipText(toolTip2);    }    private void addComponent(JPanel panel, JComponent field, String toolTip,                              GridBagConstraints gbc) {        gbc.gridy++;        gbc.gridx = 0;        gbc.insets.top = 0;        gbc.insets.left = 10;        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        panel.add(field, gbc);        if (toolTip != null) {            field.setToolTipText(toolTip);        }    }    private void addLabelFieldPair(JPanel panel, String label,                                         JComponent field, String toolTip,                                        GridBagConstraints gbc) {        gbc.gridy++;        gbc.gridx = 0;        gbc.gridwidth = 1;        if (panel.getComponentCount() > 0) {            gbc.insets.top = 0;        } else {            gbc.insets.top = 10;        }        gbc.insets.left = 10;        gbc.weightx = 0;        panel.add(new JLabel(label), gbc);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.gridx = 1;        gbc.insets.left = 5;        gbc.weightx = 1.0;        panel.add(field, gbc);                if (toolTip != null) {            field.setToolTipText(toolTip);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -