Search in sources :

Example 1 with ILeveledImportStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.

the class WorkflowImportElementFromArchive method isWorkflowGroup.

/**
 * {@inheritDoc}
 */
@Override
public boolean isWorkflowGroup() {
    ILeveledImportStructureProvider provider = getProvider();
    Object zipEntry = getEntry();
    if (provider.isFolder(zipEntry)) {
        List children = provider.getChildren(zipEntry);
        if (children == null) {
            return false;
        }
        for (Object o : children) {
            String elementLabel = provider.getLabel(o);
            if (elementLabel.equals(WorkflowPersistor.METAINFO_FILE)) {
                return true;
            }
        }
    }
    return false;
}
Also used : List(java.util.List) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)

Example 2 with ILeveledImportStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.

the class WorkflowImportOperation method handleCopyProject.

private ILeveledImportStructureProvider handleCopyProject(final IWorkflowImportElement importElement, final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    IPath destination = m_targetPath.append(importElement.getRenamedPath());
    ImportOperation operation = null;
    ILeveledImportStructureProvider provider = null;
    if (importElement instanceof WorkflowImportElementFromFile) {
        operation = createWorkflowFromFile((WorkflowImportElementFromFile) importElement, destination, new SubProgressMonitor(monitor, 1));
    } else if (importElement instanceof WorkflowImportElementFromArchive) {
        WorkflowImportElementFromArchive zip = (WorkflowImportElementFromArchive) importElement;
        provider = zip.getProvider();
        operation = createWorkflowFromArchive(zip, destination, new SubProgressMonitor(monitor, 1));
    }
    if (operation != null) {
        operation.setContext(m_shell);
        operation.setOverwriteResources(true);
        operation.setCreateContainerStructure(false);
        operation.run(monitor);
        // if we created a project -> set the correct nature
        if (Path.ROOT.equals(m_targetPath)) {
            setProjectNature(importElement);
        }
        IResource newProject = ResourcesPlugin.getWorkspace().getRoot().findMember(destination);
        if (newProject != null) {
            newProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        }
        monitor.worked(1);
    }
    return provider;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 3 with ILeveledImportStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.

the class WorkflowImportOperation method execute.

/**
 * {@inheritDoc}
 */
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    ILeveledImportStructureProvider provider = null;
    try {
        monitor.beginTask("", m_workflows.size());
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        for (IWorkflowImportElement wf : m_workflows) {
            if (!m_copy) {
                handleLinkedProject(wf, monitor);
            } else {
                provider = handleCopyProject(wf, monitor);
            }
        }
        if (!m_missingMetaInfoLocations.isEmpty()) {
            createMetaInfo();
        }
        // clean up afterwards
        m_missingMetaInfoLocations.clear();
        ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
        final IResource result = ResourcesPlugin.getWorkspace().getRoot().findMember(m_targetPath);
        if (result != null) {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    KnimeResourceUtil.revealInNavigator(result);
                }
            });
        }
    } catch (CoreException ex) {
        throw ex;
    } catch (InterruptedException ex) {
        throw ex;
    } catch (InvocationTargetException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new InvocationTargetException(ex);
    } finally {
        if (provider != null) {
            ArchiveFileManipulations.closeStructureProvider(provider, m_shell);
        }
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ILeveledImportStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.

the class WorkflowImportSelectionPage method collectWorkflowsFromZipFile.

private void collectWorkflowsFromZipFile(final String path) {
    ILeveledImportStructureProvider provider = null;
    if (ArchiveFileManipulations.isTarFile(path)) {
        try {
            TarFile sourceTarFile = new TarFile(path);
            provider = new TarLeveledStructureProvider(sourceTarFile);
        } catch (Exception io) {
            // no file -> list stays empty
            setErrorMessage("Invalid .tar file: " + path + ". Contains no workflow.");
        }
    } else if (ArchiveFileManipulations.isZipFile(path)) {
        try {
            ZipFile sourceFile = new ZipFile(path);
            provider = new ZipLeveledStructureProvider(sourceFile);
        } catch (Exception e) {
            // no file -> list stays empty
            setErrorMessage("Invalid .zip file: " + path + ". Contains no workflows");
        }
    }
    // TODO: store only the workflows (dirs are created automatically)
    final ILeveledImportStructureProvider finalProvider = provider;
    if (provider != null) {
        // reset error
        setErrorMessage(null);
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    Object child = finalProvider.getRoot();
                    m_importRoot = new WorkflowImportElementFromArchive(finalProvider, child, 0);
                    monitor.beginTask("Scanning for workflows in ", IProgressMonitor.UNKNOWN);
                    collectWorkflowsFromProvider((WorkflowImportElementFromArchive) m_importRoot, monitor);
                }
            });
        } catch (Exception e) {
            String message = "Error while trying to import workflows from " + path;
            IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, message, e);
            setErrorMessage(message);
            LOGGER.error(message, e);
            ErrorDialog.openError(getShell(), "Import Error", null, status);
        }
        validateWorkflows();
        m_workflowListUI.setInput(m_importRoot);
        m_workflowListUI.expandAll();
        m_workflowListUI.setAllChecked(true);
        m_workflowListUI.refresh(true);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)

Example 5 with ILeveledImportStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.

the class WorkflowImportElementFromArchive method isWorkflow.

/**
 * {@inheritDoc}
 */
@Override
public boolean isWorkflow() {
    ILeveledImportStructureProvider provider = getProvider();
    Object zipEntry = getEntry();
    if (provider.isFolder(zipEntry)) {
        List children = provider.getChildren(zipEntry);
        if (children == null) {
            return false;
        }
        for (Object o : children) {
            String elementLabel = provider.getLabel(o);
            if (elementLabel.equals(WorkflowPersistor.WORKFLOW_FILE)) {
                return true;
            }
        }
    }
    return false;
}
Also used : List(java.util.List) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)

Aggregations

ILeveledImportStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)6 List (java.util.List)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IResource (org.eclipse.core.resources.IResource)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 ZipFile (java.util.zip.ZipFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Status (org.eclipse.core.runtime.Status)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)1 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)1 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)1