Search in sources :

Example 6 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.

the class TalendWizardProjectsImportPage method getProjectRecords.

@Override
public ProjectRecord[] getProjectRecords() {
    if (sourcePath == null || sourcePath.length() == 0) {
        return new ProjectRecord[0];
    }
    ProjectRecord[] selectedProjects = super.getProjectRecords();
    Collection files = new ArrayList();
    List projects = new ArrayList();
    ProjectRecord[] selected = null;
    for (ProjectRecord selectedProject : selectedProjects) {
        projects.add(selectedProject);
    }
    final File directory = new File(sourcePath);
    if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        try {
            TarFile sourceTarFile = new TarFile(sourcePath);
            if (sourceTarFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new TarLeveledStructureProvider(sourceTarFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (TarException e) {
            // displayErrorDialog(DataTransferMessages.TarImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.TarImport_badFormat"));
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_couldNotRead"));
        }
    } else if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        try {
            ZipFile sourceFile = new ZipFile(sourcePath);
            if (sourceFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new ZipLeveledStructureProvider(sourceFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_badFormat"));
        }
    } else if (directory.isDirectory()) {
        collectProjectFilesFromDirectory(files, directory, null);
        selected = new ProjectRecord[files.size()];
        Iterator filesIterator = files.iterator();
        int j = 0;
        while (filesIterator.hasNext()) {
            File file = (File) filesIterator.next();
            for (int i = 0; i < projects.size(); i++) {
                if (file.getParentFile().getName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                    selected[j] = (ProjectRecord) projects.get(i);
                    j++;
                }
            }
        }
    }
    return selected;
}
Also used : TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile)

Example 7 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider 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)

Aggregations

ZipFile (java.util.zip.ZipFile)7 TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)7 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)7 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)7 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 Iterator (java.util.Iterator)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IOException (java.io.IOException)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 ILeveledImportStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)1