Search in sources :

Example 86 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class NewProjectWizardPage method dialogChanged.

/**
 * Ensures that the text field is set properly.
 */
private void dialogChanged() {
    // check if a name was entered
    String projectName = m_projectName.getText().trim();
    if (projectName.length() == 0) {
        updateStatus(m_elementName + " name must be specified");
        return;
    }
    IStatus validName = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
    if (!validName.isOK()) {
        updateStatus(m_elementName + " name is not valid!");
        return;
    }
    // check whether this container already exists
    IPath path = getWorkflowPath();
    IContainer container = (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (container != null) {
        updateStatus(m_elementName + " name already exists.");
        return;
    }
    updateStatus(null);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IContainer(org.eclipse.core.resources.IContainer)

Example 87 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class NewProjectWizardPage method handleBrowseButton.

private void handleBrowseButton() {
    WorkflowGroupSelectionDialog dialog = new WorkflowGroupSelectionDialog(getShell());
    dialog.setInitialSelection(new Path(m_destinationUI.getText()));
    if (dialog.open() == IDialogConstants.OK_ID) {
        IContainer c = dialog.getSelectedWorkflowGroup();
        m_destinationUI.setText(c.getFullPath().toString());
    }
    dialogChanged();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) WorkflowGroupSelectionDialog(org.knime.workbench.ui.wizards.workflowgroup.WorkflowGroupSelectionDialog) IContainer(org.eclipse.core.resources.IContainer)

Example 88 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class WorkflowImportSelectionPage method handleWorkflowGroupBrowseButtonPressed.

private void handleWorkflowGroupBrowseButtonPressed() {
    // get the value from the text field
    String wfGroupPath = m_targetTextUI.getText();
    IPath initialPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath();
    // if not yet set take workflow root
    if (wfGroupPath != null && !wfGroupPath.trim().isEmpty()) {
        initialPath = new Path(wfGroupPath);
    }
    WorkflowGroupSelectionDialog dialog = new WorkflowGroupSelectionDialog(getShell());
    dialog.setInitialSelection(initialPath);
    int returnCode = dialog.open();
    if (returnCode == IDialogConstants.OK_ID) {
        // set the newly selected workflow group as destination
        IContainer target = dialog.getSelectedWorkflowGroup();
        if (target != null && !target.equals(ResourcesPlugin.getWorkspace().getRoot())) {
            m_targetTextUI.setText(target.getFullPath().toString());
        } else {
            m_targetTextUI.setText(Path.ROOT.toString());
        }
    }
    validateWorkflows();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) WorkflowGroupSelectionDialog(org.knime.workbench.ui.wizards.workflowgroup.WorkflowGroupSelectionDialog) IContainer(org.eclipse.core.resources.IContainer)

Example 89 with IContainer

use of org.eclipse.core.resources.IContainer 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 90 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class WorkflowGroupSelectionDialog method pathToTreeSelection.

/**
 * @param path the path of a resource
 * @return the selection to be passed to a tree in order to select the
 *  resource denoted by the given path
 */
public static IStructuredSelection pathToTreeSelection(final IPath path) {
    if (path != null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IResource r = root.findMember(path);
        if (r != null && !r.equals(root)) {
            IContainer c = r.getParent();
            if (r instanceof IContainer) {
                c = (IContainer) r;
            }
            String[] segments = c.getFullPath().segments();
            Object[] treePathSegments = new Object[segments.length];
            // find all parents in order to create the path segments
            int i = 1;
            while (c.getParent() != null) {
                treePathSegments[treePathSegments.length - i] = c;
                c = c.getParent();
                i++;
            }
            TreePath treePath = new TreePath(treePathSegments);
            return new TreeSelection(treePath);
        }
    }
    // default: return empty selection
    return new TreeSelection();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9