Search in sources :

Example 1 with IElementComparer

use of org.eclipse.jface.viewers.IElementComparer 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

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 Folder (org.talend.core.model.repository.Folder)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)1 FilteredCheckboxTree (org.talend.core.ui.advanced.composite.FilteredCheckboxTree)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1 ENodeType (org.talend.repository.model.IRepositoryNode.ENodeType)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1