Search in sources :

Example 11 with ImportOperation

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

the class ExampleProjectCreationOperation method importFilesFromZip.

private void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
    ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, overwriteQuery);
    op.run(monitor);
}
Also used : ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ZipFileStructureProvider(org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider)

Example 12 with ImportOperation

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

the class JavaProjectHelper method importFilesFromZip.

public 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)

Example 13 with ImportOperation

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

the class ImportProjectWizardPage method createExistingProject.

/**
	 * Create the project described in record. If it is successful return true.
	 * 
	 * @param record
	 * @return boolean <code>true</code> if successful
	 * @throws InterruptedException
	 */
private boolean createExistingProject(final ProjectRecord record, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    String projectName = record.getProjectName();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    createdProjects.add(project);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        // If it is under the root use the default location
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    if (record.projectArchiveFile != null) {
        // import from archive
        List fileSystemObjects = structureProvider.getChildren(record.parent);
        structureProvider.setStrip(record.level);
        ImportOperation operation = new ImportOperation(project.getFullPath(), structureProvider.getRoot(), structureProvider, this, fileSystemObjects);
        operation.setContext(getShell());
        operation.run(monitor);
        return true;
    }
    // import from file system
    File importSource = null;
    if (copyFiles) {
        // import project from location copying files - use default project
        // location for this workspace
        URI locationURI = record.description.getLocationURI();
        // some error condition occured.
        if (locationURI != null) {
            // validate the location of the project being copied
            IStatus result = ResourcesPlugin.getWorkspace().validateProjectLocationURI(project, locationURI);
            if (!result.isOK())
                throw new InvocationTargetException(new CoreException(result));
            importSource = new File(locationURI);
            IProjectDescription desc = workspace.newProjectDescription(projectName);
            desc.setBuildSpec(record.description.getBuildSpec());
            desc.setComment(record.description.getComment());
            desc.setDynamicReferences(record.description.getDynamicReferences());
            desc.setNatureIds(record.description.getNatureIds());
            desc.setReferencedProjects(record.description.getReferencedProjects());
            record.description = desc;
        }
    }
    try {
        monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask, 100);
        project.create(record.description, new SubProgressMonitor(monitor, 30));
        project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 70));
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
    // import operation to import project files if copy checkbox is selected
    if (copyFiles && importSource != null) {
        List filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(importSource);
        ImportOperation operation = new ImportOperation(project.getFullPath(), importSource, FileSystemStructureProvider.INSTANCE, this, filesToImport);
        operation.setContext(getShell());
        // need to overwrite
        operation.setOverwriteResources(true);
        // .project, .classpath
        // files
        operation.setCreateContainerStructure(false);
        operation.run(monitor);
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) List(java.util.List) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Example 14 with ImportOperation

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

the class ImportProjectsUtilities method importProject.

private static void importProject(Shell shell, IImportStructureProvider provider, Object source, IPath path, boolean overwriteResources, boolean createContainerStructure, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    //$NON-NLS-1$
    monitor.beginTask(Messages.getString("ImportProjectsUtilities.task.importingProject"), 100);
    ArrayList fileSystemObjects = new ArrayList();
    ImportProjectsUtilities.getFilesForProject(fileSystemObjects, provider, source);
    ImportOperation operation = new ImportOperation(path, source, provider, new MyOverwriteQuery(), fileSystemObjects);
    operation.setContext(shell);
    operation.setOverwriteResources(overwriteResources);
    operation.setCreateContainerStructure(createContainerStructure);
    operation.run(new SubProgressMonitor(monitor, 95));
    monitor.worked(5);
    monitor.done();
}
Also used : ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 15 with ImportOperation

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

the class AbstractTest method createExternalProject.

/**
 * Create a CDT project outside the default workspace.
 *
 * @param bundle
 *            The plug-in bundle.
 * @param projname
 *            The name of the project.
 * @param absProjectPath
 *            Absolute path to the directory to which the project should be
 *            mapped outside the workspace.
 * @return A new external CDT project.
 * @throws CoreException
 * @throws URISyntaxException
 * @throws IOException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
protected IProject createExternalProject(Bundle bundle, final String projname, final Path absProjectPath) throws CoreException, URISyntaxException, IOException, InvocationTargetException, InterruptedException {
    IProject externalProject;
    // Turn off auto-building
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription wspDesc = workspace.getDescription();
    wspDesc.setAutoBuilding(false);
    workspace.setDescription(wspDesc);
    // Create external project
    IWorkspaceRoot root = workspace.getRoot();
    externalProject = root.getProject(projname);
    IProjectDescription description = workspace.newProjectDescription(projname);
    URI fileProjectURL = new URI("file://" + absProjectPath.toString());
    description.setLocationURI(fileProjectURL);
    externalProject = CCorePlugin.getDefault().createCDTProject(description, externalProject, new NullProgressMonitor());
    assertNotNull(externalProject);
    externalProject.open(null);
    try {
        // CDT opens the Project with BACKGROUND_REFRESH enabled which
        // causes the
        // refresh manager to refresh the project 200ms later. This Job
        // interferes
        // with the resource change handler firing see: bug 271264
        Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
    } catch (Exception e) {
    // Ignore
    }
    assertTrue(externalProject.isOpen());
    // Import boiler-plate files which can then be built and profiled
    URL location = FileLocator.find(bundle, new Path("resources/" + projname), // $NON-NLS-1$
    null);
    File testDir = new File(FileLocator.toFileURL(location).toURI());
    ImportOperation op = new ImportOperation(externalProject.getFullPath(), testDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

        @Override
        public String queryOverwrite(String pathString) {
            return ALL;
        }
    });
    op.setCreateContainerStructure(false);
    op.run(null);
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    // Make sure import went well
    assertNotNull(externalProject.findMember(new Path(IMPORTED_SOURCE_FILE)));
    // Index the project
    IIndexManager indexMgr = CCorePlugin.getIndexManager();
    indexMgr.joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
    // These natures must be enabled at this point to continue
    assertTrue(externalProject.isNatureEnabled(ScannerConfigNature.NATURE_ID));
    assertTrue(externalProject.isNatureEnabled(ManagedCProjectNature.MNG_NATURE_ID));
    return externalProject;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) URL(java.net.URL) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) File(java.io.File)

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