Search in sources :

Example 1 with IImportStructureProvider

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

the class ImportProjectsUtilities method importArchiveProject.

public static void importArchiveProject(Shell shell, String technicalName, String sourcePath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, TarException, IOException {
    IImportStructureProvider provider;
    Object source;
    if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        ZipLeveledStructureProvider zipProvider = new ZipLeveledStructureProvider(new ZipFile(sourcePath));
        source = zipProvider.getRoot();
        boolean ok = true;
        for (Object o : zipProvider.getChildren(source)) {
            String label = zipProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = zipProvider.getRoot();
        }
        provider = zipProvider;
    } else if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        TarLeveledStructureProvider tarProvider = new TarLeveledStructureProvider(new TarFile(sourcePath));
        source = tarProvider.getRoot();
        boolean ok = true;
        for (Object o : tarProvider.getChildren(source)) {
            String label = tarProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = tarProvider.getRoot();
        }
        provider = tarProvider;
    } else {
        //$NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("ImportProjectsUtilities.fileFormatError", sourcePath));
    }
    importProject(shell, provider, source, new Path(technicalName), false, false, monitor);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)

Example 2 with IImportStructureProvider

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

the class ImportProjectsUtilities method importProjectAs.

public static void importProjectAs(Shell shell, String newName, String technicalName, String sourcePath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    IImportStructureProvider provider = FilterFileSystemStructureProvider.INSTANCE;
    importProject(shell, provider, new File(sourcePath), new Path(technicalName), true, false, monitor);
    Project project = afterImportAs(newName, technicalName);
    // do additional actions after importing projects
    AfterImportProjectUtil.runAfterImportProjectActions(new org.talend.core.model.general.Project(project));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)

Example 3 with IImportStructureProvider

use of org.eclipse.ui.wizards.datatransfer.IImportStructureProvider in project webtools.sourceediting by eclipse.

the class ProjectUnzipUtility method importFile.

/**
 * @param fileToImport
 *            the file you wish to import
 * @param folderPath
 *            the container path within the workspace
 */
public void importFile(File fileToImport, String folderPath) {
    WorkspaceProgressMonitor importProgress = new WorkspaceProgressMonitor();
    try {
        if (fileToImport.exists()) {
            IPath containerPath = new Path(folderPath);
            IImportStructureProvider provider = FileSystemStructureProvider.INSTANCE;
            IOverwriteQuery overwriteImplementor = new MyOverwriteQuery();
            File[] filesToImport = { fileToImport };
            ImportOperation importOp = new ImportOperation(containerPath, null, provider, overwriteImplementor, Arrays.asList(filesToImport));
            importOp.setCreateContainerStructure(false);
            importOp.setOverwriteResources(true);
            importOp.run(importProgress);
        } else {
            System.out.println("handle source doesn't exist");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        importProgress.done();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ZipFile(java.util.zip.ZipFile) File(java.io.File) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with IImportStructureProvider

use of org.eclipse.ui.wizards.datatransfer.IImportStructureProvider in project webtools.sourceediting by eclipse.

the class ProjectUnzipUtility method importFile.

/**
 * @param fileToImport
 *            the file you wish to import
 * @param folderPath
 *            the container path within the workspace
 */
public void importFile(File fileToImport, String folderPath) {
    WorkspaceProgressMonitor importProgress = new WorkspaceProgressMonitor();
    try {
        if (fileToImport.exists()) {
            IPath containerPath = new Path(folderPath);
            // fCreatedProjects.add(folderPath);
            IImportStructureProvider provider = FileSystemStructureProvider.INSTANCE;
            IOverwriteQuery overwriteImplementor = new MyOverwriteQuery();
            File[] filesToImport = { fileToImport };
            ImportOperation importOp = new ImportOperation(containerPath, null, provider, overwriteImplementor, Arrays.asList(filesToImport));
            importOp.setCreateContainerStructure(false);
            importOp.setOverwriteResources(true);
            importOp.run(importProgress);
        } else {
            System.out.println("handle source doesn't exist");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        importProgress.done();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ZipFile(java.util.zip.ZipFile) File(java.io.File) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ZipFile (java.util.zip.ZipFile)4 IPath (org.eclipse.core.runtime.IPath)4 Path (org.eclipse.core.runtime.Path)4 IImportStructureProvider (org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)4 File (java.io.File)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CoreException (org.eclipse.core.runtime.CoreException)2 IOverwriteQuery (org.eclipse.ui.dialogs.IOverwriteQuery)2 TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)2 ImportOperation (org.eclipse.ui.wizards.datatransfer.ImportOperation)2 IProject (org.eclipse.core.resources.IProject)1 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)1 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)1 Project (org.talend.core.model.properties.Project)1