Search in sources :

Example 21 with CheckboxTreeViewer

use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.

the class ImportItemWizardPage method createTreeViewer.

private TreeViewer createTreeViewer(Composite listComposite) {
    filteredCheckboxTree = new FilteredCheckboxTree(listComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
    viewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof IContainerNode) {
                return ((IContainerNode) parentElement).getChildren().toArray();
            }
            return null;
        }

        @Override
        public Object[] getElements(Object inputElement) {
            // return getValidItems();
            return repositoryUtil.getTreeViewInput().toArray();
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).hasChildren();
            }
            return false;
        }

        @Override
        public Object getParent(Object element) {
            return null;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContainerNode) {
                if (element instanceof ProjectNode) {
                    Project project = ((ProjectNode) element).getProject();
                    return ProjectManager.getProjectDisplayLabel(project);
                }
                return ((IContainerNode) element).getLabel();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getLabel();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).getImage();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getImage();
            }
            return super.getImage(element);
        }
    });
    viewer.setSorter(TreeBuilder.createSorter());
    viewer.setInput(this);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            filteredCheckboxTree.calculateCheckedLeafNodes();
            updateFinishStatus();
        }
    });
    filteredCheckboxTree.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return selectRepositoryNode(viewer, element);
        }
    });
    return viewer;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FilteredCheckboxTree(org.talend.core.ui.advanced.composite.FilteredCheckboxTree) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Image(org.eclipse.swt.graphics.Image) IContainerNode(org.talend.repository.imports.TreeBuilder.IContainerNode) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Project(org.talend.core.model.properties.Project) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) ProjectNode(org.talend.repository.imports.TreeBuilder.ProjectNode) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 22 with CheckboxTreeViewer

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

Example 23 with CheckboxTreeViewer

use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.

the class UseDynamicJobSelectionDialog method removeCheckStateListener.

public void removeCheckStateListener(ICheckStateListener listener) {
    CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
    exportItemsTreeViewer.removeCheckStateListener(listener);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer)

Example 24 with CheckboxTreeViewer

use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.

the class UseDynamicJobSelectionDialog method collectCheckedNodes.

private void collectCheckedNodes() {
    repositoryNodes.clear();
    CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
    for (int i = 0; i < exportItemsTreeViewer.getCheckedElements().length; i++) {
        RepositoryNode node = (RepositoryNode) exportItemsTreeViewer.getCheckedElements()[i];
        if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
            repositoryNodes.add(node);
        }
    }
}
Also used : 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)

Example 25 with CheckboxTreeViewer

use of org.eclipse.jface.viewers.CheckboxTreeViewer in project bndtools by bndtools.

the class WizardBndFileSelector method createControl.

@Override
public void createControl(Composite composite) {
    checkboxTreeViewer = new CheckboxTreeViewer(composite);
    checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            ITreeContentProvider contentProvider = (ITreeContentProvider) checkboxTreeViewer.getContentProvider();
            alterChildren(element, contentProvider, event.getChecked());
            alterParents(element, contentProvider);
        }

        private void alterChildren(Object element, ITreeContentProvider contentProvider, boolean checked) {
            Queue<Object> toRecurse = new LinkedList<Object>();
            toRecurse.offer(element);
            while (!toRecurse.isEmpty()) {
                Object o = toRecurse.poll();
                for (Object child : contentProvider.getChildren(o)) {
                    if (contentProvider.hasChildren(child))
                        toRecurse.offer(child);
                    checkboxTreeViewer.setChecked(child, checked);
                    checkboxTreeViewer.setGrayed(child, false);
                }
            }
        }

        private void alterParents(Object element, ITreeContentProvider contentProvider) {
            Object parent = contentProvider.getParent(element);
            while (parent != null) {
                boolean allChecked = true;
                boolean noneChecked = true;
                for (Object child : contentProvider.getChildren(parent)) {
                    boolean checked = checkboxTreeViewer.getChecked(child);
                    boolean grayed = checkboxTreeViewer.getGrayed(child);
                    allChecked &= checked & !grayed;
                    noneChecked &= !checked;
                }
                if (allChecked) {
                    checkboxTreeViewer.setChecked(parent, true);
                    checkboxTreeViewer.setGrayed(parent, false);
                } else if (noneChecked) {
                    checkboxTreeViewer.setGrayChecked(parent, false);
                } else {
                    checkboxTreeViewer.setGrayChecked(parent, true);
                }
                parent = contentProvider.getParent(parent);
            }
        }
    });
    setControl(checkboxTreeViewer.getControl());
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Queue(java.util.Queue)

Aggregations

CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)25 Composite (org.eclipse.swt.widgets.Composite)14 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)8 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)8 GridData (org.eclipse.swt.layout.GridData)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 Label (org.eclipse.swt.widgets.Label)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 Button (org.eclipse.swt.widgets.Button)6 Viewer (org.eclipse.jface.viewers.Viewer)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)4 ArrayList (java.util.ArrayList)4 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 ModifyListener (org.eclipse.swt.events.ModifyListener)4 Text (org.eclipse.swt.widgets.Text)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)4