Java Code Examples for org.eclipse.core.resources.IContainer#getProject()
The following examples show how to use
org.eclipse.core.resources.IContainer#getProject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUtils.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Create the components of the provided folder as required. Assumes the containing project * already exists. * * @param folder the path to be created if it does not already exist * @param monitor may be {@code null} * @throws CoreException on error */ public static void createFolders(IContainer folder, IProgressMonitor monitor) throws CoreException { IPath path = folder.getProjectRelativePath(); IContainer current = folder.getProject(); SubMonitor progress = SubMonitor.convert(monitor, path.segmentCount()); for (String segment : path.segments()) { IFolder child = current.getFolder(new Path(segment)); if (!child.exists()) { child.create(true, true, progress.newChild(1)); } else { progress.worked(1); } current = child; } }
Example 2
Source File: NewFileWizardPage.java From gama with GNU General Public License v3.0 | 6 votes |
private void addProjectTemplates(final Map<String, String> templates) { final IContainer container = findContainer(); if (container == null) { return; } final IProject project = container.getProject(); if (project == null) { return; } final IFolder folder = project.getFolder("templates"); if (!folder.exists()) { return; } try { for (final IResource resource : folder.members()) { final String name = resource.getName(); if (name.contains(".template")) { templates.put(name.replaceAll(".template", ""), resource.getProjectRelativePath().toString()); } } } catch (final CoreException e) { e.printStackTrace(); } }
Example 3
Source File: PyRemSrcFolder.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override protected int doActionOnContainer(IContainer container, IProgressMonitor monitor) { try { IProject project = container.getProject(); IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project); if (pythonPathNature == null) { Log.log("Unable to get PythonNature on project: " + project); return 0; } OrderedMap<String, String> projectSourcePathMap = pythonPathNature .getProjectSourcePathResolvedToUnresolvedMap(); String pathToRemove = container.getFullPath().toString(); if (projectSourcePathMap.remove(pathToRemove) == null) { return 0; } //Set back the map with the variables, not the one with resolved vars. pythonPathNature.setProjectSourcePath(StringUtils.join("|", projectSourcePathMap.values())); PythonNature.getPythonNature(project).rebuildPath(); return 1; } catch (CoreException e) { Log.log(IStatus.ERROR, "Unexpected error setting project properties", e); } return 0; }
Example 4
Source File: TestFileCopier.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void ensureProjectExists(IContainer container) { IProject project = container.getProject(); if (project.exists()) { if (!project.isOpen()) { throw new RuntimeException("Project " + project.getName() + " closed"); } } else { try { testProject = projectFactory.createTestProject(project, new NullProgressMonitor()); project.open(new NullProgressMonitor()); } catch (CoreException e) { throw new RuntimeException(e); } } }
Example 5
Source File: JSNodeTypeInferrer.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
protected IProject getProject() { URI root = _index.getRoot(); IPath containerPath = org.eclipse.core.filesystem.URIUtil.toPath(root); if (containerPath == null) { return null; } IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(containerPath); if (container == null) { return null; } return container.getProject(); }
Example 6
Source File: PyAddSrcFolder.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override protected int doActionOnContainer(IContainer container, IProgressMonitor monitor) { try { IProject project = container.getProject(); IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project); if (pythonPathNature == null) { Log.log("Unable to get PythonNature on project: " + project); return 0; } OrderedMap<String, String> projectSourcePathMap = pythonPathNature .getProjectSourcePathResolvedToUnresolvedMap(); String pathToAdd = container.getFullPath().toString(); if (projectSourcePathMap.containsKey(pathToAdd)) { return 0; } pathToAdd = PyStructureConfigHelpers.convertToProjectRelativePath(project.getFullPath().toString(), pathToAdd); Collection<String> values = new ArrayList<String>(projectSourcePathMap.values()); values.add(pathToAdd); pythonPathNature.setProjectSourcePath(StringUtils.join("|", values)); PythonNature.getPythonNature(project).rebuildPath(); return 1; } catch (CoreException e) { Log.log(IStatus.ERROR, "Unexpected error setting project properties", e); } return 0; }
Example 7
Source File: AbstractNewModelWizard.java From gama with GNU General Public License v3.0 | 4 votes |
/** * The worker method. It will find the container, create the file if missing or just replace its contents, and open * the editor on the newly created file. */ private void doFinish(final IProgressMonitor monitor) throws CoreException { final String containerName = getPage().getContainerName(); final String fileName = getPage().getFileName(); final String author = getPage().getAuthor(); final String title = getPage().getModelName(); final String desc = getPage().getDescription(); final boolean createDoc = getPage().createDoc(); monitor.beginTask("Creating " + fileName, 2); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IResource container = findContainer(monitor, containerName, root); if (container == null) { return; } IContainer folder = (IContainer) container; final IProject project = folder.getProject(); /* Add the models folder */ if (project == container) { final IFolder modelFolder = folder.getFolder(new Path(getDefaultFolderForModels())); if (!modelFolder.exists()) { modelFolder.create(true, true, monitor); } folder = modelFolder; } /* Add the doc folder */ if (createDoc) { final IFolder libFolder = project.getFolder(new Path("doc")); if (!libFolder.exists()) { libFolder.create(true, true, monitor); } } final IFile file = folder.getFile(new Path(fileName)); final String template = getPage().getTemplatePath(); try (InputStream streamModel = getInputStream(folder, template, title, author, desc)) { ResourceManager.getInstance().reveal(file); file.create(streamModel, true, monitor); if (createDoc) { try (InputStream resourceStream = openContentStreamHtmlFile(title, desc, author);) { final IFile htmlFile = project.getFile(new Path("doc/" + title + ".html")); htmlFile.create(resourceStream, true, monitor); } } } catch (final IOException e) { e.printStackTrace(); } monitor.worked(1); monitor.setTaskName("Opening file for editing..."); GAMA.getGui().editModel(null, file); monitor.worked(1); }