Search in sources :

Example 21 with DBConnectionRepNode

use of org.talend.dq.nodes.DBConnectionRepNode in project tdq-studio-se by Talend.

the class SetJDBCDriverPreferencePage method createConnSelectDialog.

private CheckedTreeSelectionDialog createConnSelectDialog() {
    RepositoryNode node = (RepositoryNode) RepositoryNodeHelper.getMetadataFolderNode(EResourceConstant.DB_CONNECTIONS);
    CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(getShell(), new DQRepositoryViewLabelProvider(), new ResourceViewContentProvider());
    dialog.setInput(node);
    dialog.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof DBConnectionRepNode) {
                return isJdbcConnectionNode((DBConnectionRepNode) element);
            } else if (element instanceof DBConnectionSubFolderRepNode) {
                return hasJdbcConnNodeChild((DBConnectionSubFolderRepNode) element);
            }
            return false;
        }
    });
    dialog.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            for (Object object : selection) {
                if (object instanceof DBConnectionRepNode) {
                    IRepositoryViewObject nodeObject = ((DBConnectionRepNode) object).getObject();
                    // when it's locked, can not modify
                    if (nodeObject != null && nodeObject.getProperty() != null && nodeObject.getProperty().getItem() != null && (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER || nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_USER || RepositoryManager.isOpenedItemInEditor(nodeObject))) {
                        String displayName = nodeObject.getProperty().getDisplayName();
                        String version = nodeObject.getProperty().getVersion();
                        return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.isLocked", // $NON-NLS-1$ //$NON-NLS-2$
                        displayName + " " + version));
                    }
                }
            }
            return new // $NON-NLS-1$
            Status(// $NON-NLS-1$
            IStatus.OK, // $NON-NLS-1$
            PlatformUI.PLUGIN_ID, // $NON-NLS-1$
            IStatus.OK, // $NON-NLS-1$
            "", null);
        }
    });
    dialog.setContainerMode(true);
    // $NON-NLS-1$
    dialog.setTitle(DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.selectConnectionButton"));
    // $NON-NLS-1$
    dialog.setMessage(DefaultMessagesImpl.getString("SetJDBCDriverPreferencePage.ApplytoConnectionEditors"));
    dialog.setSize(80, 30);
    return dialog;
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) ResourceViewContentProvider(org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider) Viewer(org.eclipse.jface.viewers.Viewer) DBConnectionSubFolderRepNode(org.talend.dq.nodes.DBConnectionSubFolderRepNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) DQRepositoryViewLabelProvider(org.talend.dataprofiler.core.ui.views.provider.DQRepositoryViewLabelProvider)

Example 22 with DBConnectionRepNode

use of org.talend.dq.nodes.DBConnectionRepNode in project tdq-studio-se by Talend.

the class AbstractCommonActionProviderRealProjectTest method testGetConnectionCase3.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.action.provider.AbstractCommonActionProvider#getConnection(java.lang.Object)}
 * . case3 :input parameter is DBConnectionRepNode
 */
@Test
public void testGetConnectionCase3() {
    // create FileConnection
    // connection
    IRepositoryViewObject lastVersion = null;
    String propertyID = createConnectionItem(connectionName, null, null);
    try {
        lastVersion = factory.getLastVersion(propertyID);
    } catch (PersistenceException e) {
        log.error(e, e);
        Assert.fail(e.getMessage());
    }
    // ~connection data
    // ~FileConnection
    // create DFColumnFolderRepNode
    Assert.assertFalse(lastVersion == null);
    DBConnectionRepNode dbConnRepNode = new DBConnectionRepNode(lastVersion, null, null, null);
    // ~DFColumnFolderRepNode
    AbstractCommonActionProvider provider = new AbstractCommonActionProvider();
    Connection connection = provider.getConnection(dbConnRepNode);
    Assert.assertTrue(connection != null);
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Test(org.junit.Test)

Example 23 with DBConnectionRepNode

use of org.talend.dq.nodes.DBConnectionRepNode in project tdq-studio-se by Talend.

the class AbstractCommonActionProviderTest method createConnectionNode.

private RepositoryNode createConnectionNode(String name, IFolder folder, boolean isDelete) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    // connection
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.setName(name);
    // $NON-NLS-1$
    createConnection.setUsername("UserName");
    // $NON-NLS-1$
    createConnection.setRawPassword("Password");
    // $NON-NLS-1$
    createConnection.setURL("URL");
    createConnection.setDatabaseType(EDatabaseTypeName.MYSQL.getXmlName());
    createConnection.setContextMode(true);
    // ~connection
    DatabaseConnectionItem createDatabaseConnectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
    org.talend.core.model.properties.Property createDatabaseConnectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    createDatabaseConnectionProperty.setId(EcoreUtil.generateUUID());
    createDatabaseConnectionProperty.setItem(createDatabaseConnectionItem);
    createDatabaseConnectionProperty.setLabel(createConnection.getName());
    createDatabaseConnectionItem.setProperty(createDatabaseConnectionProperty);
    createDatabaseConnectionItem.setConnection(createConnection);
    ItemState createItemState = PropertiesFactory.eINSTANCE.createItemState();
    createItemState.setDeleted(isDelete);
    createDatabaseConnectionItem.setState(createItemState);
    IRepositoryViewObject repViewObject = null;
    try {
        factory.create(createDatabaseConnectionItem, createPath, false);
        repViewObject = factory.getLastVersion(createDatabaseConnectionProperty.getId());
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    RepositoryNode dbConnRepNode = new DBConnectionRepNode(repViewObject, null, ENodeType.TDQ_REPOSITORY_ELEMENT, null);
    return dbConnRepNode;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) IPath(org.eclipse.core.runtime.IPath) RepositoryNode(org.talend.repository.model.RepositoryNode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 24 with DBConnectionRepNode

use of org.talend.dq.nodes.DBConnectionRepNode in project tdq-studio-se by Talend.

the class SchemaAnalysisDPSelectionPage method addListeners.

@Override
protected void addListeners() {
    addListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            Object object = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (object instanceof Schema) {
                advanceToNextPageOrFinish();
            }
        }
    });
    addListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            Object object = ((IStructuredSelection) event.getSelection()).getFirstElement();
            PackagesAnalyisParameter schemaPanameter = (PackagesAnalyisParameter) getConnectionParams();
            List<IRepositoryNode> nodes = new ArrayList<IRepositoryNode>();
            if (object instanceof DBSchemaRepNode) {
                DBSchemaRepNode schemaNode = (DBSchemaRepNode) object;
                Schema schema = ((MetadataSchemaRepositoryObject) schemaNode.getObject()).getSchema();
                Connection tdProvider = ConnectionHelper.getTdDataProvider(SwitchHelpers.PACKAGE_SWITCH.doSwitch(schema));
                RepositoryNode parent = schemaNode.getParent();
                if (tdProvider != null && schemaPanameter != null) {
                    if (parent instanceof DBCatalogRepNode) {
                        schemaPanameter.setConnectionRepNode((DBConnectionRepNode) parent.getParent());
                    } else {
                        schemaPanameter.setConnectionRepNode((DBConnectionRepNode) parent);
                    }
                    schemaPanameter.setTdDataProvider(tdProvider);
                }
                nodes.add(schemaNode);
                schemaPanameter.setPackages(nodes);
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) DBSchemaRepNode(org.talend.dq.nodes.DBSchemaRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Schema(orgomg.cwm.resource.relational.Schema) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Connection(org.talend.core.model.metadata.builder.connection.Connection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) DBCatalogRepNode(org.talend.dq.nodes.DBCatalogRepNode) PackagesAnalyisParameter(org.talend.dq.analysis.parameters.PackagesAnalyisParameter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MetadataSchemaRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataSchemaRepositoryObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with DBConnectionRepNode

use of org.talend.dq.nodes.DBConnectionRepNode in project tdq-studio-se by Talend.

the class ConnAnalysisDPSelectionPage method addListeners.

@Override
protected void addListeners() {
    addListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            Object object = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (object instanceof IFile) {
                IFile file = (IFile) object;
                if (file.getParent() != null) {
                    advanceToNextPageOrFinish();
                }
            }
        }
    });
    addListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            // get the dataprovider from the seleted connection
            Object object = ((IStructuredSelection) event.getSelection()).getFirstElement();
            AnalysisFilterParameter connPanameter = (AnalysisFilterParameter) getConnectionParams();
            if (object instanceof DBConnectionRepNode) {
                DBConnectionRepNode connNode = (DBConnectionRepNode) object;
                IRepositoryViewObject reposViewObj = connNode.getObject();
                Connection connection = ((ConnectionItem) reposViewObj.getProperty().getItem()).getConnection();
                if (connection != null && connPanameter != null) {
                    connPanameter.setTdDataProvider(connection);
                    connPanameter.setConnectionRepNode(connNode);
                }
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) IFile(org.eclipse.core.resources.IFile) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Connection(org.talend.core.model.metadata.builder.connection.Connection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) AnalysisFilterParameter(org.talend.dq.analysis.parameters.AnalysisFilterParameter)

Aggregations

DBConnectionRepNode (org.talend.dq.nodes.DBConnectionRepNode)26 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 IRepositoryNode (org.talend.repository.model.IRepositoryNode)12 DBCatalogRepNode (org.talend.dq.nodes.DBCatalogRepNode)9 Connection (org.talend.core.model.metadata.builder.connection.Connection)8 DBSchemaRepNode (org.talend.dq.nodes.DBSchemaRepNode)8 RepositoryNode (org.talend.repository.model.RepositoryNode)8 ArrayList (java.util.ArrayList)6 DBTableRepNode (org.talend.dq.nodes.DBTableRepNode)6 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)4 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)4 DBConnectionFolderRepNode (org.talend.dq.nodes.DBConnectionFolderRepNode)4 DFConnectionRepNode (org.talend.dq.nodes.DFConnectionRepNode)4 List (java.util.List)3 Test (org.junit.Test)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3