How to override keybindings from a parent scheme in Eclipse 4? - eclipse

I am upgrading an RCP application to use Eclipse 4.2.1. One of the problems I am having is that keybindings in my custom scheme are no longer overriding Eclipse key bindings.
I have reproduced the problem in a sample plug-in project. This was created by following, then adapting, this tutorial. I can't attach the project itself, so have just included the contents of the plugin.xml file.
I have my own scheme which extends the default scheme:
<scheme
id="test.MyScheme"
name="My Scheme"
parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
</scheme>
I have a command with the key binding Ctrl+N:
<key
commandId="test.MyCommand"
contextId="org.eclipse.ui.contexts.window"
schemeId="test.MyScheme"
sequence="M1+N">
</key>
In Eclipse 3.7.2, pressing Ctrl+N would run my command.
In Eclipse 4.2.1, it pops up a box asking me to choose between running my command and launching the 'New' wizard. What do I need to do to restore the original behaviour?
Full contents of plugin.xml below.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="application"
point="org.eclipse.core.runtime.applications">
<application>
<run
class="test.Application">
</run>
</application>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
name="RCP Perspective"
class="test.Perspective"
id="test.perspective">
</perspective>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="test.MyCommandHandler"
id="test.MyCommand"
name="My Command">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="fileMenu"
label="File">
<command
commandId="test.MyCommand"
label="My Command"
style="push">
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="test.MyCommand"
contextId="org.eclipse.ui.contexts.window"
schemeId="test.MyScheme"
sequence="M1+N">
</key>
<scheme
id="test.MyScheme"
name="My Scheme"
parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
</scheme>
</extension>
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
application="test.application"
name="My Product">
<property
name="appName"
value="My Product">
</property>
<property
name="preferenceCustomization"
value="plugin_customization.ini">
</property>
</product>
</extension>
</plugin>

The old mechanism appears to just not work but there is another way.
Add an extension org.eclipse.e4.workbench.model
Add a processor fragment
Find the offending key binding: MAppliction->MBindingTable->MKeyBinding
Remove the key binding from the binding table

The following file might be missing inside your plugin directory next to the plugin.xml:
plugin_customization.ini
Its content should be:
org.eclipse.ui/KEY_CONFIGURATION_ID=test.MyScheme
See also, this tutorial and the chapter here.

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)

Toolbar item not clickable in Eclipse RCP - Windows

I am new to Eclipse Rich Client Platform. I am learning to create Views by adding toolbar, menu, etc. As a part of an exercise, I added a toolbar to my view and also declared a handler for its command. But when I run my application the toolbar appears in disabled mode and I am not able to click it.
This is my plugin.xml
<extension
point="org.eclipse.ui.commands">
<category
id="ch02.WebBrowser.commands.category"
name="Web Category">
</category>
<command
categoryId="ch02.WebBrowser.commands.category"
id="ch02.WebBrowser.commands.newBrowser"
name="New Browser">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="ch02.WebBrowser.toolbar.sampletoolbar">
<command
commandId="ch02.WebBrowser.commands.newBrowser"
icon="icons/16-earth.png"
id="ch02.WebBrowser.toolbars.newBrowserCommand"
style="push"
tooltip="Open New Browser">
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="ch02.webbrowser.handlers.NewBrowserHandler"
commandId="ch02.WebBrowser.commands.newBrowser">
</handler>
</extension>
Output
Please check your handler isEnable() and isHandled() status.

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:

Trying to put new "Generate" option under Source menu in Eclipse

I'm trying to add a new "Generate..." option under the Source menu when you right-click on a Java file. At this point, I'm just trying to get the menu option to show up but I haven't had success yet.
Is there something wrong with my plugin.xml file below as far as you can see?
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
id="GenerateBuilderPlugin.contribution1"
objectClass="org.eclipse.core.resources.IFile">
<action
class="generatebuilderplugin.popup.actions.GenerateBuilder"
enablesFor="1"
id="GenerateBuilderPlugin.newAction"
label="Generate Builder..."
menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup">
</action>
</objectContribution>
</extension>
</plugin>
I ended up going with the "Hello, World Command" template and adjusting for my needs.
Below is the updated plugin.xml that successfully displays the a new "Generate..." option on the Source menu. One just basically needs to setup a command and a handler class that does the actual work. I'd recommend just following the "Hello, World Command" plugin template and tweaking for your needs.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.commands">
<command
name="Generate Builder..."
id="GenerateBuilderProject.commands.GenerateBuilder">
</command>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
commandId="GenerateBuilderProject.commands.GenerateBuilder"
class="generatebuilderproject.handlers.GenerateBuilderHandler">
</handler>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.jdt.ui.source.menu?after=generateGroup">
<command
commandId="GenerateBuilderProject.commands.GenerateBuilder"
id="GenerateBuilder.menus.GenerateBuilder">
</command>
</menuContribution>
</extension>
</plugin>

Eclipse plugin menu item is not visible

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.