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

📄 edittableconstraintspanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * EditTableConstraintsPanel.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.Point;import java.awt.event.FocusListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.sql.SQLException;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import javax.swing.JOptionPane;import javax.swing.JTable;import org.executequery.databasemediators.QuerySender;import org.executequery.GUIUtilities;import org.executequery.databasemediators.SqlStatementResult;import org.executequery.gui.browser.ColumnConstraint;import org.executequery.gui.browser.ColumnData;import org.underworldlabs.swing.GUIUtils;import org.underworldlabs.swing.table.ComboBoxCellEditor;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.5 $ * @date     $Date: 2006/06/09 01:44:37 $ */public class EditTableConstraintsPanel extends TableConstraintsPanel {        /** The table creator object - parent to this */    private TableConstraintFunction creator;        /** The buffer off all SQL generated */    private StringBuffer sqlBuffer;        /** The hosted schemas for the connection */    private Vector hostedSchemas;        /** The original constraints */    private ColumnConstraint[] fKeys_orig;        /** Holds temporary SQL text during modifications */    private Hashtable tempSqlText;        public EditTableConstraintsPanel(TableConstraintFunction creator) {        super();        this.creator = creator;        table.addMouseListener(new MouseHandler());                sqlBuffer = new StringBuffer(100);        tempSqlText = new Hashtable();    }        public ColumnData[] getTableColumnData() {        return creator.getTableColumnData();    }    public int getMode() {        return EDIT_TABLE_MODE;    }        public void updateCellEditor(int col, int row, String value) {        Vector fKeys = model.getKeys();        ColumnConstraint cc = (ColumnConstraint)fKeys.get(row);                switch (col) {                        case 0:            case 1:                return;                            case 2:                setCellEditor(3, new ComboBoxCellEditor(getTableColumnData()));/*                                if (value == ColumnConstraint.PRIMARY) {                    setCellEditor(3, new ComboBoxCellEditor(getTableColumnData()));                }                else */                if (value == ColumnConstraint.FOREIGN) {                    if (hostedSchemas == null) {                        hostedSchemas = creator.getHostedSchemasVector();                    }                    int schemaSize = hostedSchemas.size();                                        // this means that cretor objects with null                    // schema lists must generate the table values                    // from elsewhere                    if (schemaSize == 0) {                        setCellEditor(5, new ComboBoxCellEditor(creator.getSchemaTables(value)));                        return;                    }                                        String[] schemas = new String[schemaSize];                    for (int i = 0, k = hostedSchemas.size(); i < k; i++) {                        schemas[i] = (String)hostedSchemas.elementAt(i);                    }                                        setCellEditor(4, new ComboBoxCellEditor(schemas));                                    }                                break;                            case 3:                return;                            case 4:                if (value == null || value.length() == 0) {                    return;                }                                setCellEditor(5, new ComboBoxCellEditor(creator.getSchemaTables(value)));                break;                            case 5:                setCellEditor(6, new ComboBoxCellEditor(                creator.getColumnNamesVector(value, cc.getRefSchema())));                            case 6:                return;                        }            }        public void columnValuesChanged(int col, int row, String value){               ColumnConstraint cc_orig = null;        Vector fKeys = model.getKeys();        if (row < 0 || row > (fKeys.size() - 1)) {            return;        }        ColumnConstraint cc = (ColumnConstraint)fKeys.elementAt(row);        sqlBuffer.setLength(0);                if (row > fKeys_orig.length - 1 || cc.isNewConstraint()) {                        if (value == null) {                value = cc.getName();            }            else if (value.length() == 0) {                tempSqlText.remove(ADD_CONSTRAINT + row);                generateSQL();                creator.setSQLText(sqlBuffer.toString(),                                    TableModifier.CONSTRAINT_VALUES);                return;            }            sqlBuffer.append(ALTER_TABLE).                      append(creator.getTableName()).                      append(ADD_CONSTRAINT).                      append(value).append(SPACE).                      append(cc.getTypeName() == null ? EMPTY : cc.getTypeName());            switch (cc.getType()) {                                case ColumnConstraint.FOREIGN_KEY:                    sqlBuffer.append(KEY).                              append(B_OPEN).                              append(cc.getColumn()).                              append(B_CLOSE).                              append(SPACE).                              append(REFERENCES);                                        if (cc.hasSchema()) {                        sqlBuffer.append(cc.getRefSchema()).append(DOT);                    }                    //                    sqlBuffer.append(creator.getTableName()).append(B_OPEN).                    sqlBuffer.append(cc.getRefTable()).                              append(B_OPEN).                              append(cc.getRefColumn()).                              append(B_CLOSE).                              append(SEMI_COLON).                              append(NEW_LINE);                    break;                                    case ColumnConstraint.UNIQUE_KEY:                    sqlBuffer.append(B_OPEN).                              append(cc.getColumn()).                              append(B_CLOSE).                              append(SEMI_COLON).                              append(NEW_LINE);                    break;                                    case ColumnConstraint.PRIMARY_KEY:                    sqlBuffer.append(KEY).                              append(B_OPEN).                              append(cc.getColumn()).                              append(B_CLOSE).                              append(SEMI_COLON).                              append(NEW_LINE);                    break;                                    default:                    sqlBuffer.append(B_OPEN).                              append(cc.getColumn()).                              append(B_CLOSE).                              append(SEMI_COLON).                              append(NEW_LINE);                    break;                                }                        tempSqlText.put(ADD_CONSTRAINT + row, sqlBuffer.toString());                    } else {            cc_orig = fKeys_orig[row];                        if (cc_orig.getName().equals(value)) {                tempSqlText.remove(RENAME_CONSTRAINT + row);            }                        else {                sqlBuffer.append(ALTER_TABLE).                          append(creator.getTableName()).                          append(RENAME_CONSTRAINT).                          append(cc_orig.getName()).                          append(TO).                          append(value).                          append(SEMI_COLON).                          append(NEW_LINE);                tempSqlText.put(RENAME_CONSTRAINT + row, sqlBuffer.toString());            }                    }                generateSQL();        creator.setSQLText(sqlBuffer.toString(), TableModifier.CONSTRAINT_VALUES);        

⌨️ 快捷键说明

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