Search in sources :

Example 1 with KnimeResourceContentProviderWithRoot

use of org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot in project knime-core by knime.

the class ResourceSelectDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    TreeSelectionControl tree = new TreeSelectionControl();
    tree.setContentProvider(new KnimeResourceContentProviderWithRoot());
    tree.setLabelProvider(new KnimeResourceLabelProviderWithRoot());
    tree.setInitialSelection(m_initialSelection);
    tree.setInput(m_root);
    tree.setMessage(m_message);
    tree.setValidator(new ISelectionValidator() {

        public String isValid(final Object selection) {
            if (m_validator != null) {
                String result = m_validator.isValid(selection);
                Button b = getButton(IDialogConstants.OK_ID);
                // store it in case button is not created yet
                m_valid = result == null;
                if (b != null) {
                    b.setEnabled(m_valid);
                }
                return result;
            }
            return null;
        }
    });
    tree.setChangeListener(new TreeSelectionChangeListener() {

        public void treeSelectionChanged(final Object newSelection, final boolean valid) {
            m_selectedContainer = findSelectedContainer(newSelection);
        }
    });
    return tree.createTreeControl(parent);
}
Also used : KnimeResourceContentProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot) Button(org.eclipse.swt.widgets.Button) TreeSelectionChangeListener(org.knime.workbench.ui.navigator.actions.selection.TreeSelectionControl.TreeSelectionChangeListener) KnimeResourceLabelProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceLabelProviderWithRoot) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator)

Example 2 with KnimeResourceContentProviderWithRoot

use of org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot in project knime-core by knime.

the class WorkflowSelectionDialog method createDialogArea.

/**
 * {@inheritDoc}
 */
@Override
protected Control createDialogArea(final Composite parent) {
    // a tree viewer to select a workflow group or workflow
    Group overall = new Group(parent, SWT.SHADOW_ETCHED_IN);
    overall.setText("Export selection:");
    overall.setLayout(new GridLayout(1, false));
    GridData shellLayout = new GridData(GridData.FILL_BOTH);
    shellLayout.widthHint = 300;
    shellLayout.heightHint = 350;
    overall.setLayoutData(shellLayout);
    GridData fillBoth = new GridData(GridData.FILL_BOTH);
    m_viewer = new TreeViewer(overall, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    m_viewer.getTree().setLayoutData(fillBoth);
    m_viewer.setLabelProvider(new KnimeResourceLabelProviderWithRoot());
    m_viewer.setContentProvider(new KnimeResourceContentProviderWithRoot());
    m_viewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
            if (element instanceof IWorkspaceRoot) {
                return true;
            }
            IResource resource = null;
            if (element instanceof NodeContainer) {
                ProjectWorkflowMap.findProjectFor(((NodeContainer) element).getID());
            } else if (element instanceof IResource) {
                resource = (IResource) element;
            }
            if (KnimeResourceUtil.isWorkflow(resource)) {
                return true;
            }
            if (KnimeResourceUtil.isWorkflowGroup(resource)) {
                return true;
            }
            return false;
        }
    });
    m_viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    m_viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            m_selectedObjs = (IStructuredSelection) m_viewer.getSelection();
        }
    });
    if (m_initialSelection != null) {
        m_viewer.setSelection(m_initialSelection);
    }
    m_viewer.expandAll();
    return overall;
}
Also used : Group(org.eclipse.swt.widgets.Group) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KnimeResourceLabelProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceLabelProviderWithRoot) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) NodeContainer(org.knime.core.node.workflow.NodeContainer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) KnimeResourceContentProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) IResource(org.eclipse.core.resources.IResource)

Aggregations

KnimeResourceContentProviderWithRoot (org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot)2 KnimeResourceLabelProviderWithRoot (org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceLabelProviderWithRoot)2 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Group (org.eclipse.swt.widgets.Group)1 ISelectionValidator (org.eclipse.ui.dialogs.ISelectionValidator)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1 TreeSelectionChangeListener (org.knime.workbench.ui.navigator.actions.selection.TreeSelectionControl.TreeSelectionChangeListener)1