I'm making a plugin, and I want a popup menu to appear only if a .java file that contains a class is selected. My problem is when I select a class within a .java file (IType) the menu also appears. I want it only to appear when a .java file is selected (CompilationUnit).
Example:
.
My xml code:
<menuContribution
allPopups="true"
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
id="org.plugin.generate_test.handlers.menus.popupTestMenu2"
label="Generate"
mnemonic="P2">
<command
commandId="org.plugin.generate_test.handlers.commands.generateCommand"
id="org.plugin.generate_test.handlers.menus.generateCommand"
mnemonic="PC2"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt
type="org.eclipse.core.resources.IResource">
<test
property="org.eclipse.core.resources.extension"
value="java">
</test>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menu>
</menuContribution>
Try replacing your <adapt
with a test fo ICompilationUnit
:
<instanceof value="org.eclipse.jdt.core.ICompilationUnit"/>