Search in sources :

Example 1 with KnimeResourceLabelProvider

use of org.knime.workbench.ui.navigator.KnimeResourceLabelProvider in project knime-core by knime.

the class WorkflowExportPage method createTreeViewer.

private void createTreeViewer(final Composite parent) {
    m_treeViewer = new CheckboxTreeViewer(parent);
    m_treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    m_treeViewer.setContentProvider(new ITreeContentProvider() {

        // assume to have IContainers as input
        @Override
        public Object[] getChildren(final Object parentElement) {
            if (parentElement instanceof IContainer) {
                IContainer container = (IContainer) parentElement;
                try {
                    // return only workflows and workflow groups
                    Collection<IContainer> children = new ArrayList<IContainer>();
                    for (IResource r : container.members(false)) {
                        if (KnimeResourceUtil.isWorkflow(r) || KnimeResourceUtil.isWorkflowGroup(r)) {
                            // if it is a workflow or workflow group
                            // it must be a container
                            children.add((IContainer) r);
                        }
                    }
                    return children.toArray();
                } catch (CoreException e) {
                    return new Object[0];
                }
            }
            return new Object[0];
        }

        @Override
        public Object getParent(final Object element) {
            if (element instanceof IResource) {
                return ((IResource) element).getParent();
            }
            return null;
        }

        @Override
        public boolean hasChildren(final Object element) {
            if (element instanceof IWorkspaceRoot) {
                return true;
            }
            if ((element instanceof IContainer) && KnimeResourceUtil.isWorkflowGroup((IContainer) element)) {
                return true;
            }
            return false;
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            return getChildren(inputElement);
        }

        @Override
        public void dispose() {
        // nothing to do
        }

        @Override
        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
        // nothing to do
        }
    });
    m_treeViewer.setLabelProvider(new KnimeResourceLabelProvider());
    m_treeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            Object o = event.getElement();
            boolean isChecked = event.getChecked();
            // first expand in order to be able to check children as well
            m_treeViewer.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
            m_treeViewer.setSubtreeChecked(o, isChecked);
            if (o instanceof IResource) {
                IResource element = (IResource) o;
                setParentTreeChecked(m_treeViewer, element, isChecked);
            }
            dialogChanged();
            getWizard().getContainer().updateButtons();
        }
    });
    m_treeViewer.getTree().setVisible(false);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) KnimeResourceLabelProvider(org.knime.workbench.ui.navigator.KnimeResourceLabelProvider) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) IContainer(org.eclipse.core.resources.IContainer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) IResource(org.eclipse.core.resources.IResource)

Aggregations

Collection (java.util.Collection)1 IContainer (org.eclipse.core.resources.IContainer)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 Viewer (org.eclipse.jface.viewers.Viewer)1 GridData (org.eclipse.swt.layout.GridData)1 KnimeResourceLabelProvider (org.knime.workbench.ui.navigator.KnimeResourceLabelProvider)1