Bug 466278: Annotate command should be disabled in context menu when not applicable

Change-Id: I9bd76daeda1a300f71068866e83f3b09d6563ed1
Also-By: Markus Keller <markus_keller@ch.ibm.com>
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ClassFileEditor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ClassFileEditor.java
index 47ac163..636ce51 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ClassFileEditor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ClassFileEditor.java
@@ -575,7 +575,9 @@
 		super.editorContextMenuAboutToShow(menu);
 
 		IAction action = getAction(IJavaEditorActionDefinitionIds.ANNOTATE_CLASS_FILE);
-		menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, action);
+		if (action.isEnabled()) {
+			menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, action);
+		}
 
 		ActionContext context= new ActionContext(getSelectionProvider().getSelection());
 		fContextMenuGroup.setContext(context);
@@ -802,6 +804,7 @@
 		IClassFile file= classFileEditorInput.getClassFile();
 
 		IAction copyQualifiedName= getAction(IJavaEditorActionConstants.COPY_QUALIFIED_NAME);
+		IAction annotateAction= getAction(IJavaEditorActionDefinitionIds.ANNOTATE_CLASS_FILE);
 
 		boolean wasUsingSourceCopyAction= fSourceCopyAction == getAction(ITextEditorActionConstants.COPY);
 
@@ -853,6 +856,8 @@
 
 			}
 
+			annotateAction.setEnabled(false);
+
 		} else { // show source viewer
 
 			if (fSourceAttachmentForm != null) {
@@ -867,6 +872,11 @@
 			setAction(ITextEditorActionConstants.SELECT_ALL, fSelectAllAction);
 			copyQualifiedName.setEnabled(true);
 
+			IJavaProject javaProject= file.getJavaProject();
+			boolean useExternalAnnotations= javaProject != null
+					&& javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true).equals(JavaCore.ENABLED);
+			annotateAction.setEnabled(useExternalAnnotations);
+
 		}
 
 		IAction currentCopyAction= getAction(ITextEditorActionConstants.COPY);