Search in sources :

Example 6 with IOverwriteQuery

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

Example 7 with IOverwriteQuery

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

the class WorkflowImportOperation method createWorkflowFromFile.

/**
 * @param workflow the workflow dir to import
 * @param target the destination path to import the workflow to
 * @param monitor a progress monitor to report progress to
 * @return the created import operation
 */
protected ImportOperation createWorkflowFromFile(final WorkflowImportElementFromFile workflow, final IPath target, final IProgressMonitor monitor) {
    monitor.beginTask(workflow.getName(), 1);
    ImportOperation operation = null;
    if (workflow.isWorkflow()) {
        List<File> filesToImport = new ArrayList<File>();
        getFilesForWorkflow(filesToImport, workflow.getFile());
        operation = new ImportOperation(target, workflow.getFile(), FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

            @Override
            public String queryOverwrite(final String pathString) {
                return IOverwriteQuery.YES;
            }
        });
    } else {
        // store path to create a meta info file
        m_missingMetaInfoLocations.add(target);
    // no workflow -> no import
    }
    monitor.done();
    return operation;
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ArrayList(java.util.ArrayList) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) File(java.io.File)

Example 8 with IOverwriteQuery

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

the class WorkflowImportOperation method createWorkflowFromArchive.

/**
 * @param workflow workflow im port element
 * @param target the destination path of this workflow
 * @param monitor a submonitor to report progress to
 * @return the prepared import operation
 */
protected ImportOperation createWorkflowFromArchive(final WorkflowImportElementFromArchive workflow, final IPath target, final IProgressMonitor monitor) {
    // import only workflow -> the path to them will be created anyway
    // by ContainerGenerator in ImportOperation
    monitor.beginTask(workflow.getName(), 1);
    ImportOperation op = null;
    if (workflow.isWorkflow()) {
        op = new ImportOperation(target, workflow.getEntry(), workflow.getProvider(), new IOverwriteQuery() {

            @Override
            public String queryOverwrite(final String pathString) {
                return IOverwriteQuery.YES;
            }
        });
    } else {
        // store path to create a meta info file
        m_missingMetaInfoLocations.add(target);
    // no workflow -> no import
    }
    monitor.done();
    return op;
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation)

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