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

📄 tableconstraintspanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void addTableFocusListener(FocusListener listener) {        table.addFocusListener(listener);    }        /** <p>Sets the specified table model to the table.     *     *  @param the table model     */    public void setModel(AbstractTableModel model) {        table.setModel(model);    }        public ColumnConstraint getConstraintAt(int row) {        return model.getConstraintAt(row);    }        class ColumnConstraintModel extends AbstractTableModel {                private String[] header = {"",                                   "Name",                                    "Type",                                    "Table Column",                                    "Reference Schema",                                   "Reference Table",                                    "Reference Column"};        private Vector keys;        public ColumnConstraintModel(Vector v) {            keys = v;        }                public void setNewData(Vector v) {            keys = v;        }                public int getColumnCount() {            return header.length;        }                public int getRowCount() {            return keys.size();        }                /**         * Inserts a constraint to the end of this model.         *         * @param isNew - whether the constraint will be marked as new         */        public void insertRowAfter(boolean isNew) {            keys.add(new ColumnConstraint(isNew));            int newIndex = keys.size() - 1; // end of vector            fireTableRowsInserted(newIndex, newIndex);        }        public Object getValueAt(int row, int col) {            ColumnConstraint cc = (ColumnConstraint)keys.elementAt(row);                        // check the column type            boolean canHaveReference = (cc.getType() == ColumnConstraint.FOREIGN_KEY);            switch(col) {                case 0:                    return cc;                case 1:                    return cc.getName();                case 2:                    return cc.getTypeName();                case 3:                    return cc.getColumn();                case 4:                    if (!canHaveReference) {                        return null;                    }                    return cc.getRefSchema();                case 5:                    if (!canHaveReference) {                        return null;                    }                    return cc.getRefTable();                case 6:                    if (!canHaveReference) {                        return null;                    }                    return cc.getRefColumn();                default:                    return null;            }        }                public void setValueAt(Object value, int row, int col) {            if (row < 0 || row > (keys.size() - 1)) {                return;            }            ColumnConstraint cc = (ColumnConstraint)keys.elementAt(row);                                    switch (col) {                case 0:                    return;                case 1:                    cc.setName((String)value);                    columnValuesChanged(col, row, cc.getName());                    break;                case 2:                    String colType = (String)value;                    if (colType == cc.PRIMARY) {                        cc.setType(cc.PRIMARY_KEY);                    } else if (colType == cc.FOREIGN) {                        cc.setType(cc.FOREIGN_KEY);                    } else if (colType == cc.UNIQUE) {                        cc.setType(cc.UNIQUE_KEY);                    }                                        if (colType != null) {                        updateCellEditor(col, row, colType);                        columnValuesChanged(col, row, null);                    }                                        cc.setColumn(cc.EMPTY);                    cc.setRefSchema(cc.EMPTY);                    cc.setRefTable(cc.EMPTY);                    cc.setRefColumn(cc.EMPTY);                    break;                case 3:                    cc.setColumn(value.toString());                    columnValuesChanged(col, row, null);                    break;                case 4:                    String schema = (String)value;                    cc.setRefSchema(schema);                    cc.setRefTable(cc.EMPTY);                    cc.setRefColumn(cc.EMPTY);                                        if (schema != null) {                        updateCellEditor(col, row, schema);                        columnValuesChanged(col, row, null);                    }                                        break;                case 5:                    String tbl = (String)value;                    cc.setRefColumn(cc.EMPTY);                    cc.setRefTable(tbl);                    if (tbl != null) {                        updateCellEditor(col, row, tbl);                        columnValuesChanged(col, row, null);                    }                                        break;                case 6:                    cc.setRefColumn((String)value);                    columnValuesChanged(col, row, null);                                        break;            }                        fireTableRowsUpdated(row, row);        }                public ColumnConstraint getConstraintAt(int row) {            return (ColumnConstraint)keys.elementAt(row);        }                public boolean isCellEditable(int row, int col) {            ColumnConstraint cc = (ColumnConstraint)keys.elementAt(row);                        // check if its a new table create            if (getMode() == CREATE_TABLE_MODE) {                switch (col) {                    case 0:                        return false;                    case 1:                    case 2:                    case 3:                        return true;                    case 4:                    case 5:                    case 6:                        if ((cc.getType() == cc.UNIQUE_KEY ||                                cc.getType() == cc.PRIMARY_KEY)) {                            return false;                        }                        return true;                }            }            else {                if (col == 1) {                    return true;                }                if (cc.isNewConstraint()) {                    if (col > 3 && (cc.getType() == cc.UNIQUE_KEY ||                            cc.getType() == cc.PRIMARY_KEY)) {                        return false;                    }                     else {                        return true;                    }                }                            }            return false;            /*            if (cc.isNewConstraint()) {                                if ((cc.getType() == cc.UNIQUE_KEY ||                        cc.getType() == cc.PRIMARY_KEY) && col > 3) {                    return false;                }                 else {                    return true;                }            }            else if (col == 1) {                return true;            }                        else {                return false;            }            */        }                public void deleteRow(int row) {            keys.remove(row);        }                public String getColumnName(int col) {            return header[col];        }                public void deleteConstraint(String refColumn) {                        int v_size = keys.size();            if (v_size == 0) {                insertRowAfter(getMode() == EDIT_TABLE_MODE);                return;            }            for (int i = 0; i < v_size; i++) {                ColumnConstraint cc = (ColumnConstraint)keys.elementAt(i);                                if (cc.getColumn() != null && cc.getColumn().equalsIgnoreCase(refColumn)) {                    deleteRow(i);                    fireTableRowsDeleted(i, i);                    break;                }                            }                    }        public void deleteConstraint(int index) {            deleteRow(index);            fireTableRowsDeleted(index, index);        }        public Vector getKeys() {            return keys;        }            } // class ColumnConstraintModel        }

⌨️ 快捷键说明

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