Search in sources :

Example 1 with ContainerGenerator

use of org.eclipse.ui.dialogs.ContainerGenerator in project che by eclipse.

the class ImportOperation method execute.

/* (non-Javadoc)
     * Method declared on WorkbenchModifyOperation.
     * Imports the specified file system objects from the file system.
     */
protected void execute(IProgressMonitor progressMonitor) {
    monitor = progressMonitor;
    try {
        if (selectedFiles == null) {
            //Set the amount to 1000 as we have no idea of how long this will take
            monitor.beginTask("Importing:", 1000);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(Arrays.asList(new Object[] { source }));
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importRecursivelyFrom(source, POLICY_DEFAULT);
            //Be sure it finishes
            monitor.worked(90);
        } else {
            // Choose twice the selected files size to take folders into account
            int creationCount = selectedFiles.size();
            monitor.beginTask("Importing:", creationCount + 100);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(selectedFiles);
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importFileSystemObjects(selectedFiles);
            monitor.done();
        }
    } catch (CoreException e) {
        errorTable.add(e.getStatus());
    } finally {
        monitor.done();
    }
}
Also used : ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with ContainerGenerator

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

the class WorkflowGroupCreationOperation method execute.

/**
 * {@inheritDoc}
 */
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    ContainerGenerator generator = new ContainerGenerator(m_targetPath);
    m_resultContainer = generator.generateContainer(monitor);
    if (m_resultContainer instanceof IProject) {
        // get project description
        // set nature
        // set description
        final IProject project = (IProject) m_resultContainer;
        IProjectDescription desc = project.getDescription();
        desc.setNatureIds(new String[] { KNIMEWorkflowSetProjectNature.ID });
        project.setDescription(desc, monitor);
    // only one workflow group can be created at a time
    // -> thus, only necessary to create this meta info file
    }
    // this has to be done in any case!
    MetaInfoFile.createMetaInfoFile(new File(m_resultContainer.getLocationURI()), false);
    m_resultContainer.refreshLocal(IResource.DEPTH_ONE, monitor);
}
Also used : ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) IProject(org.eclipse.core.resources.IProject)

Example 3 with ContainerGenerator

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

the class NewProjectWizard method doFinish.

/**
 * Worker method, creates the project using the given options.
 *
 * @param workflowPath path of the workflow to create in workspace
 * @param monitor Progress monitor
 * @throws CoreException if error while creating the project
 */
public static void doFinish(final IPath workflowPath, final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(workflowPath);
    if (resource != null) {
        throwCoreException("Resource \"" + workflowPath.toString() + "\" does already exist.", null);
    }
    // check if there is a folder with the same name on the file system
    // see bug (http://bimbug.inf.uni-konstanz.de/show_bug.cgi?id=1912)
    IPath rootLocation = root.getLocation();
    if (rootLocation != null) {
        IPath absolutePath = rootLocation.append(workflowPath);
        if (absolutePath.toFile().exists()) {
            throwCoreException("Resource " + workflowPath + " already exists!", null);
        }
    }
    ContainerGenerator generator = new ContainerGenerator(workflowPath);
    IContainer containerResult = generator.generateContainer(monitor);
    if (containerResult instanceof IProject) {
        IProject project = (IProject) containerResult;
        // open the project
        project.open(monitor);
        // Create project description, set the nature IDs and build-commands
        try {
            // set the nature id of the project is enough
            // the name is already set by IProject#create()
            IProjectDescription description = project.getDescription();
            description.setNatureIds(new String[] { KNIMEProjectNature.ID });
            project.setDescription(description, monitor);
        } catch (CoreException ce) {
            throwCoreException("Error while creating project description for " + project.getName(), ce);
        }
    }
    // 
    // 2. Create the optional files, if wanted
    // 
    final IFile defaultFile = containerResult.getFile(new Path(WorkflowPersistor.WORKFLOW_FILE));
    InputStream is = new ByteArrayInputStream(new byte[0]);
    defaultFile.create(is, true, monitor);
    // open the default file, if it was created
    // open the model file in the editor
    monitor.setTaskName("Opening file for editing...");
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            try {
                IDE.openEditor(page, defaultFile, true);
            } catch (PartInitException e) {
            // ignore it
            }
        }
    });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 4 with ContainerGenerator

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

the class WorkflowImportOperation method createMetaInfo.

private void createMetaInfo() throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (IPath p : m_missingMetaInfoLocations) {
        // to be sure that target location indeed exists -> create it
        ContainerGenerator generator = new ContainerGenerator(p);
        generator.generateContainer(new NullProgressMonitor());
        p = root.getLocation().append(p);
        File parent = p.toFile();
        MetaInfoFile.createMetaInfoFile(parent, false);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) File(java.io.File)

Example 5 with ContainerGenerator

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

the class KnimeResourceUtil method createContainer.

/**
 * Creates a container with the specified path (resource must not exist!).
 * Return true if the container exists at the end, false if not. Creates
 * meta info and projects files as required by KNIME.
 *
 * @param dest
 * @return
 */
private static boolean createContainer(final IPath dest) {
    int newLevel = 0;
    IPath p = dest.removeLastSegments(1);
    while (!ResourcesPlugin.getWorkspace().getRoot().exists(p)) {
        newLevel++;
        p = dest.removeLastSegments(newLevel + 1);
    }
    final ContainerGenerator cg = new ContainerGenerator(dest);
    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    cg.generateContainer(monitor);
                } catch (CoreException ce) {
                // we check later
                }
            }
        });
    } catch (InvocationTargetException e) {
    // we check later
    } catch (InterruptedException e) {
    // we check later
    }
    while (newLevel > 0) {
        // we created a new directory, create metainfo files in all levels
        IResource newRes = ResourcesPlugin.getWorkspace().getRoot().findMember(dest.removeLastSegments(newLevel));
        URI rawLoc = newRes.getLocationURI();
        if (rawLoc != null) {
            File projLoc = new File(rawLoc);
            MetaInfoFile.createMetaInfoFile(projLoc, dest.segmentCount() == 1);
        }
        newLevel--;
    }
    try {
        ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (CoreException e) {
    // don't refresh then
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) ZipFile(java.util.zip.ZipFile) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

ContainerGenerator (org.eclipse.ui.dialogs.ContainerGenerator)5 File (java.io.File)3 CoreException (org.eclipse.core.runtime.CoreException)3 IPath (org.eclipse.core.runtime.IPath)3 MetaInfoFile (org.knime.workbench.ui.metainfo.model.MetaInfoFile)3 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IProjectDescription (org.eclipse.core.resources.IProjectDescription)2 IResource (org.eclipse.core.resources.IResource)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 ZipFile (java.util.zip.ZipFile)1 IContainer (org.eclipse.core.resources.IContainer)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1