Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Overriding a command name in another plugin
Overriding a command name in another plugin [message #499667] Mon, 23 November 2009 11:29 Go to next message
Raajesh  B.Kashyap is currently offline Raajesh B.Kashyap
Messages: 7
Registered: July 2009
Junior Member
We are trying to debug a problem which involves overriding the name of a command in another plugin, in our RCP application. I want to understand the correct mechanism to override the name of the command when a new plugin is loaded.

Basically, we have a common plugin which defines a command, and its name is internationalized in the plugin.properties file in the same common plugin, something like this:

In the common plugin's plugin.xml:

<extension point="org.eclipse.ui.commands">
<command
id="com.x.y.z.abc"
name="%abc.TITLE">
</command>
</extension>

In the common plugin's plugin.properties:

abc.TITLE = Perform Operation

This command is then normally displayed in the menu system as "Perform Operation".

We have another plugin, which is optionally loaded by customers during the installation process. When this plugin is loaded, the need is to change the displayed name to something else (while the internal functionality executed is the same). So, what has been done is to re-define the command again in the optional plugin, something like this:

In the optional plugin's plugin.xml:

<extension point="org.eclipse.ui.commands">
<command
id="com.x.y.z.abc"
name="%abc.TITLE">
</command>
</extension>

In the optional plugin's plugin.properties:

abc.TITLE = Perform Transaction

However, this mechanism does not seem to work consistently. During development, when using Eclipse, the application shows "Perform Transaction" when the optional plugin is loaded, but in the installed environment, it still shows "Perform Operation". Even in the development environment, it does exhibit the behavior sometimes.

My question is if this is the correct way to override the command name in the optional plugin, and if not, what should be done?

Re: Overriding a command name in another plugin [message #499692 is a reply to message #499667] Mon, 23 November 2009 13:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The mechanism you want is not supported. A command is only allowed to be defined once.

1) if you provide a definition for the same command in different plugins, the framework will non-deterministically serve up one. You've already seen that.

2) A mechanism that is supported is handler based. i.e. the active handler (if it is an IElementUpdater) has the ability to change the text on menu elements.

PW


Re: Overriding a command name in another plugin [message #499733 is a reply to message #499692] Mon, 23 November 2009 16:23 Go to previous messageGo to next message
Raajesh  B.Kashyap is currently offline Raajesh B.Kashyap
Messages: 7
Registered: July 2009
Junior Member
Thanks Paul. I suspected this may be the case. However, you mention that the active handler can update the text. This does not seem to work on menu options that are inside sub-menus. We have one of those menu options (for which we want to override the display name) inside a sub-menu, but the handler update mechanism does not get invoked for them. It does get invoked if the menu option is in the first level, though.

Is there anything that I am missing?
Re: Overriding a command name in another plugin [message #499903 is a reply to message #499733] Tue, 24 November 2009 08:56 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The MenuItem itself usually isn't instantiated until the submenu is about to show. But I wouldn't think that would matter (unless you have menus with removeAllWhenShown set).

When the CommandContributionItem is added the active handler is given a chance to update its label. When a new handler becomes active, it is also given the change to update all registered CommandContributionItems.

If the text needs to be updated at some other event, then org.eclipse.ui.commands.ICommandService.refreshElements(Stri ng, Map) needs to be called.

PW


Previous Topic:Cant create a product
Next Topic:Best Update Strategy
Goto Forum:
  


Current Time: Sat Jul 26 03:14:40 EDT 2014

Powered by FUDForum. Page generated in 0.02514 seconds