📄 createtablefunctionpanel.java
字号:
/* * CreateTableFunctionPanel.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.table;import java.awt.BorderLayout;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTabbedPane;import javax.swing.JTextField;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import org.executequery.GUIUtilities;import org.underworldlabs.swing.DynamicComboBoxModel;import org.executequery.databasemediators.*;import org.executequery.datasource.ConnectionManager;import org.executequery.gui.FocusComponentPanel;import org.executequery.gui.browser.*;import org.executequery.gui.text.TextEditor;import org.executequery.gui.text.SimpleSqlTextPanel;import org.executequery.gui.text.TextEditorContainer;import org.underworldlabs.jdbc.DataSourceException;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. * ---------------------------------------------------------- *//** * The Create Table base panel. * * @author Takis Diakoumis * @version $Revision: 1.8 $ * @date $Date: 2006/07/16 06:47:12 $ */public abstract class CreateTableFunctionPanel extends JPanel implements FocusComponentPanel, ItemListener, ChangeListener, TableModifier, TableConstraintFunction, TextEditorContainer { /** The table name field */ protected JTextField nameField; /** The schema combo box */ protected JComboBox schemaCombo; /** the schema combo box model */ protected DynamicComboBoxModel schemaModel; /** The connection combo selection */ protected JComboBox connectionsCombo; /** the schema combo box model */ protected DynamicComboBoxModel connectionsModel; /** The table column definition panel */ protected NewTablePanel tablePanel; /** The table constraints panel */ protected NewTableConstraintsPanel consPanel; /** The text pane showing SQL generated */ protected SimpleSqlTextPanel sqlText; /** The tabbed pane containing definition and constraints */ private JTabbedPane tableTabs; /** The buffer off all SQL generated */ protected StringBuffer sqlBuffer; /** The tool bar */ private CreateTableToolBar tools; /** Utility to retrieve database meta data */ protected MetaDataValues metaData; /** The base panel */ protected JPanel mainPanel; /** <p> Constructs a new instance. */ public CreateTableFunctionPanel() { super(new BorderLayout()); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } /** <p>Initializes the state of this instance. */ private void jbInit() throws Exception { nameField = new JTextField(); //initialise the schema label metaData = new MetaDataValues(true); // combo boxes Vector connections = ConnectionManager.getActiveConnections(); connectionsModel = new DynamicComboBoxModel(connections); connectionsCombo = new JComboBox(connectionsModel); connectionsCombo.addItemListener(this); schemaModel = new DynamicComboBoxModel(); schemaCombo = new JComboBox(schemaModel); schemaCombo.addItemListener(this); // create tab pane tableTabs = new JTabbedPane(); // create the column definition panel // and add this to the tabbed pane tablePanel = new NewTablePanel(this); tableTabs.add("Columns", tablePanel); // create the constraints table and model JPanel constraintsPanel = new JPanel(new GridBagLayout()); consPanel = new NewTableConstraintsPanel(this); consPanel.setData(new Vector(0), true); constraintsPanel.add(consPanel, new GridBagConstraints( 1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0)); tableTabs.add("Constraints", constraintsPanel); sqlText = new SimpleSqlTextPanel(); tools = new CreateTableToolBar(this); mainPanel = new JPanel(new GridBagLayout()); mainPanel.setBorder(BorderFactory.createEtchedBorder()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(7,5,5,5); gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; mainPanel.add(new JLabel("Connection:"), gbc); gbc.gridx = 2; gbc.weightx = 1.0; gbc.gridwidth = 1; gbc.insets.left = 0; gbc.insets.top = 5; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(connectionsCombo, gbc); gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 2; gbc.insets.top = 0; gbc.insets.left = 5; gbc.weightx = 0; gbc.fill = GridBagConstraints.NONE; mainPanel.add(new JLabel("Schema:"), gbc); gbc.gridx = 2; gbc.weightx = 1.0; gbc.gridwidth = 1; gbc.insets.left = 0; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(schemaCombo, gbc); gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 2; gbc.insets.left = 5; gbc.weightx = 0; gbc.fill = GridBagConstraints.NONE; mainPanel.add(new JLabel("Table Name:"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridx = 2; gbc.weightx = 1.0; gbc.insets.left = 0; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(nameField, gbc); gbc.gridwidth = 1; gbc.gridx = 0; gbc.gridy++; gbc.weightx = 0; gbc.insets.right = 0; gbc.insets.left = 5; gbc.insets.top = 20; gbc.fill = GridBagConstraints.VERTICAL; mainPanel.add(tools, gbc); gbc.insets.left = 0; gbc.insets.right = 5; gbc.insets.top = 0; gbc.gridx = 1; gbc.weighty = 0.4; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; mainPanel.add(tableTabs, gbc); gbc.gridx = 0; gbc.gridy++; gbc.weighty = 0.6; gbc.insets.left = 5; gbc.insets.bottom = 5; gbc.insets.top = 10; mainPanel.add(sqlText, gbc); setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); add(mainPanel, BorderLayout.CENTER); tableTabs.addChangeListener(this); nameField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(KeyEvent e) { setSQLText(); } }); sqlBuffer = new StringBuffer(CreateTableSQLSyntax.CREATE_TABLE); // check initial values for possible value inits if (connections == null || connections.isEmpty()) { schemaCombo.setEnabled(false); connectionsCombo.setEnabled(false); } else { DatabaseConnection connection = (DatabaseConnection)connections.elementAt(0); metaData.setDatabaseConnection(connection); Vector schemas = metaData.getHostedSchemasVector(); if (schemas == null || schemas.size() == 0) { schemas = metaData.getHostedCatalogsVector(); } schemaModel.setElements(schemas); schemaCombo.setSelectedIndex(0); tablePanel.setDataTypes(metaData.getDataTypesArray()); } } /** * Returns the selected connection from the panel's * connections combo selection box. * * @return the selected connection properties object */ public DatabaseConnection getSelectedConnection() { return (DatabaseConnection)connectionsCombo.getSelectedItem(); } /** * Returns the table name field. */ public Component getDefaultFocusComponent() { return nameField; } /** * Invoked when an item has been selected or deselected by the user. * The code written for this method performs the operations * that need to occur when an item is selected (or deselected). */ public void itemStateChanged(ItemEvent event) { // interested in selections only if (event.getStateChange() == ItemEvent.DESELECTED) { return; } final Object source = event.getSource(); GUIUtils.startWorker(new Runnable() { public void run() { try { setInProcess(true); if (source == connectionsCombo) { connectionChanged(); } else if (source == schemaCombo) { setSQLText(); } } finally { setInProcess(false); } } }); } private void connectionChanged() { // retrieve connection selection DatabaseConnection connection = (DatabaseConnection)connectionsCombo.getSelectedItem(); // reset meta data metaData.setDatabaseConnection(connection); // reset schema values
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -