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

📄 browsercontroller.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * BrowserController.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.sql.ResultSet;import java.sql.SQLException;import java.util.Hashtable;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import java.util.Vector;import javax.swing.JOptionPane;import javax.swing.JPanel;import org.executequery.GUIUtilities;import org.executequery.SystemUtilities;import org.executequery.databasemediators.DatabaseConnection;import org.executequery.databasemediators.DatabaseProcedure;import org.executequery.databasemediators.MetaDataValues;import org.executequery.databasemediators.QuerySender;import org.executequery.databasemediators.SqlStatementResult;import org.underworldlabs.jdbc.DataSourceException;import org.executequery.gui.forms.FormObjectView;import org.executequery.util.Log;import org.underworldlabs.util.MiscUtils;import org.underworldlabs.swing.util.SwingWorker;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * Performs SQL execution tasks from browser components. * * @author   Takis Diakoumis * @version  $Revision: 1.13 $ * @date     $Date: 2006/09/05 12:01:24 $ */public class BrowserController {        public static final int UPDATE_CANCELLED = 99;        /** the meta data retrieval object */    private MetaDataValues metaData;    /** query sender object */    private QuerySender querySender;        /** the connections tree panel */    private ConnectionsTreePanel treePanel;        /** the databse viewer panel */    private BrowserViewPanel viewPanel;    /** the swing worker thread */    private SwingWorker worker;        /** Creates a new instance of BorwserQueryExecuter */    public BrowserController(ConnectionsTreePanel treePanel) {        this.treePanel = treePanel;    }    /**     * Connects/disconnects the specified connection.     *     * @param dc - the conn to connect/disconnect     */    protected void connect(DatabaseConnection dc, boolean reselectRoot) {        try {            if (dc.isConnected()) {                treePanel.setRootSelectOnDisconnect(reselectRoot);                SystemUtilities.disconnect(dc);            } else {                SystemUtilities.connect(dc);            }        } catch (DataSourceException e) {            StringBuffer sb = new StringBuffer();            sb.append("The connection to the database could not be established.");            sb.append("\nPlease ensure all required fields have been entered ");            sb.append("correctly and try again.\n\nThe system returned:\n");            sb.append(e.getExtendedMessage());            GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);        }        finally {            // reset the disconnect selection            treePanel.setRootSelectOnDisconnect(false);        }    }    /**     * Performs the drop database object action.     */    protected void dropSelectedObject() {        try {            // make sure we are not on a type parent object            if (treePanel.isTypeParentSelected()) {                return;            }            DatabaseObject object = treePanel.getSelectedDatabaseObject();            if (object == null) {                return;            }            // display confirmation dialog            int yesNo = GUIUtilities.displayConfirmDialog(                               "Are you sure you want to drop " + object + "?");            if (yesNo == JOptionPane.NO_OPTION) {                return;            }            int result = dropObject(getDatabaseConnection(),                                     object);            if (result >= 0) {                treePanel.removeSelectedNode();            }        }        catch (SQLException e) {            StringBuffer sb = new StringBuffer();            sb.append("An error occurred removing the selected object.").               append("\n\nThe system returned:\n").               append(MiscUtils.formatSQLError(e));            GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);        }            }    /**     * Ensures we have a browser panel and that it is visible.     */    protected void checkBrowserPanel() {        // check we have the browser view panel        if (viewPanel == null) {            viewPanel = new BrowserViewPanel(this);        }        // check the panel is in the pane        JPanel _viewPanel = GUIUtilities.getCentralPane(BrowserViewPanel.TITLE);        if (_viewPanel == null) {            GUIUtilities.addCentralPane(BrowserViewPanel.TITLE,                                        BrowserViewPanel.FRAME_ICON,                                         viewPanel,                                        BrowserViewPanel.TITLE,                                        true);        }         else {            GUIUtilities.setSelectedCentralPane(BrowserViewPanel.TITLE);        }    }    /**     * Saves the connection data to file.     */    public boolean saveConnections() {        return viewPanel.saveConnections();    }    /**     * Informs the view panel of a pending change.     */    protected void selectionChanging() {        if (viewPanel != null) {            viewPanel.selectionChanging();        }    }    /**      * Sets the selected connection tree node to the      * specified database connection.     *     * @param dc - the database connection to select     */    protected void setSelectedConnection(DatabaseConnection dc) {        treePanel.setSelectedConnection(dc, true);    }    /**     * Reloads the database properties meta data table panel.     */    protected void updateDatabaseProperties() {        FormObjectView view = viewPanel.getFormObjectView(HostPanel.NAME);        if (view != null) {            HostPanel panel = (HostPanel)view;            panel.updateDatabaseProperties();        }    }    /**      * Adds a new connection.     */    protected void addNewConnection() {        treePanel.newConnection();    }    /**     * Indicates that a node name has changed and fires a call     * to repaint the tree display.     */    protected void nodeNameValueChanged(ConnectionObject metaObject) {        treePanel.nodeNameValueChanged(metaObject);    }    /**     * Indicates a change in the tree selection value.<br>     * This will determine and builds the object view panel to be     * displayed based on the specified host node connection object     * and the selected node as specified.     *     * @param the connection host parent object     * @param the selected node     */    public synchronized void valueChanged(final ConnectionObject parent,                                           final BrowserTreeNode node,                                          final boolean reload) {        worker = new SwingWorker() {            public Object construct() {                try {                    treePanel.setInProcess(true);                    return buildPanelView(parent, node, reload);                }                finally {                    treePanel.setInProcess(false);                }            }            public void finished() {                try {                    GUIUtilities.showWaitCursor();                    FormObjectView panel = (FormObjectView)get();                    if (panel != null) {                        viewPanel.setView(panel);                        checkBrowserPanel();                    }                } finally {                    GUIUtilities.showNormalCursor();                }            }        };        worker.start();    }    /**     * Determines and builds the object view panel to be     * displayed based on the specified host node connection object     * and the selected node as specified.     *     * @param the connection host parent object     * @param the selected node     */    private FormObjectView buildPanelView(ConnectionObject parent,                                           BrowserTreeNode node,                                           boolean reload) {        // if the parent is null - bail        if (parent == null) {            return null;        }                try {            DatabaseConnection dc = parent.getDatabaseConnection();            DatabaseObject databaseObject = node.getDatabaseUserObject();                        String catalog = parent.isCatalogsInUse() ?                                 databaseObject.getCatalogName() : null;            String schema = databaseObject.getSchemaName();            String name = databaseObject.getName();            // determine the type of selection            int type = databaseObject.getType();                        //Log.debug("Node type selected: " + type);                        switch (type) {                case BrowserConstants.HOST_NODE:                    HostPanel hostPanel = null;                    if (!viewPanel.containsPanel(HostPanel.NAME)) {                        hostPanel = new HostPanel(this);                        viewPanel.addToLayout(hostPanel);                    }                     else {                        hostPanel = (HostPanel)viewPanel.getFormObjectView(HostPanel.NAME);                    }                    hostPanel.setValues(parent);                    return hostPanel;                // catalog node:                // this will display the schema table list                case BrowserConstants.CATALOG_NODE:                    CatalogPanel catalogPanel = null;                    if (!viewPanel.containsPanel(CatalogPanel.NAME)) {                        catalogPanel = new CatalogPanel(this);                        viewPanel.addToLayout(catalogPanel);                    }                     else {                        catalogPanel = (CatalogPanel)viewPanel.getFormObjectView(CatalogPanel.NAME);                    }                    catalogPanel.setValues(name, getCatalogSchemas(dc));                    return catalogPanel;                case BrowserConstants.SCHEMA_NODE:                    SchemaPanel schemaPanel = null;                    if (!viewPanel.containsPanel(SchemaPanel.NAME)) {                        schemaPanel = new SchemaPanel(this);                        viewPanel.addToLayout(schemaPanel);                    }                     else {                        schemaPanel = (SchemaPanel)viewPanel.getFormObjectView(SchemaPanel.NAME);                    }                    schemaPanel.selected(parent, databaseObject);                    return schemaPanel;                                }                        // if not a leaf node            if (!node.isLeaf()) {                            // if its a system object - need a meta table display                if (databaseObject.isSystemObject()) {                                        // use the same meta panel                                        MetaKeyPanel metaKeyPanel = null;                    if (!viewPanel.containsPanel(MetaKeyPanel.NAME)) {                        metaKeyPanel = new MetaKeyPanel(this);                        viewPanel.addToLayout(metaKeyPanel);                    }                     else {                        metaKeyPanel = (MetaKeyPanel)viewPanel.getFormObjectView(MetaKeyPanel.NAME);                    }                    String[] values = null;                    switch (type) {                        case BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE:                            values = getSystemFunctions(dc,MetaDataValues.STRING_FUNCTIONS);                            break;                        case BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE:                            values = getSystemFunctions(dc,MetaDataValues.NUMERIC_FUNCTIONS);                            break;                        case BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE:                            values = getSystemFunctions(dc,MetaDataValues.TIME_DATE_FUNCTIONS);                            break;                    }                    metaKeyPanel.setValues(name, values);                    return metaKeyPanel;                }                // if its a meta parent node                else if (node.isTypeParent()) {                    MetaKeyPanel metaKeyPanel = null;                    if (!viewPanel.containsPanel(MetaKeyPanel.NAME)) {                        metaKeyPanel = new MetaKeyPanel(this);                        viewPanel.addToLayout(metaKeyPanel);                    }                     else {                        metaKeyPanel = (MetaKeyPanel)viewPanel.getFormObjectView(MetaKeyPanel.NAME);                    }                    // TODO: don't think this is using a cache!!!                    // if its the system function node - just add the functions types                    if (type == BrowserConstants.SYSTEM_FUNCTION_NODE) {                        String[] values = {"String Functions",                                            "Numeric Functions",                                            "Date/Time Functions"};                        metaKeyPanel.setValues(name, values);                        return metaKeyPanel;                    }                    if (!metaKeyPanel.hasObject(databaseObject)) {                        String[] values = getTables(dc, catalog, schema, name);                        // if we have no values here - see if proc or function                        if (values == null || values.length == 0) {                            values = checkProcedureTerm(dc, databaseObject);                        }                        metaKeyPanel.setValues(name, values);                    }                    else {                                        metaKeyPanel.setValues(name);                    }                    return metaKeyPanel;                }            }            // if we have nothing here - must be a specific type            switch (type) {                case BrowserConstants.FUNCTIONS_NODE:                case BrowserConstants.PROCEDURE_NODE:                case BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE:

⌨️ 快捷键说明

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