Search in sources :

Example 1 with IOverwriteQuery

use of org.eclipse.ui.dialogs.IOverwriteQuery in project knime-core by knime.

the class KnimeResourceUtil method importWorkflowIntoWorkspace.

/**
 * Stores the flow in the archive in the local workspace.
 *
 * @param destination the name of the new workflow. Must denote a flow (if
 *            it exists it is overwritten).
 * @param zippedWorkflow
 * @throws IOException
 * @throws ZipException
 * @throws InterruptedException
 * @throws InvocationTargetException
 */
private static void importWorkflowIntoWorkspace(final IPath destination, final File zippedWorkflow) throws ZipException, IOException, InvocationTargetException, InterruptedException {
    ZipFile zFile = new ZipFile(zippedWorkflow);
    ZipLeveledStructProvider importStructureProvider = new ZipLeveledStructProvider(zFile);
    importStructureProvider.setStrip(1);
    ZipEntry root = (ZipEntry) importStructureProvider.getRoot();
    List<ZipEntry> rootChild = importStructureProvider.getChildren(root);
    if (rootChild.size() == 1) {
        // the zipped workflow normally contains only one dir
        root = rootChild.get(0);
    }
    LOGGER.debug("Importing workflow. Destination:" + destination.toString());
    try {
        final ImportOperation iOper = new ImportOperation(destination, root, importStructureProvider, new IOverwriteQuery() {

            @Override
            public String queryOverwrite(final String pathString) {
                return IOverwriteQuery.YES;
            }
        });
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                iOper.run(monitor);
            }
        });
    } finally {
        importStructureProvider.closeArchive();
    }
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with IOverwriteQuery

use of org.eclipse.ui.dialogs.IOverwriteQuery 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 3 with IOverwriteQuery

use of org.eclipse.ui.dialogs.IOverwriteQuery 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 4 with IOverwriteQuery

use of org.eclipse.ui.dialogs.IOverwriteQuery 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 5 with IOverwriteQuery

use of org.eclipse.ui.dialogs.IOverwriteQuery 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

IOverwriteQuery (org.eclipse.ui.dialogs.IOverwriteQuery)8 ImportOperation (org.eclipse.ui.wizards.datatransfer.ImportOperation)8 File (java.io.File)5 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Path (org.eclipse.core.runtime.Path)4 ZipFile (java.util.zip.ZipFile)3 IProject (org.eclipse.core.resources.IProject)3 IProjectDescription (org.eclipse.core.resources.IProjectDescription)3 CoreException (org.eclipse.core.runtime.CoreException)3 IPath (org.eclipse.core.runtime.IPath)3 IFile (org.eclipse.core.resources.IFile)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IImportStructureProvider (org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1