Eclipse plugin menu item is not visible - eclipse

I tried to add a menu item to package explorer's right click menu. But my menu item is not visible when i run my plugin. what am i missing?
here is my plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="kodsayici.counter"
label="Count"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="menuSelection">
<iterate
ifEmpty="false"
operator="or">
<adapt
type="org.eclipse.jdt.core.ICompilationUnit">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="kodsayici.Counter"
id="kodsayici.counter"
name="Count">
</command>
</extension>
</plugin>

I solved my problem. menuSelection is a wrong variable name. These variable names are predefined (Command_Core_Expressions). If change menuSelection to activeMenuSelection, my plugin works.

Related

Eclipse Plugin extension point org.eclipse.ui.command: how to change text?

EDIT: Here is the full plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="TB Category"
id="TBPlugin.commands.category">
</category>
<command
name="fubar1"
categoryId="TBPlugin.commands.category"
id="TBPlugin.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="TBPlugin.commands.sampleCommand"
class="tbplugin.handlers.SampleHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="TBPlugin.commands.sampleCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="TB"
mnemonic="M"
id="TBPlugin.menus.sampleMenu">
<command
commandId="TBPlugin.commands.sampleCommand"
mnemonic="S"
id="TBPlugin.menus.sampleCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="TBPlugin.toolbars.sampleToolbar">
<command
commandId="TBPlugin.commands.sampleCommand"
icon="icons/sample.png"
tooltip="TB"
id="TBPlugin.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
I would expect that fubar would show up someplace but I see "Sample Command" when, for example, I click on the new item in the menu bar, not "fubar". Moreover, search the code, xml files, etc. and the specific string "Sample Command" is not showing up. Where is that string defined and how do I change it?
The name value in the command is the default name of the command. It may be overridden by the menu definition.
If the org.eclipse.ui.menus extension point is used to define the menu you might have something like:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="some location URI">
<command
commandId="TBPlugin.commands.sampleCommand"
label="%command.name"
style="push">
label sets the displayed name, it is optional with the command name being the default.
If label starts with % it is the id of a property in the plugin's bundle localization properties file (usually plugin.properties or OSGI-INF/i10n/bundle.properties)

Project Explore has replicated(duplicated) popup menu entry of Package Explorer

I am new to extention creation in eclipse. I am trying to add same context menu to Project Explorer and Package Explorer.
XXX_label is menu and XXX, YYY and ZZZ are commands.
For project Explorer as described in Link, I added entry for project explorer and package Explorer.
Plugin.xml
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
id="XXX_Project"
label="XXX_label">
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:XXX_Project?after=additions">
<command
commandId="demoeeeeeeeemenu.XXX"
id="XXX"
label="XXX"
style="push">
<visibleWhen>
<with
variable="activeMenuSelection">
<iterate
ifEmpty="true"
operator="or">
//Only option to get the Project instance in core expression is adapt type!!
<adapt
type="org.eclipse.core.internal.resources.Project">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="demoeeeeeeeemenu.YYY"
label="YYY"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.ZZZ"
label="ZZZ"
style="push">
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:popup:org.eclipse.jdt.ui.PackageExplorer#PopupMenu?after=additions">
<menu
id="XXX_package"
label="XXX_label">
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:XXX_package?after=additions">
<command
commandId="demoeeeeeeeemenu.XXX"
label="XXX"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.YYY"
label="YYY"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.ZZZ"
label="ZZZ"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="demoeeeeeeeemenu.XXX"
name="XXX">
</command>
<command
id="demoeeeeeeeemenu.YYY"
name="YYY">
</command>
<command
id="demoeeeeeeeemenu.ZZZ"
name="ZZZ">
</command>
</extension>
</plugin>
How to eliminate extra entry done by package explorer?
Any of Help is Appreciated.
EDIT :
I think it is better to use locationURI="popup:org.eclipse.ui.popup.any?after=additions" as single popup entry which will add menu entry in both package explorer, Project Explorer and Navigator.
Location URI for package explorer is : popup:org.eclipse.jdt.ui.PackageExplorer.

Eclipse RCP: how to create a popup menu for the selection in a text editor?

Using the Eclipse template I generated this sample which works fine when I select a file in the project explorer. However I want to also make it available when I do right-click on a Text Editor or even when I have some text selected.
What is the right objectClass to use in the objectContribution?
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
id="com.example.popup-cli.contribution1"
objectClass="org.eclipse.core.resources.IFile">
<menu
id="com.example.popup.menu1"
label="New Submenu"
path="additions">
<separator
name="group1">
</separator>
</menu>
<action
class="com.example.popup.actions.NewAction"
enablesFor="1"
id="com.example.popup.newAction"
label="New Action"
menubarPath="com.example.popup.menu1/group1">
</action>
</objectContribution>
</extension>
Using the org.eclipse.ui.menus extension point you can use the activeEditorInput variable to test the current editor input (the file being edited).
For example:
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#AbstractTextEditorRulerContext?after=QuickDiff.Toggle">
<command
commandId="org.eclipse.team.cvs.ui.showAnnotation"
label="%ShowAnnotationAction.label"
style="push">
<visibleWhen
checkEnabled="false">
<with variable="activeEditorInput">
<test
property="org.eclipse.team.internal.ccvs.ui.isManaged"
value="true">
</test>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
The above is from the CVS plugin
I'm not sure if this is the ideal solution but it worked, it makes the popup menu visible when I press right-click on a resource in the Project Explorer and in the Editor if it's associated to a resource in the Project Explorer.
This is not perfect since it's still being displayed in non Text Editor editors/views, but I can ignore the action on those cases. If someone has some suggestion to improve this please comment.
<extension point="org.eclipse.core.expressions.definitions">
<definition id="com.example.definitions.resourceDefinition">
<adapt type="org.eclipse.core.resources.IResource"/>
</definition>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command commandId="com.example.commands.myCommand">
<visibleWhen checkEnabled="false">
<or>
<with variable="activeEditorInput">
<reference definitionId="com.example.definitions.resourceDefinition"/>
</with>
<iterate>
<reference definitionId="com.example.definitions.resourceDefinition"/>
</iterate>
</or>
</visibleWhen>
</command>
<menuContribution>
</extension>

Add line separator in context menu of Eclipse

I have a menu contribution to the Package Explorer from an Eclipse plugin.
It looks like this:
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="org.attrx.actions.Open"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt
type="org.eclipse.core.resources.IFile">
<test
property="org.eclipse.core.resources.name"
value="*.java">
</test>
</adapt>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.attrx.actions.Open"
id="org.attrx.actions.Open"
name="Open File">
</command>
</extension>
</plugin>
I would like to add a separator line in the context menu before and after this command. Could someone help me achieve this?
Use
<separator
name="separator-id"
visible="true">
</separator>
before and after the <command>.
Note: Separators are not shown if they are at the beginning or end of a menu.

Unable to export Eclipse Plugin

I have created a plugin which adds a menu to the existing menu (Using Hello, World Command)
when i run it while testing, the runtime runtime-EclipseApplication was created and i could see the Menu and Command. But when i install it from export wizard, i couldn't see the menu.
There are no logs to debug this issue.
I already have same type of plugin (Using Hello, World Command) installed. will that cause any issues
this is the plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="CheckList.commands.category">
</category>
<command
name="Create Checklist"
categoryId="CheckList.commands.category"
id="CheckList.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="CheckList.commands.sampleCommand"
class="checklist.handlers.createChecklistHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="CheckList.commands.sampleCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+8"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="Create Checklist"
mnemonic="M"
id="CheckList.menus.sampleMenu">
<command
commandId="CheckList.commands.sampleCommand"
mnemonic="C"
id="CheckList.menus.sampleCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="CheckList.toolbars.sampleToolbar">
<command
commandId="CheckList.commands.sampleCommand"
icon="icons/sample.gif"
tooltip="Create migration Checklist"
id="CheckList.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
I suspect that the new menu is in a plug-in that is in the launch configuration, but not in the product definition.
EDIT:
I expect that your current product definition is plug-in based rather than feature based:
You can now add the wanted plug-ins via the Dependencies page: