📄 erdedittabledialog.java
字号:
/* * ErdEditTableDialog.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.erd;import java.awt.Container;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.*;import javax.swing.JTable;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import org.executequery.Constants;import org.executequery.databasemediators.MetaDataValues;import org.executequery.gui.table.*;import org.executequery.gui.browser.ColumnConstraint;import org.executequery.gui.browser.ColumnData;import org.underworldlabs.swing.table.ComboBoxCellEditor;import org.underworldlabs.swing.DisabledField;/* ---------------------------------------------------------- * 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.4 $ * @date $Date: 2006/05/14 06:56:52 $ */public class ErdEditTableDialog extends ErdPrintableDialog implements TableFunction, TableConstraintFunction { /** The ERD parent panel */ private ErdViewerPanel parent; /** The <code>ErdTable</code> representing this dialog */ private ErdTable erdTable; /** Contains the column descriptions for a selected table */ private EditTablePanel columnDataTable; /** The panel displaying the table's constraints */ private EditErdTableConstraintsPanel conPanel; /** The table name field (non-editable) */ private DisabledField tableNameField; /** The buffer off all SQL generated */ private StringBuffer sqlBuffer; /** The table currently in focus */ private JTable focusTable; /** The tool bar */ private CreateTableToolBar tools; /** The tabbed pane display */ private JTabbedPane tabs; public ErdEditTableDialog(ErdViewerPanel parent, ErdTable erdTable) { super("Table Description: " + erdTable.getTableName()); this.parent = parent; this.erdTable = erdTable; try { jbInit(); } catch (Exception e) { e.printStackTrace(); } display(); } private void jbInit() throws Exception { JButton closeButton = new JButton("Close"); JButton applyButton = new JButton("Apply"); ActionListener btnListener = new ActionListener() { public void actionPerformed(ActionEvent e) { buttons_actionPerformed(e); } }; closeButton.addActionListener(btnListener); applyButton.addActionListener(btnListener); closeButton.setPreferredSize(Constants.BUTTON_SIZE); applyButton.setPreferredSize(Constants.BUTTON_SIZE); ColumnData[] columns = erdTable.getTableColumns(); // make a copy of the current columns ColumnData[] _columns = new ColumnData[columns.length]; for (int i = 0; i < columns.length; i++) { _columns[i] = new ColumnData(); _columns[i].setValues(columns[i]); } columnDataTable = new EditTablePanel(this); columnDataTable.setColumnDataArray(_columns, null); columnDataTable.setOriginalData(erdTable.getOriginalTableColumns()); columnDataTable.setSQLChangesHash(erdTable.getAlterTableHash()); conPanel = new EditErdTableConstraintsPanel(this, _columns); JPanel conBase = new JPanel(new GridBagLayout()); conBase.add(conPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); // set up and add the focus listener for the tables FocusListener tableFocusListener = new FocusListener() { public void focusGained(FocusEvent e) { focusTable = (JTable)e.getSource(); } public void focusLost(FocusEvent e) {} }; columnDataTable.addTableFocusListener(tableFocusListener); conPanel.addTableFocusListener(tableFocusListener); tabs = new JTabbedPane(); tabs.add("Columns", columnDataTable); tabs.add("Constraints", conBase); tabs.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (tabs.getSelectedIndex() == 1) tools.enableButtons(false); else tools.enableButtons(true); } }); tools = new CreateTableToolBar(this, false); sqlText.setSQLText(erdTable.getAlterTableScript()); JPanel mainPanel = new JPanel(new GridBagLayout()); mainPanel.setBorder(BorderFactory.createEtchedBorder()); tableNameField = new DisabledField(erdTable.getTableName()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(10,10,10,10); gbc.gridx = 0; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.gridwidth = 2; mainPanel.add(new JLabel("Table Name:"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.left = 0; gbc.gridx = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; mainPanel.add(tableNameField, gbc); gbc.insets.left = 10; gbc.weightx = 0; gbc.insets.top = 0; gbc.gridwidth = 1; gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.VERTICAL; gbc.insets.right = 0; mainPanel.add(tools, gbc); gbc.insets.left = 0; gbc.insets.right = 10; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.left = 5; gbc.gridx = 1; gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 0.8; mainPanel.add(tabs, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.weighty = 0.6; gbc.insets.left = 10; gbc.insets.bottom = 0; mainPanel.add(sqlText, gbc); gbc.weighty = 0; gbc.weightx = 0; gbc.gridy = 4; gbc.gridx = 4; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.VERTICAL; gbc.insets.left = 7; gbc.insets.top = 7; gbc.insets.bottom = 10; gbc.anchor = GridBagConstraints.SOUTHEAST; mainPanel.add(closeButton, gbc); gbc.insets.right = 0; gbc.gridx = 3; gbc.weightx = 1.0; mainPanel.add(applyButton, gbc); mainPanel.setPreferredSize(new Dimension(520, 375)); Container c = this.getContentPane(); c.setLayout(new GridBagLayout()); c.add(mainPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH, new Insets(7, 7, 7, 7), 0, 0)); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); sqlBuffer = new StringBuffer(); } // ----------------------------------------------- // -------- TableFunction implementations -------- // ----------------------------------------------- public void setSQLText() { sqlText.setSQLText(columnDataTable.getSQLText() + conPanel.getSQLText()); } public void setSQLText(String values, int type) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -