@Override public void selectionChanged(IAction action, ISelection selection) { if (!(selection instanceof IStructuredSelection)) { project = null; return; } IStructuredSelection ssel = (IStructuredSelection) selection; Object firstElement = ssel.getFirstElement(); if(firstElement == null) { project = null; return; } project = getProject(firstElement); if (project != null) { return; } if (firstElement instanceof IResource) { project = ((IResource) firstElement).getProject(); } if (project != null) { return; } if (firstElement instanceof IProjectNature) { project = ((IProjectNature) firstElement).getProject(); } }
public void addNature(IProject project, String nature_id) { if(project.isOpen() == false) { return; } try { IProjectDescription pd = project.getDescription(); IProjectNature nature = project.getNature(nature_id); if(nature == null) { List<String> newNatures = new ArrayList<String>(); newNatures.addAll(Arrays.asList(pd.getNatureIds())); newNatures.add(nature_id); pd.setNatureIds(newNatures.toArray(new String[newNatures.size()])); project.setDescription(pd, null); } } catch(Exception e) { /* Do Nothing */ } }
@Override public void decorate(Object element, IDecoration decoration) { // TODO Auto-generated method stub if(element instanceof IFolder) { try{ IFolder folder = (IFolder)element; IProjectNature nature = folder.getProject().getNature(WTNewProjectNature.ID); if(nature!=null){ //Search XMI IFile file = folder.getFile(folder.getName().concat(".xmi")); if(file.exists()){ XMI_File file_xmi = new XMI_File(URI.createFileURI(file.getFullPath().toString())); EObject root = file_xmi.Get_Root(); } } }catch(Throwable th){/*Ignore if file is not found*/ } } }
private SpifeGenericProjectNature getSpifeNature(IResource resource) { SpifeLabelProviderNature labelProviderNature = getSpifeLabelProviderNature(resource); if (labelProviderNature != null) { return labelProviderNature; } try { IProject project = resource.getProject(); if (project != null) { IProjectNature nature = project.getNature(SpifeProjectNature.ID); if (nature instanceof SpifeProjectNature) { return (SpifeProjectNature) nature; } } } catch (CoreException e) { //silent fail } return null; }
private SpifeLabelProviderNature getSpifeLabelProviderNature(IResource resource) { IProject project = resource.getProject(); if (project != null) { try { IProjectDescription description = project.getDescription(); String[] natureIds = description.getNatureIds(); List<SpifeLabelProviderNature> labelProviderNatures = new ArrayList(); for (String natureID : natureIds) { IProjectNature nature = project.getNature(natureID); if (nature instanceof SpifeLabelProviderNature) { labelProviderNatures.add((SpifeLabelProviderNature) nature); } } if (labelProviderNatures.size() > 1) { LogUtil.error("Found " + labelProviderNatures.size() + " SpifeLabelProviderNature's. Can't have more than one! Returning generic."); } else if (labelProviderNatures.size() == 1){ return labelProviderNatures.get(0); } } catch (CoreException e) { //silent fail } } return null; }
public static boolean isOnBuildPath(IJavaElement element) { //fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051 if (element.getElementType() == IJavaElement.JAVA_PROJECT) return true; IJavaProject project= element.getJavaProject(); try { if (!project.isOnClasspath(element)) return false; IProject resourceProject= project.getProject(); if (resourceProject == null) return false; IProjectNature nature= resourceProject.getNature(JavaCore.NATURE_ID); // We have a Java project if (nature != null) return true; } catch (CoreException e) { } return false; }
public static IJavaProject addJavaNature(IProject project, boolean rawClasspath) throws CoreException, JavaModelException { IProjectNature nature = project.getNature(ProjectConstants.JAVA_NATURE_ID); if(nature==null){ ProjectUtils.addNatureToProject(project, true, ProjectConstants.JAVA_NATURE_ID); } IJavaProject javaProject = JavaCore.create(project); IFolder targetFolder = project.getFolder("target"); targetFolder.create(false, true, null); javaProject.setOutputLocation(targetFolder.getFullPath(), null); Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); if(rawClasspath){ entries.addAll(Arrays.asList(getClasspathEntries(javaProject))); } if(nature==null){ entries.add(JavaRuntime.getDefaultJREContainerEntry()); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); return javaProject; }
public IFile createRadlFile(String folderName, String serviceName, IProgressMonitor monitor, IWorkspaceRoot root) throws CoreException { IFolder folder = root.getFolder(new Path(folderName)); if (!folder.exists()) { ensureFolder(monitor, folder); } final IFile result = folder.getFile(serviceNameToFileName(serviceName)); try (InputStream stream = getRadlSkeleton(serviceName)) { if (result.exists()) { result.setContents(stream, true, true, monitor); } else { result.create(stream, true, monitor); } } catch (IOException e) { // NOPMD EmptyCatchBlock } IProjectNature nature = new RadlNature(); nature.setProject(folder.getProject()); nature.configure(); return result; }
public static @Nullable RustNature get(final @Nullable IProject p, boolean askAddNature) { if (p == null) { return null; } try { IProjectNature nat = p.getNature(NATURE_ID); if (nat instanceof RustNature) { return (RustNature) nat; } else if (askAddNature) { final boolean answer[] = new boolean[] {false}; Display.getDefault().syncExec(() -> { answer[0] = MessageDialog.openQuestion(null, "No Rust nature", "No Rust nature was found for the project " + p.getName() + ".\n" + "Do you want to add the Rust nature?"); }); if (answer[0]) { addNatureToProject(p); return get(p); } } } catch (CoreException e) { e.printStackTrace(); } return null; }
public static ScenarioNature getScenarioNature(IProject project) { if (project == null) { return null; } try { IProjectNature nature = project.getNature(NATURE_ID); if (nature instanceof ScenarioNature) { return (ScenarioNature) nature; } } catch (CoreException e) { e.printStackTrace(); } return null; }
/** * @param project the project we want to know about (if it is null, null is returned) * @return the django nature for a project (or null if it does not exist for the project) * * @note: it's synchronized because more than 1 place could call getDjangoNature at the same time and more * than one nature ended up being created from project.getNature(). */ public static DjangoNature getDjangoNature(IProject project) { if (project != null && project.isOpen()) { try { if (project.hasNature(DJANGO_NATURE_ID)) { synchronized (lockGetNature) { IProjectNature n = project.getNature(DJANGO_NATURE_ID); if (n instanceof DjangoNature) { return (DjangoNature) n; } } } } catch (CoreException e) { Log.logInfo(e); } } return null; }
public void setElement(IAdaptable element) { if (element instanceof IProject) { project = (IProject) element; } else if (element instanceof IProjectNature) { IProjectNature pn = (IProjectNature) element; project = pn.getProject(); } }
public static boolean isProject(IProject pro) { IProjectNature nature_modular = null; try { nature_modular = pro.getNature(Project_Nature); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(nature_modular==null) return false; else return true; }
@SuppressWarnings("unchecked") public EList<?> getChoicesOfValuesWS(String modularNature, EClass anEClass){ EList<EObject> result = new BasicEList<EObject>(); IProject[] projs = ResourcesPlugin.getWorkspace().getRoot().getProjects(); int count = projs.length; IProjectNature nat = null; IProject current_pro = null; ResourceSet set = new ResourceSetImpl(); Resource res = null; EList<?> project_result = null; try { for (int i = 0; i < count; i++) { current_pro = projs[i]; nat = current_pro.getNature(modularNature); if(nat!=null){ IFile fil = current_pro.getFile(new Path(current_pro.getName() + ".xmi")); res = set.createResource(URI.createPlatformResourceURI(fil.getFullPath().toString(), true)); project_result = getChoicesOfValuesProject(res, anEClass); if(project_result!=null) { result.addAll((EList<? extends EObject>) project_result); project_result = null; } } } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
private boolean checkProject (InputAlternative ia) { String projectName = ia.getExtractedProjectName(); if (projectName == null || projectName.isEmpty()) { ia.getSelfStatus().addWarning(INFO_NO_PROJECT_NAME, IValidationStatus.SEVERITY_ERROR, "Project is missing."); return false; } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); if (project == null || !project.exists()) { ia.getSelfStatus().addWarning(INFO_NO_PROJECT, IValidationStatus.SEVERITY_ERROR, "Project does not exist. -> Project Name = "+projectName); return false; } final String JAVA_NATURE_ID = "org.eclipse.jdt.core.javanature"; try { IProjectNature nature = project.getNature(JAVA_NATURE_ID); if (nature == null) throw new Exception(); } catch (Exception e) { ia.getSelfStatus().addWarning(INFO_NO_PROJECT_JAVA, IValidationStatus.SEVERITY_ERROR, "Project is not Java nature."); return false; } return true; }
/** * add the srcDir as a source directory in the java project, if it is not yet added */ private void setFolderAsSourceFolder(final IProject proj, final String srcDir) { try { String _name = proj.getName(); String _plus = ("/" + _name); String _plus_1 = (_plus + "/"); final String expectedSrcDir = (_plus_1 + srcDir); final IProjectNature nat = proj.getNature(JavaCore.NATURE_ID); if ((nat instanceof IJavaProject)) { boolean found = false; final IJavaProject jvp = ((IJavaProject) nat); IClasspathEntry[] _resolvedClasspath = jvp.getResolvedClasspath(true); for (final IClasspathEntry cpe : _resolvedClasspath) { if (((!found) && expectedSrcDir.equals(cpe.getPath().toString()))) { int _entryKind = cpe.getEntryKind(); boolean _equals = (_entryKind == IClasspathEntry.CPE_SOURCE); found = _equals; } } if ((!found)) { final Path path = new Path(expectedSrcDir); final IClasspathEntry srcEntry = JavaCore.newSourceEntry(path); IClasspathEntry[] _rawClasspath = jvp.getRawClasspath(); final ArrayList<IClasspathEntry> newClassPath = new ArrayList<IClasspathEntry>((Collection<? extends IClasspathEntry>)Conversions.doWrapArray(_rawClasspath)); newClassPath.add(srcEntry); NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); jvp.setRawClasspath(((IClasspathEntry[])Conversions.unwrapArray(newClassPath, IClasspathEntry.class)), _nullProgressMonitor); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public ProjectStub(File file, IProjectNature nature, boolean addNullChild, List<Object> additionalChildren) { Assert.isTrue(file.exists() && file.isDirectory()); this.projectRoot = file; this.nature = nature; this.addNullChild = addNullChild; this.additionalChildren = additionalChildren; }
@Override public IProjectNature getNature(String natureId) throws CoreException { if (nature == null) { throw new RuntimeException("not expected"); } return nature; }
/** * This method will check the given project and if it's a java project, will create a project modules manager * that can be used to get things from it as we need in pydev. */ public static IModulesManager createJavaProjectModulesManagerIfPossible(IProject project) { if (JDTSupported == false) { return null; } try { if (project.isOpen()) { IProjectNature nature = project.getNature(JavaCore.NATURE_ID); if (nature instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) nature; return new JavaProjectModulesManager(javaProject); } } } catch (Throwable e) { if (JythonModulesManagerUtils.isOptionalJDTClassNotFound(e)) { //ignore it at this point: we don't have JDT... set the static variable to it and don't even //try to get to this point again (no need to log it or anything). JDTSupported = false; return null; } else { Log.log(e); } } return null; }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { // TODO Auto-generated method stub ISelectionService serv = (ISelectionService) serviceLocator.getService(ISelectionService.class); ISelection selection = serv.getSelection(); TreeSelection treeselection = (TreeSelection)selection; Object firstelement = treeselection.getFirstElement(); if(firstelement instanceof IProject || firstelement instanceof IFolder){ IProject pro = null; if(firstelement instanceof IProject) pro = (IProject)firstelement; if(firstelement instanceof IFolder) pro = ((IFolder)firstelement).getProject(); try { IProjectNature nature = pro.getNature(WTNewProjectNature.ID); if(nature==null) return; } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } MenuManager menu = new MenuManager(); menu.setMenuText("New WT"); if(firstelement instanceof IProject) { CommandContributionItemParameter pcommand = new CommandContributionItemParameter(serviceLocator, "", "org.eclipse.ui.newWizard", CommandContributionItem.STYLE_PUSH); pcommand.parameters = new HashMap<String,String>(); pcommand.parameters.put("newWizardId", "org.mondo.wt.cstudy.collectioninputoutput.collectioninputoutputNewFile"); CommandContributionItem itemitsInputOutput = new CommandContributionItem(pcommand); menu.add(itemitsInputOutput); pcommand.parameters.put("newWizardId", "org.mondo.wt.cstudy.mainsubsystem.mainsubsystemNewFile"); CommandContributionItem itemitsSubsystems = new CommandContributionItem(pcommand); menu.add(itemitsSubsystems); } else if(firstelement instanceof IFolder) { IFolder fol = (IFolder)firstelement; IPath filePath = fol.getFullPath().append("/"+fol.getName().concat(".xmi")); XMI_File file = new XMI_File(URI.createPlatformResourceURI(filePath.toString(), true), true); EObject root = null; try { root = file.Get_Root(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if(root!=null) { } } additions.addContributionItem(menu, null); } }
@Override public IProjectNature getNature(String s) throws CoreException { throw new UnsupportedOperationException(); }
/** * {@inheritDoc} */ @Override public IProjectNature getNature(final String natureId) throws CoreException { return resource().getNature(natureId); }
@Override public IProjectNature getNature(String natureId) throws CoreException { return null; }
public void setNature(IProjectNature pythonNatureStub) { this.nature = pythonNatureStub; }
@Override public IProjectNature getNature(String natureId) throws CoreException { return this.nature; }
public ProjectStub(File file, IProjectNature nature) { this(file, nature, false); }
public ProjectStub(File file, IProjectNature nature, boolean addNullChild) { this(file, nature, addNullChild, new ArrayList<Object>()); }
/** * Returns if the nature is not null and instance of IJavaProject. * @param nature the nature of a project * @return whether the nature is not null and instance of IJavaProject. */ private boolean isNatureNotNullAndInstanceOfIJavaProject(IProjectNature nature) { return nature != null && nature instanceof IJavaProject; }