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

📄 createindexpanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                schemas = metaData.getHostedCatalogsVector();            } else {                useCatalogs = false;            }            populateSchemaValues(schemas);        }        catch (DataSourceException e) {            GUIUtilities.displayExceptionErrorDialog(                    "Error retrieving the catalog/schema names for the " +                    "current connection.\n\nThe system returned:\n" +                     e.getExtendedMessage(), e);            populateSchemaValues(new Vector(0));        }    }        private void populateTableValues(final String[] tables) {        GUIUtils.invokeAndWait(new Runnable() {            public void run() {                tablesModel.removeAllElements();                                if (tables == null || tables.length == 0) {                    tableCombo.setEnabled(false);                }                 else {                    tableCombo.setEnabled(true);                    tablesModel.setElements(tables);                }            }        });    }        private void populateSchemaValues(final Vector schemas) {        GUIUtils.invokeAndWait(new Runnable() {            public void run() {                schemaModel.removeAllElements();                tablesModel.removeAllElements();                schemaModel.setElements(schemas);                schemaCombo.setEnabled(true);                if (schemaModel.getSize() > 0) {                    schemaCombo.setSelectedIndex(0);                }                else {                    tablesModel.removeAllElements();                    tableCombo.setEnabled(false);                }            }        });    }            private void schemaChanged() {        try {            String catalogName = null;            String schemaName = null;            Object value = schemaCombo.getSelectedItem();            if (value != null) {                if (useCatalogs) {                    catalogName = value.toString();                }                else {                                        schemaName = value.toString();                }            }            String[] tables = metaData.getTables(catalogName, schemaName, "TABLE");            populateTableValues(tables);        }        catch (DataSourceException e) {            GUIUtilities.displayExceptionErrorDialog(                    "Error retrieving the table list for the selected " +                    "catalog/schema.\n\nThe system returned:\n" +                     e.getExtendedMessage(), e);            populateTableValues(new String[0]);        }                tableChanged();    }        /**     * Returns the index name field.     */    public Component getDefaultFocusComponent() {        return nameField;    }    private void tableChanged() {        tableVector.clear();        String name = (String)tableCombo.getSelectedItem();                if (name == null || name.length() == 0) {            GUIUtils.invokeAndWait(new Runnable() {                public void run() {                    tableChanged(null);                    model.fireTableDataChanged();                }            });            return;        }                ColumnData[] cd = null;                String catalogName = null;        String schemaName = null;        Object value = schemaCombo.getSelectedItem();        if (value != null) {            if (useCatalogs) {                catalogName = value.toString();            }            else {                                    schemaName = value.toString();            }        }        try {            cd = metaData.getColumnMetaData(catalogName, schemaName, name);        }        catch (Exception e) {            StringBuffer sb = new StringBuffer();            sb.append("An error occurred retrieving table and column data.").               append("\n\nThe system returned:\n").               append(e.getMessage());            GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);        }                if (cd != null) {                        for (int i = 0; i < cd.length; i++) {                TableDefinition td = new TableDefinition();                td.name = cd[i].getColumnName();                td.type = cd[i].getColumnType();                tableVector.add(td);            }                    }        GUIUtils.invokeAndWait(new Runnable() {            public void run() {                model.fireTableDataChanged();                tableChanged(null);            }        });    }        public void actionPerformed(ActionEvent e) {        Object source = e.getSource();        if (source instanceof JCheckBox) {            tableChanged(null);        }        else if (source == moveUpButton || source == moveDownButton) {            move_actionPerformed(source);        }        else {            // check the command for a create            if ("Create".equals(e.getActionCommand())) {                GUIUtils.startWorker(new Runnable() {                    public void run() {                        try {                            parent.setInProcess(true);                            createIndex();                        }                        finally {                            parent.setInProcess(false);                        }                    }                });            }        }    }    private void createIndex() {        DatabaseConnection dc = (DatabaseConnection)                        connectionsCombo.getSelectedItem();        if (dc == null) {            GUIUtilities.displayErrorMessage(                    "No database connection is available.");            return;        }        try {            QuerySender qs = new QuerySender(dc);            SqlStatementResult result = qs.updateRecords(sqlText.getSQLText());            if (result.getUpdateCount() >= 0) {                GUIUtilities.displayInformationMessage(                        "Index " + nameField.getText() + " created.");                parent.finished();            }            else {                SQLException e = result.getSqlException();                if (e != null) {                    StringBuffer sb = new StringBuffer();                    sb.append("An error occurred applying the specified changes.").                       append("\n\nThe system returned:\n").                       append(MiscUtils.formatSQLError(e));                    GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);                }                 else {                    GUIUtilities.displayErrorMessage(result.getErrorMessage());                }            }                    }                catch (Exception e) {            GUIUtilities.displayExceptionErrorDialog("Error:\n" + e.getMessage(), e);        }            }        public void tableChanged(TableModelEvent e) {        String name = (String)tableCombo.getSelectedItem();        String schema = (String)schemaCombo.getSelectedItem();        sqlBuffer = new StringBuffer(100);        if (uniqueCheck.isSelected()) {            sqlBuffer.append(CREATE_UNIQUE);        }        else if (bitmapCheck.isSelected()) {            sqlBuffer.append(CREATE_BITMAP);        }        else {            sqlBuffer.append(CREATE_INDEX);        }        sqlBuffer.append(nameField.getText() == null ? EMPTY : nameField.getText());        sqlBuffer.append(ON);                if (schema != null && schema.length() > 0) {            sqlBuffer.append(schema).append(DOT);        }        sqlBuffer.append(name == null ? EMPTY : name).append(SPACE);        sqlBuffer.append(B_OPEN);                for (int i = 0, k = tableVector.size(); i < k; i++) {            TableDefinition td = (TableDefinition)tableVector.elementAt(i);                        if (td.order != null && td.order.booleanValue()) {                                sqlBuffer.append(td.name);                if (i != k - 1) {                    sqlBuffer.append(COMMA).append(SPACE);                }            }                    }        sqlBuffer.append(B_CLOSE);                if (unsortedCheck.isSelected()) {            sqlBuffer.append(NO_SORT);        }                String text = sqlBuffer.toString();        int comma_index = text.lastIndexOf(COMMA);                if (comma_index == text.length() - 3) {            sqlBuffer.delete(comma_index, comma_index + 2);        }        //sqlText.setSQLText(sqlBuffer.toString());        final String _sqlText = sqlBuffer.toString();        GUIUtils.invokeLater(new Runnable() {            public void run() {                sqlText.setSQLText(_sqlText);            }        });            }        private void move_actionPerformed(Object source) {                int selection = selectedTable.getSelectedRow();                if (source == moveUpButton) {                        if (selection == -1 || selection == 0) {                return;            }                        int newPostn = selection - 1;            TableDefinition move = (TableDefinition)tableVector.elementAt(selection);            tableVector.removeElementAt(selection);            tableVector.add(newPostn, move);            selectedTable.setRowSelectionInterval(newPostn, newPostn);            model.fireTableRowsUpdated(newPostn, selection);        }                else if (source == moveDownButton) {                        if (selection == -1 || selection == tableVector.size() - 1)                return;                        int newPostn = selection + 1;            TableDefinition move = (TableDefinition)tableVector.elementAt(selection);            tableVector.removeElementAt(selection);            tableVector.add(newPostn, move);            selectedTable.setRowSelectionInterval(newPostn, newPostn);            model.fireTableRowsUpdated(selection, newPostn);        }            }        // ------------------------------------------------    // ----- TextEditorContainer implementations ------    // ------------------------------------------------        /**     * Returns the SQL text pane as the TextEditor component      * that this container holds.     */    public TextEditor getTextEditor() {        return sqlText;    }            private class CreateIndexModel extends AbstractTableModel {                protected String[] header = {"Column Name", "Datatype", "Select"};                public CreateIndexModel() {}                public int getColumnCount() {            return 3;        }                public int getRowCount() {            return tableVector.size();        }                public Object getValueAt(int row, int col) {            TableDefinition tc = (TableDefinition)tableVector.elementAt(row);                        switch(col) {                case 0:                    return tc.name;                case 1:                    return tc.type;                case 2:                    return tc.order;                default:                    return null;            }        }                public void setValueAt(Object value, int row, int col) {            TableDefinition tc = (TableDefinition)tableVector.elementAt(row);                        switch (col) {                case 0:                    tc.name = (String)value;                    break;                case 1:                    tc.type = (String)value;                    break;                case 2:                    tc.order = value != null ? (Boolean)value : null;                    break;            }                        fireTableRowsUpdated(row, row);        }                public boolean isCellEditable(int row, int col) {            if (col < 2) {                return false;            } else {                return true;            }        }                public String getColumnName(int col) {            return header[col];        }                public Class getColumnClass(int col) {            if (col == 2)                return Boolean.class;            else                return String.class;        }            } // CreateIndexModel            static class TableDefinition {        String name;        String type;        Boolean order;                TableDefinition() {}                public String toString() {            return name;        }            } // TableDefinition            public String getDisplayName() {        return "";    }        public String toString() {        return TITLE;    }    }

⌨️ 快捷键说明

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