Search in sources :

Example 76 with IContainer

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

the class DeleteAction method deleteWorkflows.

private void deleteWorkflows(final List<IContainer> toDelWFs) {
    for (IContainer wf : toDelWFs) {
        assert VMFileLocker.isLockedForVM(new File(wf.getLocationURI()));
        assert KnimeResourceUtil.isWorkflow(wf);
        try {
            // delete the workflow file first
            IResource wfFile = wf.findMember(WorkflowPersistor.WORKFLOW_FILE);
            wfFile.delete(true, null);
            for (IResource child : wf.members()) {
                if (VMFileLocker.LOCK_FILE.equals(child.getName())) {
                    // delete the lock file last
                    continue;
                }
                child.delete(true, null);
            }
            // release lock in order to delete lock file
            VMFileLocker.unlockForVM(new File(wf.getLocationURI()));
            // lock file resource may not exist
            File lockFile = new File(new File(wf.getLocationURI()), VMFileLocker.LOCK_FILE);
            lockFile.delete();
            // delete the workflow directory itself
            wf.delete(true, null);
        } catch (CoreException e) {
            LOGGER.error("Error while deleting workflow " + wf.getFullPath() + ": " + e.getMessage(), e);
        // continue with next workflow...
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 77 with IContainer

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

the class ImportKnimeWorkflowAction method run.

/**
 * Invoke the Import wizards selection Wizard.
 */
@Override
public void run() {
    WorkflowImportWizard wizard = new WorkflowImportWizard();
    WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
    IStructuredSelection selectionToPass;
    // get the current workbench selection
    ISelection workbenchSelection = m_workbenchWindow.getSelectionService().getSelection();
    if (workbenchSelection instanceof IStructuredSelection) {
        selectionToPass = (IStructuredSelection) workbenchSelection;
        if (selectionToPass.size() == 1) {
            Object o = selectionToPass.getFirstElement();
            if (o instanceof IContainer) {
                wizard.setInitialDestination((IContainer) o);
            }
        }
    }
    dialog.open();
}
Also used : WorkflowImportWizard(org.knime.workbench.ui.wizards.imports.WorkflowImportWizard) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 78 with IContainer

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

the class KnimeResourceUtil method getResourceForURI.

/**
 * Returns the resource denoted by the specified URI - or null, if no such
 * resource exists within the workspace.
 *
 * @param location if inside the workspace and existing the corresponding
 *            resource is returned - otherwise null
 *
 * @return the resource denoted by the specified URI - or null, if no such
 *         resource exists within the workspace.
 */
public static IResource getResourceForURI(final URI location) {
    if (location == null) {
        return null;
    }
    IWorkspaceRoot rootPath = ResourcesPlugin.getWorkspace().getRoot();
    IContainer[] conts = rootPath.findContainersForLocationURI(location);
    if (conts.length >= 1) {
        return conts[0];
    }
    return null;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer)

Example 79 with IContainer

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

the class KnimeResourceUtil method isWorkflow.

/**
 * @param resource the resource to test
 * @return true if the resource contains a workflow
 */
public static boolean isWorkflow(final IResource resource) {
    if (resource == null) {
        return false;
    }
    if (resource instanceof IFile) {
        return false;
    }
    if (!(resource instanceof IContainer)) {
        return false;
    }
    IContainer container = (IContainer) resource;
    // if container contains a workflow file but not its parent
    IContainer parent = container.getParent();
    if ((parent != null) && parent.exists(WORKFLOW_FILE)) {
        return false;
    }
    return container.exists(WORKFLOW_FILE);
}
Also used : IFile(org.eclipse.core.resources.IFile) IContainer(org.eclipse.core.resources.IContainer)

Example 80 with IContainer

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

the class WorkflowExportWizard method findLeadOffset.

private int findLeadOffset() {
    // go up until root is reached
    int offset = 0;
    IContainer p = m_container;
    if (ResourcesPlugin.getWorkspace().getRoot().equals(m_container.getParent())) {
        // nothing to strip -> use common export operation
        return -1;
    }
    while (p != null && !p.equals(ResourcesPlugin.getWorkspace().getRoot())) {
        offset++;
        p = p.getParent();
    }
    return offset;
}
Also used : IContainer(org.eclipse.core.resources.IContainer)

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