📄 browsertableeditingpanel.java
字号:
/* * BrowserTableEditingPanel.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.Color;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.awt.print.Printable;import java.util.HashMap;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTable;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.table.TableColumn;import javax.swing.table.TableColumnModel;import org.executequery.Constants;import org.executequery.EventMediator;import org.executequery.GUIUtilities;import org.executequery.databasemediators.DatabaseTable;import org.executequery.event.KeywordEvent;import org.executequery.event.KeywordListener;import org.executequery.gui.DefaultTable;import org.executequery.gui.table.EditTableConstraintsPanel;import org.executequery.gui.table.EditTablePanel;import org.executequery.gui.table.TableModifier;import org.executequery.gui.text.SimpleSqlTextPanel;import org.executequery.print.TablePrinter;import org.underworldlabs.swing.DisabledField;import org.executequery.gui.forms.AbstractFormObjectViewPanel;import org.executequery.gui.scriptgenerators.ScriptGenerationUtils;import org.executequery.gui.table.TableConstraintFunction;import org.underworldlabs.swing.FlatSplitPane;import org.executequery.gui.editor.ResultSetTableModel;import org.executequery.gui.text.TextEditor;/* ---------------------------------------------------------- * 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.9 $ * @date $Date: 2006/09/06 09:30:58 $ */public class BrowserTableEditingPanel extends AbstractFormObjectViewPanel implements ActionListener, KeywordListener, FocusListener, TableConstraintFunction, ChangeListener { // TEXT FUNCTION CONTAINER public static final String NAME = "BrowserTableEditingPanel"; /** Contains the table name */ private DisabledField tableNameField; /** Contains the schema name */ private DisabledField schemaNameField; /** Contains the data row count */ private DisabledField rowCountField; /** The table view tabbed pane */ private JTabbedPane tabPane; /** The SQL text pane for alter text */ private SimpleSqlTextPanel alterSqlText; /** The SQL text pane for create table text */ private SimpleSqlTextPanel createSqlText; /** Contains the column descriptions for a selected table */ private EditTablePanel columnDataTable; /** The panel displaying the table's constraints */ private EditTableConstraintsPanel conPanel; /** Contains the column indexes for a selected table */ private JTable columnIndexTable; /** A reference to the currently selected table. * This is not a new <code>JTable</code> instance */ private JTable focusTable; /** Whether the SQL pane is currently visible */ private boolean hasSQL; /** Contains the constraints for a selected table */ private Vector<ColumnConstraint> constraintsVector; /** The table column index table model */ private ColumnIndexTableModel citm; /** Holds temporary SQL text during modifications */ private StringBuffer sbTemp; /** table data tab panel */ private TableDataTab tableDataPanel; /** current node selection object */ private DatabaseObject metaObject; /** the erd panel */ private ReferencesDiagramPanel referencesPanel; /** table privileges list */ private TablePrivilegeTab tablePrivilegePanel; /** panel cache */ private HashMap cache; /** the apply changes button */ private JButton applyButton; /** the cancel changes button */ private JButton cancelButton; /** the browser's control object */ private BrowserController controller; /** the meta data table */ private JTable metaDataTable; /** the meta data model */ private ResultSetTableModel metaDataModel; /** the last focused editor */ private TextEditor lastFocusEditor; public BrowserTableEditingPanel(BrowserController controller) { this.controller = controller; try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() throws Exception { // the column index table citm = new ColumnIndexTableModel(); columnIndexTable = new DefaultTable(citm); columnIndexTable.setRowHeight(20); columnIndexTable.setColumnSelectionAllowed(false); columnIndexTable.getTableHeader().setReorderingAllowed(false); // column indexes panel JPanel indexesPanel = new JPanel(new BorderLayout()); indexesPanel.setBorder(BorderFactory.createTitledBorder("Table Indexes")); indexesPanel.add(new JScrollPane(columnIndexTable), BorderLayout.CENTER); // table meta data table metaDataModel = new ResultSetTableModel(); metaDataTable = new DefaultTable(metaDataModel); metaDataTable.setRowHeight(20); metaDataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // table meta data panel JPanel metaDataPanel = new JPanel(new BorderLayout()); metaDataPanel.setBorder(BorderFactory.createTitledBorder("Table Column Meta Data")); metaDataPanel.add(new JScrollPane(metaDataTable), BorderLayout.CENTER); // table data panel tableDataPanel = new TableDataTab(); // table privileges panel tablePrivilegePanel = new TablePrivilegeTab(); // table references erd panel referencesPanel = new ReferencesDiagramPanel(); // alter sql text panel alterSqlText = new SimpleSqlTextPanel(); alterSqlText.setSQLTextBackground(Color.WHITE); alterSqlText.setBorder(BorderFactory.createTitledBorder("Alter Table")); alterSqlText.setPreferredSize(new Dimension(100, 100)); alterSqlText.getEditorTextComponent().addFocusListener(this); // create sql text panel createSqlText = new SimpleSqlTextPanel(); createSqlText.setSQLTextBackground(Color.WHITE); createSqlText.setBorder(BorderFactory.createTitledBorder("Create Table")); createSqlText.getEditorTextComponent().addFocusListener(this); // sql text split pane FlatSplitPane splitPane = new FlatSplitPane(FlatSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(alterSqlText); splitPane.setBottomComponent(createSqlText); splitPane.setDividerSize(7); splitPane.setResizeWeight(0.25); // the contraints panel conPanel = new EditTableConstraintsPanel(this); conPanel.setBorder(BorderFactory.createTitledBorder("Table Keys")); // the column decription table columnDataTable = new EditTablePanel(this); columnDataTable.setBorder(BorderFactory.createTitledBorder("Table Columns")); tableNameField = new DisabledField(); schemaNameField = new DisabledField(); rowCountField = new DisabledField(); // create the tabbed pane tabPane = new JTabbedPane(); tabPane.add("Description", columnDataTable); tabPane.add("Constraints", conPanel); tabPane.add("Indexes", indexesPanel); tabPane.add("Privileges", tablePrivilegePanel); tabPane.add("References", referencesPanel); tabPane.add("Data", tableDataPanel); tabPane.add("SQL", splitPane); tabPane.add("Meta Data", metaDataPanel); tabPane.addChangeListener(this); // apply/cancel buttons applyButton = new JButton("Apply"); cancelButton = new JButton("Cancel"); applyButton.setPreferredSize(Constants.FORM_BUTTON_SIZE); applyButton.setMinimumSize(Constants.FORM_BUTTON_SIZE); cancelButton.setPreferredSize(Constants.FORM_BUTTON_SIZE); cancelButton.setMinimumSize(Constants.FORM_BUTTON_SIZE); applyButton.addActionListener(this); cancelButton.addActionListener(this); // add to the base panel JPanel base = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); Insets ins = new Insets(10,5,5,5); gbc.insets = ins; gbc.anchor = GridBagConstraints.NORTHEAST; gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; base.add(new JLabel("Table Name:"), gbc); gbc.insets.left = 5; gbc.insets.right = 5; gbc.gridx = 1; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; base.add(tableNameField, gbc); gbc.insets.top = 0; gbc.gridy++; base.add(schemaNameField, gbc); gbc.insets.right = 5; gbc.insets.left = 5; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; base.add(new JLabel("Schema:"), gbc); // add the tab pane gbc.gridy++; gbc.gridx = 0; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHEAST; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.bottom = 5; gbc.insets.top = 0; gbc.insets.right = 5; gbc.insets.left = 5; gbc.weightx = 1.0; gbc.weighty = 1.0; base.add(tabPane, gbc); // add the bottom components gbc.gridy++; gbc.gridx = 0; gbc.weighty = 0; gbc.weightx = 0; gbc.insets.top = 1; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; base.add(new JLabel("Data Row Count:"), gbc); gbc.gridx = 2; gbc.insets.top = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 1; gbc.insets.right = 0; base.add(rowCountField, gbc); gbc.gridx = 3; gbc.weightx = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -