Search in sources :

Example 81 with IContainer

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

the class WorkflowExportWizard method canFinish.

/**
 * {@inheritDoc}
 */
@Override
public boolean canFinish() {
    Collection<IContainer> workflows = m_page.getWorkflows();
    final List<IResource> resourceList = new ArrayList<IResource>();
    for (IContainer c : workflows) {
        addResourcesFor(resourceList, c, m_excludeData);
    }
    if (resourceList.isEmpty()) {
        return false;
    }
    return m_page.isPageComplete();
}
Also used : ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 82 with IContainer

use of org.eclipse.core.resources.IContainer 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 83 with IContainer

use of org.eclipse.core.resources.IContainer 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 84 with IContainer

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

the class WorkflowExportPage method getWorkflows.

/**
 * @return checked workflows and workflow groups
 */
public Collection<IContainer> getWorkflows() {
    Object[] checkedObjs = m_treeViewer.getCheckedElements();
    List<IContainer> workflows = new ArrayList<IContainer>();
    // also add the root
    IContainer rootContainer = getContainerForFullPath(new Path(m_containerText.getText()));
    if (rootContainer != null) {
        workflows.add(rootContainer);
    }
    for (Object o : checkedObjs) {
        if (o instanceof IContainer) {
            IContainer container = (IContainer) o;
            if (KnimeResourceUtil.isWorkflowGroup(container) || KnimeResourceUtil.isWorkflow(container)) {
                workflows.add(container);
            }
        }
    }
    return workflows;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer)

Example 85 with IContainer

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

the class WorkflowExportPage method dialogChanged.

/**
 * Ensures that both text fields are set.
 */
private void dialogChanged() {
    Collection<IContainer> workflows = getWorkflows();
    final List<IResource> list = new ArrayList<IResource>();
    for (IContainer c : workflows) {
        WorkflowExportWizard.addResourcesFor(list, c, excludeData());
    }
    if (list.isEmpty()) {
        updateStatus("Select an element to export!");
        return;
    }
    String fileName = getFileName();
    if (fileName.length() == 0 || fileName.endsWith(File.separator)) {
        updateStatus("File name must be specified");
        return;
    }
    updateStatus(null);
}
Also used : ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9