Search in sources :

Example 6 with ITDQRepositoryService

use of org.talend.core.ITDQRepositoryService 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 7 with ITDQRepositoryService

use of org.talend.core.ITDQRepositoryService in project tdq-studio-se by Talend.

the class SQLTextEditor method createIFile.

/**
 * DOC qzhang Comment method "createIFile".
 *
 * @param monitor
 * @param file
 * @param content
 * @throws CoreException
 */
private IFile createIFile(IFile file, String content) throws CoreException {
    // MOD qiongli 2011-4-21.bug 20205 .should create sql file and property.use extension of service mechanism.
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
        ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
        if (service != null) {
            String fName = StringUtils.removeEnd(StringUtils.removeEnd(file.getName(), DEFAULT_FILE_EXTENSION), DEFAULT_VERSION_STRING);
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IPath rootPath = new Path("TDQ_Libraries/Source Files");
            Item item = service.createFile(content, file.getProjectRelativePath().removeLastSegments(1).makeRelativeTo(rootPath), fName, file.getFileExtension());
            // get the correct path(contain version info) for newInput file in editor.
            IPath location = file.getLocation();
            if (item != null && item.getProperty() != null && location != null) {
                location = location.removeLastSegments(1);
                StringBuffer strb = new StringBuffer();
                strb.append(location.toString());
                String version = item.getProperty().getVersion() == null ? "" : "_" + item.getProperty().getVersion();
                strb.append(Path.SEPARATOR).append(fName).append(version).append(DEFAULT_FILE_EXTENSION);
                location = Path.fromOSString(strb.toString());
                file = workspace.getRoot().getFileForLocation(location);
            }
        }
    }
    return file;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Item(org.talend.core.model.properties.Item) ITDQRepositoryService(org.talend.core.ITDQRepositoryService) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 8 with ITDQRepositoryService

use of org.talend.core.ITDQRepositoryService in project tdq-studio-se by Talend.

the class ConnectionTypePage method getNextPage.

@Override
public IWizardPage getNextPage() {
    RepositoryNode node = null;
    IWizard nextWizard = null;
    // make the next wizard do not open the created connection
    ITDQRepositoryService tdqRepService = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
    tdqRepService.setIsOpenConnectionEditorAfterCreate(Boolean.TRUE);
    int selectionIndex = connectionType.getSelectionIndex();
    switch(selectionIndex) {
        case // db
        0:
            node = (RepositoryNode) RepositoryNodeHelper.getMetadataFolderNode(EResourceConstant.DB_CONNECTIONS);
            nextWizard = new DatabaseWizard(PlatformUI.getWorkbench(), true, node, null);
            break;
        case // file
        1:
            node = (RepositoryNode) RepositoryNodeHelper.getMetadataFolderNode(EResourceConstant.FILEDELIMITED);
            nextWizard = new DelimitedFileWizard(PlatformUI.getWorkbench(), true, node, null);
            break;
        default:
            break;
    }
    WizardDialog dialog = new WizardDialog(null, nextWizard);
    dialog.setPageSize(550, 550);
    if (WizardDialog.OK == dialog.open()) {
        publishSelectDataEvent(nextWizard, tdqRepService);
    }
    // make it back to initial value if cancel it
    tdqRepService.setIsOpenConnectionEditorAfterCreate(Boolean.FALSE);
    return null;
}
Also used : ITDQRepositoryService(org.talend.core.ITDQRepositoryService) DatabaseWizard(org.talend.repository.ui.wizards.metadata.connection.database.DatabaseWizard) IWizard(org.eclipse.jface.wizard.IWizard) RepositoryNode(org.talend.repository.model.RepositoryNode) DelimitedFileWizard(org.talend.repository.ui.wizards.metadata.connection.files.delimited.DelimitedFileWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 9 with ITDQRepositoryService

use of org.talend.core.ITDQRepositoryService in project tdq-studio-se by Talend.

the class ApplicationWorkbenchWindowAdvisor method postWindowOpen.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen()
     */
@SuppressWarnings("restriction")
@Override
public void postWindowOpen() {
    this.getWindowConfigurer().getWindow().getShell().setMaximized(true);
    super.postWindowOpen();
    ChangePerspectiveAction.getAction().switchTitle();
    IWorkbenchWindowConfigurer workbenchWindowConfigurer = getWindowConfigurer();
    // hide Preference page
    PreferenceManager preferenceManager = workbenchWindowConfigurer.getWindow().getWorkbench().getPreferenceManager();
    preferenceManager.remove("org.eclipse.debug.ui.DebugPreferencePage" + WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR + "org.eclipse.ui.externaltools.ExternalToolsPreferencePage");
    // hide toolBar item
    IActionBarConfigurer actionBarConfigurer = workbenchWindowConfigurer.getActionBarConfigurer();
    ICoolBarManager coolBarManager = actionBarConfigurer.getCoolBarManager();
    IContributionItem toolBarItem = coolBarManager.find("org.eclipse.debug.ui.launchActionSet");
    if (toolBarItem != null) {
        coolBarManager.remove(toolBarItem);
    }
    // hide run menu
    // hide Help->Install New Software and Help->Check For Updates
    // hide File->Open File...
    IMenuManager menuManager = actionBarConfigurer.getMenuManager();
    IContributionItem[] menuItems = menuManager.getItems();
    for (IContributionItem menuItem : menuItems) {
        // Hack to remove the Navigate menu -which can't be removed by "org.eclipse.ui.activities
        if ("org.eclipse.ui.run".equals(menuItem.getId()) || "navigate".equals(menuItem.getId())) {
            // $NON-NLS-1$//$NON-NLS-2$
            menuManager.remove(menuItem);
        }
        if ("file".equals(menuItem.getId())) {
            // $NON-NLS-1$
            hideFileActions(menuItem);
        }
        if ("help".equals(menuItem.getId())) {
            // $NON-NLS-1$
            hideHelpActions(menuItem);
        }
    }
    ITDQRepositoryService tdqRepositoryService = (ITDQRepositoryService) org.talend.core.GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
    if (tdqRepositoryService != null) {
        tdqRepositoryService.addPartListener();
        tdqRepositoryService.addSoftwareSystemUpdateListener();
    }
}
Also used : ITDQRepositoryService(org.talend.core.ITDQRepositoryService) IContributionItem(org.eclipse.jface.action.IContributionItem) IWorkbenchWindowConfigurer(org.eclipse.ui.application.IWorkbenchWindowConfigurer) IMenuManager(org.eclipse.jface.action.IMenuManager) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IActionBarConfigurer(org.eclipse.ui.application.IActionBarConfigurer) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Aggregations

ITDQRepositoryService (org.talend.core.ITDQRepositoryService)9 ArrayList (java.util.ArrayList)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)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 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)1 SQLExplorerPluginPerspective (net.sourceforge.sqlexplorer.plugin.perspectives.SQLExplorerPluginPerspective)1 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1