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

📄 edittablepanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * EditTablePanel.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.MouseAdapter;import java.awt.event.MouseEvent;import java.sql.SQLException;import java.util.Enumeration;import java.util.Hashtable;import javax.swing.DefaultCellEditor;import javax.swing.JOptionPane;import org.executequery.databasemediators.QuerySender;import org.executequery.GUIUtilities;import org.executequery.databasemediators.SqlStatementResult;import org.executequery.gui.browser.ColumnData;import org.underworldlabs.swing.GUIUtils;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 EditTablePanel extends TableDefinitionPanel {        /** The table creator object - parent to this */    private TableModifier creator;        /** The buffer off all SQL generated */    private StringBuffer sqlText;        /** Holds temporary SQL text during modifications */    private Hashtable tempSqlText;        /** The column descriptions for the current selection before modifications */    private ColumnData[] originalData;        /** The string literal 'ALTER TABLE ' */    private static String DROP_COLUMN_1 = "ALTER TABLE ";        /** The string literal ' DROP COLUMN ' */    private static String DROP_COLUMN_2 = " DROP COLUMN ";        //------------------------------------------------    // The following are reuseable String constants    // used in the SQL text pane when making table    // or other schema modifications.    //------------------------------------------------        /** The String literal 'ALTER TABLE ' */    private static final String ALTER_TABLE = "ALTER TABLE ";    /** The String literal ' MODIFY (' */    private static final String MODIFY = " MODIFY (";    /** The String literal ' NOT NULL' */    private static final String NOT_NULL = " NOT NULL";    /** The String literal ' NULL' */    private static final String NULL = " NULL";    /** The String literal ' ADD ' */    private static final String ADD = " ADD ";    /** The String literal ' DROP ' */    private static final String DROP = " DROP ";    /** The String literal ')' */    private static final String CLOSE_B = ")";    /** The character literal '(' */    private static final char OPEN_B = '(';    /** The String literal ' RENAME COLUMN ' */    private static final String RENAME_COLUMN = " RENAME COLUMN ";    /** The String literal ' TO ' */    private static final String TO = " TO ";    /** The character literal ',' */    private static final char COMMA = ',';    /** The character literal '.' */    private static final char DOT = '.';    /** The character literal ' ' */    private static final char SPACE = ' ';    /** An empty String literal */    private static final String EMPTY = "";    /** A semi-colon followed by a carriage return ';\n' */    private static final String NEW_LINE = ";\n";        public EditTablePanel(TableModifier creator) {        super();        this.creator = creator;                sqlText = new StringBuffer(100);        tempSqlText = new Hashtable();        getTable().addMouseListener(new MouseHandler());    }        public String getSQLText() {        generateSQL();        return sqlText.toString();    }        public void setOriginalData(ColumnData[] cda) {        originalData = cda;    }        /*    public void setColumnDataArray(ColumnData[] cda) {        _model.setColumnDataArray(cda);    }    */    /** <p>Sets the SQL changes <code>Hashtable</code> to     *  an existing one as the value passed.     *     *  @param the SQL changes within a <code>Hashtable</code>     */    public void setSQLChangesHash(Hashtable tempSqlText) {                if (tempSqlText != null) {            this.tempSqlText = tempSqlText;        }    }        /** <p>Returns the SQL changes within a <code>Hashtable</code>.     *     *  @return the SQL changes     */    public Hashtable getSQLChangesHash() {        return tempSqlText;    }    public void setOriginalData() {                GUIUtils.startWorker(new Runnable() {        //SwingUtilities.invokeLater(new Runnable() {            public void run() {                                int v_size = tableVector.size();                originalData = new ColumnData[v_size];                                for (int i = 0; i <v_size; i++) {                    originalData[i] = new ColumnData();                    originalData[i].setValues(tableVector.elementAt(i));                }                            }        });            }        /** <p>Drops the currently selected column (table row)     *  from the database table and applies this change     *  to the database.     *     *  @param the <code>QuerySender</code> to perform the     *         operation on the database.     */    public void deleteRow(QuerySender qs) {        int row = getSelectedRow();        if (row == -1) {            return;        }                tableEditingStopped(null);                if (isEditing()) {            removeEditor();        }                ColumnData cd = tableVector.elementAt(row);                int newEditingRow = row == tableVector.size() - 1 ? row - 1 : row;        setEditingRow(newEditingRow);                if (cd.isNewColumn()) {            tableVector.removeElementAt(row);            _model.fireTableRowsDeleted(row, row);            tempSqlText.remove(ADD + row);            addColumnLines(-1);            return;        }                int yesNo = GUIUtilities.displayConfirmDialog(                                "Are you sure you want to remove\n" +                                "the column " + cd.getColumnName() + "?");                if (yesNo == JOptionPane.NO_OPTION || yesNo == JOptionPane.CANCEL_OPTION) {            return;        }        else if (yesNo == JOptionPane.YES_OPTION) {                        try {                SqlStatementResult result = qs.updateRecords(                        DROP_COLUMN_1 + creator.getTableName() +                        DROP_COLUMN_2 + cd.getColumnName());                                if (result.getUpdateCount() >= 0) {                    tableVector.removeElementAt(row);                    _model.fireTableRowsDeleted(row, row);                }                                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) {                e.printStackTrace();                StringBuffer sb = new StringBuffer();                sb.append("An error occurred applying the specified changes.").                   append("\n\nThe system returned:\n").                   append(e.getMessage());                GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);            }                    }            }    /**      * <p>Inserts a new column after the selected     * column moving the selected column up one row.      *      * Overrides to mark the column as new.     */    public void insertAfter() {        fireEditingStopped();        int selection = getSelectedRow();        if (selection == -1) {            return;        }        int newRow = selection + 1;        ColumnData cd = new ColumnData(true);        cd.setColumnRequired(ColumnData.VALUE_NOT_REQUIRED);        if (selection == tableVector.size()) {            tableVector.add(cd);        }        else {            tableVector.add(newRow, cd);        }                _model.fireTableRowsInserted(selection, newRow);                setRowSelectionInterval(newRow);        setColumnSelectionInterval(1);

⌨️ 快捷键说明

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