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 checkEnabled(IStructuredSelection selection) { if (selection.size() != 1) return false; return selection.getFirstElement() instanceof IJavaElement; }
public static boolean isConvertAnonymousAvailable(final IStructuredSelection selection) throws JavaModelException { if (selection.size() == 1) { if (selection.getFirstElement() instanceof IType) { return isConvertAnonymousAvailable((IType) selection.getFirstElement()); } } return false; }
private static IJavaElement getJavaElement(IStructuredSelection selection) { if (selection.size() != 1) return null; Object first= selection.getFirstElement(); if (! (first instanceof IJavaElement)) return null; return (IJavaElement)first; }
private boolean isBuildTarget(ISelection s) { if (!(s instanceof IStructuredSelection)) return false; IStructuredSelection selection= (IStructuredSelection)s; if (selection.size() != 1) return false; return selection.getFirstElement() instanceof IJavaProject; } }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { final IType type= (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
/** * {@inheritDoc} */ @Override protected void setInput(ISelection selection) { super.setInput(selection); if (!selection.isEmpty()) { assignment = (ChartingMethodSensorAssignment) ((IStructuredSelection) selection).getFirstElement(); } else { assignment = null; // NOPMD } }
public static boolean isMoveMethodAvailable(final IStructuredSelection selection) throws JavaModelException { if (selection.size() == 1) { final Object first= selection.getFirstElement(); return first instanceof IMethod && isMoveMethodAvailable((IMethod) first); } return false; }
private ISourceReference getFirstSelectedSourceReference(final SelectionChangedEvent event) { final ISelection s= event.getSelection(); if (!(s instanceof IStructuredSelection)) return null; final IStructuredSelection ss= (IStructuredSelection) s; if (ss.size() != 1) return null; final Object first= ss.getFirstElement(); if (!(first instanceof ISourceReference)) return null; return (ISourceReference) first; }
private IResource getResource(IStructuredSelection selection) { if (selection.size() != 1) return null; Object element= selection.getFirstElement(); if (element instanceof IResource) return (IResource)element; if (element instanceof IJavaElement) return getResource((IJavaElement)element); return null; }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if (getSelectedFields(selection) != null) return true; if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { IType type= (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnnotation() && !type.isAnonymous(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
private void edit() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); Object[] objects= selection.toArray(); if ((objects == null) || (objects.length != 1)) return; TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); edit(data); }
public static boolean isInlineMethodAvailable(final IStructuredSelection selection) throws JavaModelException { if (selection.isEmpty() || selection.size() != 1) return false; final Object first= selection.getFirstElement(); return (first instanceof IMethod) && isInlineMethodAvailable(((IMethod) first)); }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
@Override public void run(IStructuredSelection selection) { if (!canEnableFor(selection)) return; IJavaElement element= (IJavaElement)selection.getFirstElement(); if (!ActionUtil.isProcessable(getShell(), element)) return; run(element); }
@Override public void doubleClick(DoubleClickEvent event) { TreeViewer viewer= (TreeViewer)getViewer(); Object element= ((IStructuredSelection)event.getSelection()).getFirstElement(); if (viewer.isExpandable(element)) viewer.setExpandedState(element, !viewer.getExpandedState(element)); } });
@Override public void selectionChanged(IStructuredSelection structuredSelection) { super.selectionChanged(structuredSelection); Object element= structuredSelection.getFirstElement(); if (element instanceof URL) { setText(InfoViewMessages.OpenInBrowserAction_url_label); setToolTipText(InfoViewMessages.OpenInBrowserAction_url_toolTip); } else { setText(ActionMessages.OpenAttachedJavadocAction_label); setToolTipText(ActionMessages.OpenAttachedJavadocAction_tooltip); } }
@Override public void menuAboutToShow(IMenuManager menu) { JavaPlugin.createStandardGroups(menu); IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection(); int size= selection.size(); Object element= selection.getFirstElement(); if (size == 1) addOpenNewWindowAction(menu, element); fActionGroups.setContext(new ActionContext(selection)); fActionGroups.fillContextMenu(menu); fActionGroups.setContext(null); }
private void updateSourceView(IStructuredSelection selection) { NLSSubstitution first= (NLSSubstitution) selection.getFirstElement(); if (first != null) { Region region= first.getNLSElement().getPosition(); fSourceViewer.setSelectedRange(region.getOffset(), region.getLength()); fSourceViewer.revealRange(region.getOffset(), region.getLength()); } }
@Override public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineConstantAvailable(selection)); Object first= selection.getFirstElement(); Assert.isTrue(first instanceof IField); IField field= (IField) first; run(field.getNameRange().getOffset(), field.getNameRange().getLength(), field.getCompilationUnit()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineConstantAction_dialog_title, RefactoringMessages.InlineConstantAction_unexpected_exception); } }