Search in sources :

Example 6 with DatabaseStructureView

use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.

the class FilterStructureAction method run.

public void run() {
    try {
        DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
        FilterStructureDialog dialog = new FilterStructureDialog();
        Session session = view.getSession();
        if (session == null)
            return;
        Alias alias = session.getUser().getAlias();
        if (alias.getSchemaFilterExpression() != null && alias.getSchemaFilterExpression().length() != 0) {
            dialog.setSchemaFilter(alias.getSchemaFilterExpression().split(","));
        }
        if (alias.getFolderFilterExpression() != null && alias.getFolderFilterExpression().length() != 0) {
            dialog.setFolderFilter(alias.getFolderFilterExpression().split(","));
        }
        if (alias.getNameFilterExpression() != null && alias.getNameFilterExpression().length() != 0) {
            dialog.setNameFilter(alias.getNameFilterExpression());
        }
        if (dialog.open() != Window.OK) {
            return;
        }
        String[] schemaFilter = dialog.getSchemaFilter();
        StringBuffer schemaFilterString = new StringBuffer("");
        String sep = "";
        if (schemaFilter != null) {
            for (int i = 0; i < schemaFilter.length; i++) {
                schemaFilterString.append(sep);
                schemaFilterString.append(schemaFilter[i]);
                sep = ",";
            }
        }
        alias.setSchemaFilterExpression(schemaFilterString.toString());
        String[] folderFilter = dialog.getFolderFilter();
        StringBuffer folderFilterString = new StringBuffer("");
        sep = "";
        if (folderFilter != null) {
            for (int i = 0; i < folderFilter.length; i++) {
                folderFilterString.append(sep);
                folderFilterString.append(folderFilter[i]);
                sep = ",";
            }
        }
        alias.setFolderFilterExpression(folderFilterString.toString());
        alias.setNameFilterExpression(dialog.getNameFilter());
        view.refreshSessionTrees(view.getSession());
    } catch (Exception e) {
        SQLExplorerPlugin.error("Error creating dialog", e);
    }
}
Also used : Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) FilterStructureDialog(net.sourceforge.sqlexplorer.dialogs.FilterStructureDialog) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 7 with DatabaseStructureView

use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.

the class RefreshNodeAction method run.

/**
 * Refresh selected node and descendants.
 * @see org.eclipse.jface.action.IAction#run()
 */
public void run() {
    // clear cache for all nodes
    for (int i = 0; i < _selectedNodes.length; i++) {
        if (_selectedNodes[i] instanceof DatabaseNode) {
            // clear detail cache for session
            DetailTabManager.clearCacheForSession(_selectedNodes[i].getSession());
            break;
        } else {
            // clear detail cache for node.
            DetailTabManager.clearCacheForNode(_selectedNodes[i]);
        }
    }
    // refresh nodes
    for (int i = 0; i < _selectedNodes.length; i++) {
        _selectedNodes[i].refresh();
    }
    // refresh structure view
    DatabaseStructureView structureView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
    _treeViewer.refresh();
    // refresh detail view
    DatabaseDetailView detailView = (DatabaseDetailView) SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
    structureView.synchronizeDetailView(detailView);
}
Also used : DatabaseNode(net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode) DatabaseDetailView(net.sourceforge.sqlexplorer.plugin.views.DatabaseDetailView) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)

Example 8 with DatabaseStructureView

use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.

the class SqlexplorerService method findSqlExplorerTableNode.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.service.ISqlexplorerService#findSqlExplorerTableNode(org.talend.core.model.metadata.builder
     * .connection.Connection, orgomg.cwm.objectmodel.core.Package, java.lang.String, java.lang.String)
     */
@Override
public void findSqlExplorerTableNode(Connection providerConnection, Package parentPackageElement, String tableName, String activeTabName) {
    // Open data explore perspective.
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
        ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
        if (service != null) {
            service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
        } else {
            return;
        }
    }
    Collection<Alias> aliases = SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
    String url = JavaSqlFactory.getURL(providerConnection);
    User currentUser = null;
    for (Alias alias : aliases) {
        if (alias.getUrl().equals(url)) {
            currentUser = alias.getDefaultUser();
            OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, alias.getDefaultUser(), false);
            openDlgAction.run();
            break;
        }
    }
    // MOD qiongli bug 13093,2010-7-2,show the warning dialog when the table can't be found
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (currentUser == null) {
        // $NON-NLS-1$
        MessageDialog.openWarning(// $NON-NLS-1$
        shell, // $NON-NLS-1$
        Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
        Messages.getString("SqlExplorerBridge.MissTable") + tableName);
        return;
    }
    DatabaseNode root = currentUser.getMetaDataSession().getRoot();
    root.load();
    List<INode> catalogs = root.getCatalogs();
    List<INode> schemas = root.getSchemas();
    Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
    Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
    INode catalogOrSchemaNode = null;
    // TDQ-12005: fix Exasol/hive(TDQ-11887: hdp20 at least) database can view index/keys well
    String findCatalogNodeName = isExasol(url) ? "EXA_DB" : (isHive(url) ? "NoCatalog" : "");
    if (!findCatalogNodeName.equals("") && !catalogs.isEmpty()) {
        for (INode catalogNode : catalogs) {
            if (findCatalogNodeName.equalsIgnoreCase(catalogNode.getName())) {
                catalogOrSchemaNode = catalogNode;
                break;
            }
        }
    } else {
        if (catalog != null) {
            // MOD klliu bug 14662 2010-08-05
            if (!catalogs.isEmpty()) {
                for (INode catalogNode : catalogs) {
                    if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
                        catalogOrSchemaNode = catalogNode;
                        break;
                    }
                }
            } else {
                catalogOrSchemaNode = root;
            }
        } else {
            // MOD by zshen for 20517
            if (schemas.isEmpty()) {
                // the case for mssql/postgrel(which have catalog and schema structor) schema analysis.
                Catalog shcmeaOfCatalogNode = CatalogHelper.getParentCatalog(parentPackageElement);
                for (INode catalogNode : catalogs) {
                    if (shcmeaOfCatalogNode != null && shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
                        catalogOrSchemaNode = catalogNode;
                        break;
                    }
                }
            }
            for (INode schemaNode : schemas) {
                if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
                    catalogOrSchemaNode = schemaNode;
                    break;
                }
            }
        }
    }
    // find the table folder node.
    if (catalogOrSchemaNode == null) {
        // $NON-NLS-1$
        throw new NullPointerException(Messages.getString("SqlExplorerBridge.CATORSCHMISNULL"));
    }
    // catalog node.
    if (schema != null) {
        if (catalogOrSchemaNode.getSchemaName() == null) {
            catalogOrSchemaNode.setSchemaName(schema.getName());
        } else if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(), schema.getName())) {
            // if this catalog already loaded its children of some schema, should reload for this schema.
            if (catalogOrSchemaNode.isChildrenLoaded()) {
                SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
                List<INode> catalogs2 = currentUser.getMetaDataSession().getRoot().getCatalogs();
                if (catalogs2.size() != 0) {
                    for (INode catalogNode : catalogs2) {
                        if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
                            catalogOrSchemaNode = catalogNode;
                            catalogOrSchemaNode.setSchemaName(schema.getName());
                            break;
                        }
                    }
                }
            }
        }
    }
    // ~
    INode[] childNodes = catalogOrSchemaNode.getChildNodes();
    // need to find the schema and load the table nodes
    if (isNetezza(url)) {
        SchemaNode sNode = getNetezzaSchema(childNodes, JavaSqlFactory.getUsername(providerConnection));
        if (sNode != null) {
            childNodes = sNode.getChildNodes();
        }
    }
    TableFolderNode tableFolderNode = null;
    for (INode node : childNodes) {
        if ("TABLE".equals(node.getQualifiedName())) {
            // $NON-NLS-1$
            tableFolderNode = (TableFolderNode) node;
            break;
        }
    }
    if (tableFolderNode == null) {
        // $NON-NLS-1$
        log.fatal(Messages.getString("SqlExplorerBridge.TABLE_FOLDER_NULL0"));
    } else {
        INode[] tableNodes = tableFolderNode.getChildNodes();
        for (INode node : tableNodes) {
            if (tableName.equalsIgnoreCase(node.getName())) {
                DetailTabManager.setActiveTabName(activeTabName);
                DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
                dsView.setSessionSelectionNode(currentUser.getMetaDataSession(), new StructuredSelection(node));
                // MOD qiongli bug 13093,2010-7-2
                SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
                return;
            }
        }
    }
    // $NON-NLS-1$
    MessageDialog.openWarning(// $NON-NLS-1$
    shell, // $NON-NLS-1$
    Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
    Messages.getString("SqlExplorerBridge.MissTable") + tableName);
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) User(net.sourceforge.sqlexplorer.dbproduct.User) ITDQRepositoryService(org.talend.core.ITDQRepositoryService) Schema(orgomg.cwm.resource.relational.Schema) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) OpenPasswordConnectDialogAction(net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction) Catalog(orgomg.cwm.resource.relational.Catalog) TableFolderNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode) SchemaNode(net.sourceforge.sqlexplorer.dbstructure.nodes.SchemaNode) Shell(org.eclipse.swt.widgets.Shell) DatabaseNode(net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLExplorerPluginPerspective(net.sourceforge.sqlexplorer.plugin.perspectives.SQLExplorerPluginPerspective) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)

Example 9 with DatabaseStructureView

use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.

the class SQLExplorerPlugin method startDefaultConnections.

/**
 * Open all connections that have the 'open on startup property'. This method should be called from within the UI
 * thread!
 */
public void startDefaultConnections(ConnectionsView connectionsView) {
    this.connectionsView = connectionsView;
    if (_defaultConnectionsStarted) {
        return;
    }
    String fontDesc = getPluginPreferences().getString(IConstants.FONT);
    FontData fontData = null;
    try {
        try {
            fontData = new FontData(fontDesc);
        } catch (IllegalArgumentException e) {
            fontData = new FontData("1|Courier New|10|0|WINDOWS|1|-13|0|0|0|400|0|0|0|0|3|2|1|49|Courier New");
        }
        PreferenceConverter.setValue(getPreferenceStore(), IConstants.FONT, fontData);
    } catch (IllegalArgumentException e) {
        error("Error setting font", e);
    }
    boolean openEditor = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.AUTO_OPEN_EDITOR);
    // Get the database structure view - NOTE: we don't use SQLExplorerPlugin.getDatabaseView()
    // because it may not have an active page yet
    DatabaseStructureView dbView = null;
    IWorkbenchSite site = connectionsView.getSite();
    if (site.getPage() != null) {
        dbView = (DatabaseStructureView) site.getPage().findView(DatabaseStructureView.class.getName());
    }
    for (Alias alias : aliasManager.getAliases()) {
        if (alias.isConnectAtStartup() && alias.isAutoLogon() && alias.getDefaultUser() != null) {
            if (dbView != null) {
                try {
                    dbView.addUser(alias.getDefaultUser());
                } catch (SQLCannotConnectException e) {
                // Ignore it; the problem is already in the log, we do not want to delay startup, and the
                // problem will
                // be apparent as soon as the user tries to use the connection
                }
            }
            if (openEditor) {
                SQLEditorInput input = new SQLEditorInput(SQL_EDITOR + SQLExplorerPlugin.getDefault().getEditorSerialNo() + SQL);
                input.setUser(alias.getDefaultUser());
                try {
                    site.getPage().openEditor(input, SQLEditor.class.getName());
                } catch (PartInitException e) {
                    SQLExplorerPlugin.error("Cannot open SQL editor", e);
                }
            }
        }
    }
    _defaultConnectionsStarted = true;
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) FontData(org.eclipse.swt.graphics.FontData) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) PartInitException(org.eclipse.ui.PartInitException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Aggregations

DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)9 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)5 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)4 PartInitException (org.eclipse.ui.PartInitException)3 MalformedURLException (java.net.MalformedURLException)2 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)2 Session (net.sourceforge.sqlexplorer.dbproduct.Session)2 User (net.sourceforge.sqlexplorer.dbproduct.User)2 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)2 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)1 SessionEstablishedListener (net.sourceforge.sqlexplorer.connections.SessionEstablishedListener)1 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)1 SchemaNode (net.sourceforge.sqlexplorer.dbstructure.nodes.SchemaNode)1 TableFolderNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableFolderNode)1