if (firstElement instanceof IAdaptable) return (IJavaElement)((IAdaptable)firstElement).getAdapter(IJavaElement.class); else
if (firstElement instanceof ISearchResultViewEntry) { IJavaElement je= SearchUtil.getJavaElement((ISearchResultViewEntry)firstElement); if (je != null) return je; firstElement= ((ISearchResultViewEntry)firstElement).getResource(); } if (firstElement instanceof IAdaptable) { IJavaElement je= (IJavaElement)((IAdaptable)firstElement).getAdapter(IJavaElement.class); if (je == null && firstElement instanceof IFile) { IContainer parent= ((IFile)firstElement).getParent(); if (parent != null) return (IJavaElement)parent.getAdapter(IJavaElement.class); else return null; } else return je;  } else
	protected Object getSingleElementFromSelection(ISelection selection) {		if (!(selection instanceof StructuredSelection) || selection.isEmpty())			return null;				Iterator iter= ((StructuredSelection)selection).iterator();		Object firstElement= iter.next();		if (!(firstElement instanceof IJavaElement)) {			if (firstElement instanceof IAdaptable)				return (IJavaElement)((IAdaptable)firstElement).getAdapter(IJavaElement.class);			else				return firstElement;		}		Object currentInput= (IJavaElement)getViewer().getInput();		if (currentInput == null || !currentInput.equals(findInputForJavaElement((IJavaElement)firstElement)))			if (iter.hasNext())				// multi selection and view is empty				return null;			else				// ok: single selection and view is empty 				return firstElement;		// be nice to multi selection		while (iter.hasNext()) {			Object element= iter.next();			if (!(element instanceof IJavaElement))				return null;			if (!currentInput.equals(findInputForJavaElement((IJavaElement)element)))				return null;		}		return firstElement;	}