Search in sources :

Example 6 with TarLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method updateProjectsList.

/**
	 * Update the list of projects based on path. Method declared public only
	 * for test suite.
	 * 
	 * @param path
	 */
public void updateProjectsList(final String path) {
    // on an empty path empty selectedProjects
    if (path == null || path.length() == 0) {
        setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
        selectedProjects = new ProjectRecord[0];
        projectsList.refresh(true);
        projectsList.setCheckedElements(selectedProjects);
        setPageComplete(projectsList.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
        // change, no refreshing is required
        return;
    }
    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;
    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            /*
				 * (non-Javadoc)
				 * 
				 * @see
				 * org.eclipse.jface.operation.IRunnableWithProgress#run(org
				 * .eclipse.core.runtime.IProgressMonitor)
				 */
            @SuppressWarnings("rawtypes")
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        IDEWorkbenchPlugin.log(e.getMessage(), e);
    } catch (InterruptedException e) {
    // Nothing to do if the user interrupts.
    }
    projectsList.refresh(true);
    ProjectRecord[] projects = getProjectRecords();
    boolean displayWarning = false;
    for (int i = 0; i < projects.length; i++) {
        if (projects[i].hasConflicts) {
            displayWarning = true;
            projectsList.setGrayed(projects[i], true);
        } else {
            projectsList.setChecked(projects[i], true);
        }
    }
    if (displayWarning) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
    } else {
        setMessage("");
    }
    setPageComplete(projectsList.getCheckedElements().length > 0);
    if (selectedProjects.length == 0) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
    }
}
Also used : ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) 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) Iterator(java.util.Iterator) Collection(java.util.Collection) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Example 7 with TarLeveledStructureProvider

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