Search in sources :

Example 6 with ImportOperation

use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project jbosstools-hibernate by jbosstools.

the class JavaProjectHelper method importFilesFromZip.

private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
    ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
    try {
        ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
        op.run(monitor);
    } catch (InterruptedException e) {
    // should not happen
    }
}
Also used : ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ZipFileStructureProvider(org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider)

Example 7 with ImportOperation

use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project n4js by eclipse.

the class ProjectTestsUtils method importProject.

private static IProject importProject(File probandsFolder, String projectName, boolean prepareDotProject) throws Exception {
    File projectSourceFolder = new File(probandsFolder, projectName);
    if (!projectSourceFolder.exists()) {
        throw new IllegalArgumentException("proband not found in " + projectSourceFolder);
    }
    if (prepareDotProject) {
        prepareDotProject(projectSourceFolder);
    }
    IProgressMonitor monitor = new NullProgressMonitor();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName);
    IProject project = workspace.getRoot().getProject(projectName);
    project.create(newProjectDescription, monitor);
    project.open(monitor);
    if (!project.getLocation().toFile().exists()) {
        throw new IllegalArgumentException("test project correctly created in " + project.getLocation());
    }
    IOverwriteQuery overwriteQuery = new IOverwriteQuery() {

        @Override
        public String queryOverwrite(String file) {
            return ALL;
        }
    };
    ImportOperation importOperation = new ImportOperation(project.getFullPath(), projectSourceFolder, FileSystemStructureProvider.INSTANCE, overwriteQuery);
    importOperation.setCreateContainerStructure(false);
    importOperation.run(monitor);
    return project;
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 8 with ImportOperation

use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project statecharts by Yakindu.

the class GitRepositoryExampleService method importExample.

@Override
public void importExample(ExampleData edata, IProgressMonitor monitor) {
    try {
        IProjectDescription original = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project"));
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName());
        IProjectDescription clone = ResourcesPlugin.getWorkspace().newProjectDescription(original.getName());
        clone.setBuildSpec(original.getBuildSpec());
        clone.setComment(original.getComment());
        clone.setDynamicReferences(original.getDynamicReferences());
        clone.setNatureIds(original.getNatureIds());
        clone.setReferencedProjects(original.getReferencedProjects());
        if (project.exists()) {
            return;
        }
        project.create(clone, monitor);
        project.open(monitor);
        @SuppressWarnings("unchecked") List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir());
        ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(), FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

            @Override
            public String queryOverwrite(String pathString) {
                return IOverwriteQuery.ALL;
            }
        }, filesToImport);
        io.setOverwriteResources(true);
        io.setCreateContainerStructure(false);
        io.run(monitor);
        project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IFile(org.eclipse.core.resources.IFile) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 9 with ImportOperation

use of org.eclipse.ui.wizards.datatransfer.ImportOperation 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 10 with ImportOperation

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

ImportOperation (org.eclipse.ui.wizards.datatransfer.ImportOperation)18 File (java.io.File)9 IOverwriteQuery (org.eclipse.ui.dialogs.IOverwriteQuery)8 IPath (org.eclipse.core.runtime.IPath)7 IProject (org.eclipse.core.resources.IProject)6 CoreException (org.eclipse.core.runtime.CoreException)6 Path (org.eclipse.core.runtime.Path)6 IOException (java.io.IOException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 ZipFile (java.util.zip.ZipFile)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IStatus (org.eclipse.core.runtime.IStatus)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 ArrayList (java.util.ArrayList)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ZipFileStructureProvider (org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider)3 URI (java.net.URI)2 URL (java.net.URL)2 IIndexManager (org.eclipse.cdt.core.index.IIndexManager)2