Search in sources :

Example 1 with ENodeType

use of org.talend.repository.model.IRepositoryNode.ENodeType in project tdi-studio-se by Talend.

the class DetecteViewImpactAction method init.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.commons.ui.swt.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
     * org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    // try to check via extension point first.
    boolean canWork = UpdateManagerProviderDetector.INSTANCE.validateAction(viewer, selection);
    if (canWork) {
        setEnabled(true);
        return;
    }
    canWork = !selection.isEmpty() && selection.size() == 1;
    if (canWork) {
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (factory.isUserReadOnlyOnCurrentProject()) {
            canWork = false;
        } else {
            Object o = selection.getFirstElement();
            RepositoryNode node = (RepositoryNode) o;
            ENodeType nodeType = node.getType();
            switch(nodeType) {
                case REPOSITORY_ELEMENT:
                    ERepositoryObjectType objectType = node.getObjectType();
                    /*
                     * TESB-6415 if it's "CAMEL" product, then is disable
                     */
                    if (objectType != null) {
                        String[] products = objectType.getProducts();
                        if (products != null && products.length == 1 && "CAMEL".equals(products[0])) {
                            setEnabled(false);
                            return;
                        }
                    }
                    if (objectType == ERepositoryObjectType.METADATA_CON_TABLE) {
                        IRepositoryViewObject repositoryObject = node.getObject();
                        if (repositoryObject != null) {
                            Item item2 = repositoryObject.getProperty().getItem();
                            if (item2 instanceof DatabaseConnectionItem) {
                                DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
                                DatabaseConnection connection = (DatabaseConnection) item.getConnection();
                                CDCConnection cdcConns = connection.getCdcConns();
                                if (cdcConns != null) {
                                    if (repositoryObject instanceof MetadataTableRepositoryObject) {
                                        MetadataTable table = ((MetadataTableRepositoryObject) repositoryObject).getTable();
                                        String tableType = table.getTableType();
                                        canWork = RepositoryConstants.TABLE.equals(tableType);
                                        break;
                                    }
                                }
                            }
                        }
                        canWork = true;
                    } else if (objectType == ERepositoryObjectType.METADATA_CON_QUERY || objectType == ERepositoryObjectType.METADATA_CONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_DELIMITED || objectType == ERepositoryObjectType.METADATA_FILE_POSITIONAL || objectType == ERepositoryObjectType.METADATA_FILE_REGEXP || objectType == ERepositoryObjectType.METADATA_FILE_XML || objectType == ERepositoryObjectType.METADATA_FILE_LDIF || objectType == ERepositoryObjectType.METADATA_FILE_EXCEL || objectType == ERepositoryObjectType.METADATA_SAPCONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_EBCDIC || objectType == ERepositoryObjectType.METADATA_FILE_HL7 || objectType == ERepositoryObjectType.METADATA_VALIDATION_RULES || objectType == ERepositoryObjectType.METADATA_FILE_FTP || objectType == ERepositoryObjectType.METADATA_FILE_BRMS || objectType == ERepositoryObjectType.METADATA_MDMCONNECTION || objectType == ERepositoryObjectType.CONTEXT || objectType == ERepositoryObjectType.JOBLET) {
                        canWork = true;
                    } else if (objectType == ERepositoryObjectType.BUSINESS_PROCESS || objectType == ERepositoryObjectType.PROCESS || objectType == ERepositoryObjectType.ROUTINES || objectType == ERepositoryObjectType.PIG_UDF || objectType == ERepositoryObjectType.JOB_SCRIPT || objectType == ERepositoryObjectType.SQLPATTERNS || objectType == ERepositoryObjectType.JOB_DOC || objectType == ERepositoryObjectType.JOBLET_DOC || objectType == ERepositoryObjectType.DOCUMENTATION || objectType == ERepositoryObjectType.PROCESS_MR || objectType == ERepositoryObjectType.METADATA_CON_COLUMN || (ERepositoryObjectType.TEST_CONTAINER != null && objectType == ERepositoryObjectType.TEST_CONTAINER)) {
                        canWork = false;
                    } else {
                        Object obj = selection.getFirstElement();
                        RepositoryNode nodeObj = (RepositoryNode) obj;
                        Item item = nodeObj.getObject().getProperty().getItem();
                        if (item instanceof ConnectionItem) {
                            if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                                IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
                                if (service != null) {
                                    boolean flag = service.isServiceItem(item.eClass().getClassifierID());
                                    if (flag) {
                                        canWork = false;
                                        break;
                                    }
                                }
                            }
                        }
                        for (IRepositoryContentHandler handler : RepositoryContentManager.getHandlers()) {
                            ERepositoryObjectType stype = handler.getRepositoryObjectType(item);
                            if (stype == objectType) {
                                canWork = true;
                                break;
                            }
                        }
                        if (RepositoryContentManager.getHandlers().size() < 0) {
                            canWork = false;
                        }
                    }
                    break;
                default:
                    canWork = false;
            }
            RepositoryNode parent = node.getParent();
            if (canWork && parent != null && parent.isBin()) {
                canWork = false;
            }
            if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
                canWork = false;
            }
        }
    }
    setEnabled(canWork);
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryContentHandler(org.talend.core.model.repository.IRepositoryContentHandler) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IESBService(org.talend.core.IESBService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 2 with ENodeType

use of org.talend.repository.model.IRepositoryNode.ENodeType in project tdi-studio-se by Talend.

the class DatabaseTypeFilter method select.

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (text == null || text.equals("")) {
        //$NON-NLS-1$
        return true;
    }
    RepositoryNode node = (RepositoryNode) element;
    ENodeType nodeType = node.getType();
    if (nodeType == ENodeType.STABLE_SYSTEM_FOLDER || nodeType == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    if (nodeType != ENodeType.REPOSITORY_ELEMENT) {
        List<IRepositoryNode> children = node.getChildren();
        if (children.isEmpty()) {
            return false;
        }
        for (IRepositoryNode child : children) {
            if (select(viewer, null, child)) {
                return true;
            }
        }
        return false;
    }
    final IRepositoryViewObject object = node.getObject();
    if (object != null) {
        String name = object.getProperty().getLabel();
        if (name != null) {
            return name.matches(text);
        }
    }
    // always
    return true;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType)

Example 3 with ENodeType

use of org.talend.repository.model.IRepositoryNode.ENodeType in project tdi-studio-se by Talend.

the class UseDynamicJobSelectionDialog method createTreeViewer.

private void createTreeViewer(Composite itemComposite) {
    filteredCheckboxTree = new FilteredCheckboxTree(itemComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI) {

        @Override
        protected CheckboxTreeViewer doCreateTreeViewer(Composite parent, int style) {
            return (CheckboxTreeViewer) RepoCommonViewerProvider.CHECKBOX.createViewer(parent);
        }

        @Override
        protected void refreshCompleted() {
            restoreCheckedElements();
        }
    };
    CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
    viewer.setComparer(new IElementComparer() {

        private String getElementUniqueString(Object element) {
            if (element instanceof RepositoryNode && getSupportType() != null && getSupportType().equals(((RepositoryNode) element).getContentType())) {
                final RepositoryNode node = (RepositoryNode) element;
                StringBuffer sb = new StringBuffer();
                boolean validElem = false;
                ENodeType type = node.getType();
                if (ENodeType.REPOSITORY_ELEMENT.equals(type)) {
                    sb.append(node.getId());
                    validElem = true;
                } else if (ENodeType.SIMPLE_FOLDER.equals(type)) {
                    final IRepositoryViewObject object = node.getObject();
                    // path
                    if (object instanceof Folder) {
                        sb.append(((Folder) object).getPath());
                        sb.append('/');
                    }
                    sb.append(node.getLabel());
                    validElem = true;
                }
                if (validElem) {
                    sb.append('|');
                    // add project
                    if (node.getRoot() != null && node.getRoot().getProject() != null) {
                        sb.append(node.getRoot().getProject().getTechnicalLabel());
                    }
                    sb.append('|');
                    sb.append(node.getContentType().getType());
                    sb.append('|');
                    sb.append(type);
                    return sb.toString();
                }
            }
            return null;
        }

        @Override
        public int hashCode(Object element) {
            final String elementUniqueString = getElementUniqueString(element);
            if (elementUniqueString != null) {
                return elementUniqueString.hashCode();
            }
            return element.hashCode();
        }

        @Override
        public boolean equals(Object a, Object b) {
            String aStr = getElementUniqueString(a);
            String bStr = getElementUniqueString(b);
            return aStr != null && bStr != null ? aStr.equals(bStr) : a.equals(b);
        }
    });
    viewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            RepositoryNode node = (RepositoryNode) element;
            return filterRepositoryNode(node);
        }
    });
}
Also used : FilteredCheckboxTree(org.talend.core.ui.advanced.composite.FilteredCheckboxTree) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IElementComparer(org.eclipse.jface.viewers.IElementComparer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Folder(org.talend.core.model.repository.Folder) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType)

Aggregations

IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 ENodeType (org.talend.repository.model.IRepositoryNode.ENodeType)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 IElementComparer (org.eclipse.jface.viewers.IElementComparer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Composite (org.eclipse.swt.widgets.Composite)1 IESBService (org.talend.core.IESBService)1 CDCConnection (org.talend.core.model.metadata.builder.connection.CDCConnection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 Item (org.talend.core.model.properties.Item)1 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)1 Folder (org.talend.core.model.repository.Folder)1 IRepositoryContentHandler (org.talend.core.model.repository.IRepositoryContentHandler)1 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)1