Search in sources :

Example 71 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.

the class WorkflowExportPage method handleSingleSelection.

private IContainer handleSingleSelection(final IStructuredSelection selection) {
    Object obj = selection.getFirstElement();
    IContainer resultContainer = null;
    // prepare default export file name
    if (obj instanceof IContainer) {
        resultContainer = (IContainer) obj;
    } else if (obj instanceof IResource) {
        resultContainer = ((IResource) obj).getParent();
    }
    if (obj instanceof NodeContainer) {
        resultContainer = getContainerForWorkflow((NodeContainer) obj);
    }
    if (obj instanceof IContainer) {
        IContainer container = (IContainer) obj;
        // check whether it is a workflow group -> list all workflows
        if (KnimeResourceUtil.isWorkflowGroup(container) || container instanceof IWorkspaceRoot) {
            // get all contained containers and list them recursively
            m_treeViewer.setInput(container);
            m_treeViewer.getTree().setVisible(true);
            m_treeViewer.expandAll();
            // all
            if (selection.size() <= 1) {
                /*
                     * Since the tree is expanded before the deprecated method
                     * should work. Reason why it is deprecated:
                     * "this method only checks or unchecks visible items" but
                     * CheckboxTreeViewer#setSubtreeChecked(Object, boolean)
                     * does not work.
                     */
                m_treeViewer.setAllChecked(true);
            }
        } else if (KnimeResourceUtil.isWorkflow(container)) {
            // or a workflow -> list nothing
            m_treeViewer.getTree().setVisible(false);
        }
    }
    return resultContainer;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) NodeContainer(org.knime.core.node.workflow.NodeContainer) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 72 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.

the class WorkflowExportPage method handleSelection.

private IContainer handleSelection(final IStructuredSelection selection) {
    IContainer resultContainer = null;
    // reset checked elements
    m_treeViewer.expandAll();
    m_treeViewer.setAllChecked(false);
    if (selection.size() > 1) {
        resultContainer = handleMultiSelection(selection);
    } else if (selection.size() == 1) {
        resultContainer = handleSingleSelection(selection);
    }
    if (resultContainer != null) {
        String containerSelectionText = resultContainer.getFullPath().toString();
        if (resultContainer instanceof IWorkspaceRoot) {
            containerSelectionText = "/";
        }
        m_containerText.setText(containerSelectionText);
    }
    // also update the target file name
    updateFileName(resultContainer);
    return resultContainer;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer)

Example 73 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.

the class WorkflowExportPage method updateFileName.

private void updateFileName(final IContainer container) {
    if (container != null) {
        String fileName = container.getName() + ".zip";
        if (container instanceof IWorkspaceRoot) {
            fileName = "knime-export.zip";
        }
        File f = null;
        if (lastSelectedTargetLocation != null) {
            // create file in last used directory
            File parentFile = new File(lastSelectedTargetLocation);
            if (parentFile.exists() && parentFile.isDirectory()) {
                f = new File(parentFile, fileName);
            }
        }
        if (f == null) {
            // no value for last selected target - or folder does not exists
            // anymore -> default case: create file in user.home
            f = new File(System.getProperty("user.home"), fileName);
        }
        m_fileText.setText(f.getAbsolutePath());
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) File(java.io.File)

Example 74 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot 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)

Example 75 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.

the class NewProjectWizardPage method createDestinationSelectionComposite.

private void createDestinationSelectionComposite(final Composite parent) {
    Group destGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    destGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    destGroup.setLayout(new GridLayout(3, false));
    // second row: workflow destination
    Label destinationLabel = new Label(destGroup, SWT.NONE);
    destinationLabel.setText("Workspace destination:");
    m_destinationUI = new Text(destGroup, SWT.BORDER | SWT.READ_ONLY);
    m_destinationUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (m_initiallySelectedResource != null && !(m_initiallySelectedResource instanceof IWorkspaceRoot)) {
        m_destinationUI.setText(m_initiallySelectedResource.getFullPath().toString());
    } else {
        m_destinationUI.setText("/");
    }
    Button browseBtn = new Button(destGroup, SWT.PUSH);
    browseBtn.setText("Browse...");
    browseBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            handleBrowseButton();
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10