diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java index 76559d3..4826032 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java @@ -411,11 +411,37 @@ fLinking= enabled; if (fLinking && fLastSelectionProvider != null) { - computeAndSetInput(fLastSelectionProvider); + //compute the current selection + ISelection selection= fLastSelectionProvider.getSite().getSelectionProvider().getSelection(); + if (!selection.isEmpty()) { + IJavaElement je= findSelectedJavaElement(null, selection); + if (selection instanceof IStructuredSelection && !isValidJavadocViewInput(je)) { + //while re-enabling if the selection is invalid then clear the view + doSetInput(null); + fCurrentViewInput= null; + } else { + computeAndSetInput(fLastSelectionProvider); + } + + } else { + //while re-enabling if the selection is empty use the previously computed input to set the view content + setInput(fCurrentViewInput); + } } } /** + * Finds whether the given Java element is a valid input for the Javadoc view. + * + * @param je the Java element whose validity has to be checked + * @return true if the Java element can be a valid input to the Javadoc view, + * false otherwise + * @since 3.9 + */ + protected boolean isValidJavadocViewInput(IJavaElement je) { + return !(je == null || (je.getElementType() == IJavaElement.JAVA_MODEL || je.getElementType() == IJavaElement.JAVA_PROJECT || je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT)); + } + /** * Returns whether this info view reacts to selection * changes in the workbench. * diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java index 7a11720..11439de 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java @@ -321,9 +321,40 @@ @Override public void run() { setLinkingEnabled(!isLinkingEnabled()); + JavaPluginImages.setLocalImageDescriptors(fToggleLinkAction, "synced.gif"); //$NON-NLS-1$ } } + @Override + public void selectionChanged(final IWorkbenchPart part, final ISelection selection) { + if (part.equals(this)) { + return; + } + super.selectionChanged(part, selection); + + if (isLinkingEnabled()) { + String iconName= "synced.gif"; //$NON-NLS-1$ + //find the current structured selection + if (!selection.isEmpty()) { + IJavaElement je= findSelectedJavaElement(part, selection); + //if there is an existing valid view input and the current selection is invalid, then update the icon + if (getInput() != null + && selection instanceof IStructuredSelection + && !isValidJavadocViewInput(je)) { + //Testcase : Select a valid Java file in the Package explorer view and then select a Java project + if (isValidJavadocViewInput(fCurrentViewInput) && fCurrentViewInput.exists()) { + iconName= "sync_broken.gif"; //$NON-NLS-1$ + } + } + } + //if the selection is empty and the view input element does not exist. Testcase :Select a Java file in Package explorer view and then delete it. + else if (fCurrentViewInput != null && !fCurrentViewInput.exists()) { + iconName= "sync_broken.gif"; //$NON-NLS-1$ + } + JavaPluginImages.setLocalImageDescriptors(fToggleLinkAction, iconName); + } + } + /** * Action to open the selection in an external browser. If the selection is a java element its * corresponding javadoc is shown if possible. If it is an URL the URL's content is shown.