IProgressMonitor progressMonitor = new NullProgressMonitor(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("DesiredProjectName"); project.create(progressMonitor); project.open(progressMonitor);
IViewPart [] parts = MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews(); IProject activeProject = null; for(int i=0;i<parts.length;i++) { if(parts[i] instanceof ResourceNavigator) { ResourceNavigator navigator = (ResourceNavigator)parts[i]; StructuredSelection sel = (StructuredSelection)navigator.getTreeViewer().getSelection(); IResource resource = (IResource)sel.getFirstElement(); activeProject = resource.getProject(); break; } } String activeProjectName = activeProject .getName();
IEditorPart editorPart = getSite().getWorkbenchWindow().getActivePage().getActiveEditor(); if(editorPart != null) { IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ; IFile file = input.getFile(); IProject activeProject = file.getProject(); String activeProjectName = activeProject.getName(); //... use activeProjectName }
private boolean hasClosedProjectsInWorkspace() { IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen()) return true; } return false; }
/** * Returns whether the given project is available. * * @param projectName project name * @return whether the project exists and is open */ private boolean isAvailable(String projectName) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); return project.exists() && project.isOpen(); }
private IPathVariableManager getManager(IPath workspacePath) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(workspacePath); if (resource != null) return resource.getPathVariableManager(); return workspaceRoot.getFile(workspacePath).getPathVariableManager(); }
private static IProject getModuleProject( final IMarker marker ) { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final String moduleProjectName = marker.getAttribute( ATTR_MODULE_PROJECT, null ); return ws.getRoot().getProject( moduleProjectName ); }
private void createProj(IProject newProj, boolean isJavaProject) throws CoreException { newProj.create(null); IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(newProj.getName()); // if (isJavaProject) // description.setNatureIds(new String[]{JavaCore.NATURE_ID}); description.setLocation(null); newProj.open(null); newProj.setDescription(description, null); }
@Override public IResource getResource() { IPath fullPath= fFileState.getFullPath(); return ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); } }
/** * @return the location or <code>null</code> */ private IPath getWorkspaceLocation() { return ResourcesPlugin.getWorkspace().getRoot().getLocation(); } }
public IProject findUniqueProject(IWorkspace workspace, String basename) { IProject project = null; String name; for (int i = 1; project == null || project.exists(); i++) { name = (i < 2)? basename:basename + " ("+ i +")"; project = workspace.getRoot().getProject(name); } return project; }
@Override public ISchedulingRule computeCommitRule() { IResourceRuleFactory factory= ResourcesPlugin.getWorkspace().getRuleFactory(); return factory.modifyRule(fFile); }
IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class); if (file == null) throw new FileNotFoundException(); String content = IOUtils.toString(file.getContents(), file.getCharset());
public void addMarkerToResource(IResource target, String message) throws CoreException { IMarker marker = target.createMarker(ID); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); }
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof IAdaptable) { IProject project = (IProject)((IAdaptable)firstElement).getAdapter(IProject.class); IPath path = project.getFullPath(); System.out.println(path); } }
private boolean hasClosedProjectsInWorkspace() { IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen()) return true; } return false; } }
private String ensureUniqueProjectName(String projectName) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); String newName = projectName; int index = 0; IProject proj = root.getProject(newName); while (proj.exists()) { index++; newName = projectName + index; proj = root.getProject(newName); } return newName; }
private IPathVariableManager getManager(IPath workspacePath) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(workspacePath); if (resource != null) return resource.getPathVariableManager(); return workspaceRoot.getFile(workspacePath).getPathVariableManager(); }
private boolean hasClosedProjectsInWorkspace() { IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen()) return true; } return false; }
private boolean hasClosedProjectsInWorkspace() { IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen()) return true; } return false; } }