List of usage examples for org.eclipse.jdt.core IJavaElement getJavaProject
IJavaProject getJavaProject();
null
if this element is not contained in any Java project (for instance, the IJavaModel
is not contained in any Java project). From source file:net.sourceforge.metrics.ui.MetricsView.java
License:Open Source License
/** * react to selections elsewhere in the workbench * /* www .j a va2s .c o m*/ * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (!selection.isEmpty()) { if (selection instanceof IStructuredSelection) { IStructuredSelection l_structSelection = (IStructuredSelection) selection; if (l_structSelection.size() == 1) { // only one element allowed Object l_first = (l_structSelection).getFirstElement(); IJavaElement l_jElem = null; if (l_first instanceof IJavaElement) { l_jElem = (IJavaElement) l_first; } else if (l_first instanceof IResource) { l_jElem = (IJavaElement) ((IResource) l_first).getAdapter(IJavaElement.class); } if (l_jElem != null && canDoMetrics(l_jElem)) { try { if (l_jElem.getJavaProject().getProject().hasNature(pluginId + ".nature")) { setJavaElement(l_jElem, false); } } catch (CoreException l_ce) { // TODO GB 04/15/2005 ? what to do in such case Log.logError("project nature does not exist", l_ce); } } } } } }
From source file:nz.ac.massey.cs.jquest.views.SingleDependencyView.java
License:Open Source License
public void setSelectedElement(IJavaElement selection2) { this.selection = selection2; selectedProject = selection2.getJavaProject().getProject(); }
From source file:nz.co.senanque.madura.wizards.RuleNewWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *///from w w w . j a va2 s. c om private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IJavaElement) { IJavaElement ijp = (IJavaElement) obj; containerText.setText(ijp.getPath().toPortableString()); resource = ijp.getJavaProject().getProject(); } if (obj instanceof IFolder) { IFolder ijp = (IFolder) obj; containerText.setText(ijp.getFullPath().toPortableString()); resource = ijp; } if (obj instanceof IFile) { IFile ijp = (IFile) obj; IContainer container = ijp.getParent(); if (container instanceof IFolder) { IFolder f = (IFolder) container; containerText.setText(f.getFullPath().toPortableString()); resource = f; } else if (container instanceof IProject) { IProject p = (IProject) container; containerText.setText(p.getFullPath().toPortableString()); resource = p; } } } fileText.setText("new_file.rul"); }
From source file:nz.co.senanque.madura.wizards.WorkflowNewWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *//*from w w w. j a v a 2 s . c o m*/ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IJavaElement) { IJavaElement ijp = (IJavaElement) obj; containerText.setText(ijp.getPath().toPortableString()); resource = ijp.getJavaProject().getProject(); } if (obj instanceof IFolder) { IFolder ijp = (IFolder) obj; containerText.setText(ijp.getFullPath().toPortableString()); resource = ijp; } if (obj instanceof IFile) { IFile ijp = (IFile) obj; IContainer container = ijp.getParent(); if (container instanceof IFolder) { IFolder f = (IFolder) container; containerText.setText(f.getFullPath().toPortableString()); resource = f; } else if (container instanceof IProject) { IProject p = (IProject) container; containerText.setText(p.getFullPath().toPortableString()); resource = p; } } } fileText.setText("new_file.wrk"); }
From source file:org.antlr.eclipse.ui.editor.AntlrConfiguration.java
License:Open Source License
private IJavaProject getProject() { if (fEditor == null) return null; IJavaElement element = null; IEditorInput input = fEditor.getEditorInput(); IDocumentProvider provider = fEditor.getDocumentProvider(); if (provider instanceof ICompilationUnitDocumentProvider) { ICompilationUnitDocumentProvider cudp = (ICompilationUnitDocumentProvider) provider; element = cudp.getWorkingCopy(input); } else if (input instanceof IClassFileEditorInput) { IClassFileEditorInput cfei = (IClassFileEditorInput) input; element = cfei.getClassFile();/*w w w . ja va 2s . c o m*/ } if (element == null) return null; return element.getJavaProject(); }
From source file:org.apache.tapestrytools.ui.internal.wizards.NewTapestryComponentPage.java
License:Open Source License
private IProject getSelectedProject() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) return null; ISelection selection = window.getSelectionService().getSelection(); if (selection == null) return null; if (!(selection instanceof IStructuredSelection)) return null; IJavaElement element = getInitialJavaElement(selection); if (element != null && element.getJavaProject() != null) return element.getJavaProject().getProject(); IStructuredSelection stucturedSelection = (IStructuredSelection) selection; IProject project = getExtendedSelectedProject(stucturedSelection.getFirstElement()); if (project != null) { return project; }// w ww. j av a 2 s . co m if (selection instanceof TreeSelection && (((TreeSelection) selection).getPaths().length > 0)) { TreePath path = (((TreeSelection) selection).getPaths()[0]); if (path.getSegmentCount() > 0 && path.getSegment(0) instanceof IProject) { return (IProject) path.getSegment(0); } } return null; }
From source file:org.caesarj.ui.views.CaesarHierarchyView.java
License:Open Source License
/** * Refreshes the view using the current properties and this java element. * This method sets this java element as the active java element. * //ww w .ja v a 2 s .com * @param file the java element to use in the refresh */ public void refresh(IJavaElement file) { try { // Set the active project properties for the editor activeProjectProperties = ProjectProperties.create(file.getJavaProject().getProject()); // Set the active java element activeJavaElement = file; // Call refresh refresh(activeProjectProperties, activeJavaElement); } catch (Exception e) { refresh(); } }
From source file:org.caesarj.ui.views.CaesarHierarchyView.java
License:Open Source License
/** * Refreshes the view.//from ww w . j av a2 s.co m * * Checks if the properties have an ASM. If not, just print messages in the view. * * If yes, create new input objects for the treeviewer and list viewer. If error occurs, * set the messages is the view. * * @param properties * @param file */ public void refresh(ProjectProperties properties, IJavaElement file) { // Enable the buttons filterButton.setEnabled(true); toolButton.setEnabled(true); // Check if we already have an ASM for the project. If we don't have, // just call the update method with empty nodes (to show a message) and return if (properties == null || properties.getAsmManager() == null) { treeViewer.setInput(new RootNode(HierarchyNode.EMPTY)); listViewer.setInput(new LinearNode(HierarchyNode.EMPTY)); // Disable the buttons, since we don't have input filterButton.setEnabled(false); toolButton.setEnabled(false); return; } try { // Gets the absolute path for the project output directory String outputdir = properties.getProjectLocation() + properties.getOutputPath(); // Gets the filename for the input element String filename = file.getResource().getName(); // Try to get the class string, which is the packages + the file name String path = file.getResource().getProjectRelativePath().removeFileExtension().toOSString(); IPackageFragmentRoot[] roots = file.getJavaProject().getAllPackageFragmentRoots(); String clazz = null; for (int i = 0; i < roots.length; i++) { if (path.lastIndexOf(roots[i].getElementName()) != -1) { clazz = path.substring(roots[i].getElementName().length() + 1); } } // Create the input nodes with the factory RootNode rootNode = HierarchyModelFactory.createHierarchyTreeModel( properties.getAsmManager().getHierarchy(), filename, outputdir, implicitFilter, superView); LinearNode linearNode = HierarchyModelFactory.createHierarchyListModel(clazz, outputdir); // If the root node is EMPTY or if it doesn't have children, disable the buttons if (rootNode.getKind().equals(HierarchyNode.EMPTY) || rootNode.getChildren().length == 0) { // Disable the buttons, since we don't have input filterButton.setEnabled(false); toolButton.setEnabled(false); } // Set the input for the viewers treeViewer.setInput(rootNode); listViewer.setInput(linearNode); // Show 5 levels on the treeViewer treeViewer.expandToLevel(5); } catch (Exception e) { // If we have an error, set the messages in the view treeViewer.setInput(new RootNode(HierarchyNode.EMPTY)); listViewer.setInput(new LinearNode(HierarchyNode.EMPTY)); // Disable the buttons, since we don't have input filterButton.setEnabled(false); toolButton.setEnabled(false); } }
From source file:org.codecover.eclipse.CodeCoverPropertyTester.java
License:Open Source License
private boolean isCodeCoverActivated(IJavaElement receiver, String property, Object[] args, Object expectedValue) {//from www . j a va 2 s. co m IJavaProject javaProject = receiver.getJavaProject(); if (javaProject == null) { return false; } else { return CodeCoverPlugin.isCodeCoverActivated(javaProject.getProject()); } }
From source file:org.codehaus.groovy.eclipse.codeassist.tests.CompletionTestCase.java
License:Open Source License
public void performDummySearch(IJavaElement element) throws Exception { JavaModelManager.getIndexManager().indexAll(element.getJavaProject().getProject()); new SearchEngine().searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "XXXXXXXXX".toCharArray(), // make sure we search a concrete name. This is faster according to Kent SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS, SearchEngine.createJavaSearchScope(new IJavaElement[] { element }), new Requestor(), IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); }