|
Re: dynamically changing menu and toolbar icons [message #510935 is a reply to message #510898] |
Fri, 29 January 2010 08:50 |
Daniel Krügler Messages: 853 Registered: July 2009 |
Senior Member |
|
|
On 29.01.2010 05:00, Alex Ignácio da Silva wrote:
> Hi all,
>
> I have a command contributed through the command framework extension
> points to both a menu item and a toolbar item. In order to dynamically
> change the image associated with the menu and toolbar items, I let the
> command handler implement the org.eclipse.ui.commands.IElementUpdater
> interface:
>
> public class MyHandler extends AbstractHandler implements IElementUpdater {
>
> ...
>
> @Override
> public void updateElement(UIElement element, Map parameters) {
> element.setIcon(...);
> }
>
>
> }
>
> In my application I use 16x16 icons for menu items, and 24x24 icons for
> toolbar icons, so I need to set a different image for each UIElement.
> The problem is that the UIElement interface has no API to extract
> information from the element being configured, so I have no way to tell
> whether it's a menu or a toolbar item.
>
> Can anyone suggest a way to work around this limitation?
You should be able to do that quite cleanly as follows: First
add to your org.eclipse.ui.commands extension a command
parameter:
<extension
point="org.eclipse.ui.commands">
<command
id="/your-command-id/" name="bla-bla">
<commandParameter id="/your-parameter-id/"
name="%blub"
optional="true">
</commandParameter>
</command>
</extension>
Now ensure that your org.eclipse.ui.menus menu contribution with
different representations set a different parameter *value*,
in the following contribution definition this value is
"/param-value-1/":
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="/whatever/">
<command
commandId="/your-command-id/"
label="bla-bla"
style="push">
<parameter name="/your-parameter-id/"
value="/param-value-1/">
</parameter>
</command>
</menuContribution>
</extension>
Finally, in your updateElement method, you use the "Map parameters"
argument to check the current command parameter value by accessing
parameters.get("/your-parameter-id/") and comparing the result
against your different values, i.e against "/param-value-1/"
etc.
Remark: I believe this should work. A similar variant of this
idea is that you can define different execution behavior
of your Object execute(ExecutionEvent event) implementation
by checking the corresponding parameter value via
event.getParameter("/your-parameter-id/") to decide for
the parameter-specific "execution policy".
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
|
Powered by
FUDForum. Page generated in 0.03119 seconds