Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Filter commands by parameter
Filter commands by parameter [message #483982] Thu, 03 September 2009 20:06 Go to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

I have a parametrized command in my application.
I also have two menu entries registered against the command; the style of
the menu entries is 'toggle' for both of them. The parameter of the
command associated with each menu entry is distinct.

I have successfully managed to update the toggle state of the command.
When any of the menu entries is selected then both menu entries are
checked/unchecked and the command handler is executed correctly (it
changes the current perspective). And this is consistent with
http://wiki.eclipse.org/Menu_Contributions/Update_checked_st ate: 'the
command service calls public void updateElement(UIElement element, Map
parameters) for every UIElement registered against the command'.

Since the Javadoc of the updateElement method states that the 'element'
should not be tracked down I needed to find a way have the toggle state
change only for the menu entry selected (and not for both of the menu
entries).

I tried to create a filter for the 'refreshElements' method of the
'ICommandService' but I cannot get the desired effect: both of the menu
entries toggle their state.
In the Javadoc of the above method it states that: 'If the command is
parameterized, some of the parameters can be specified to help narrow down
which elements to refresh.'
So I tried to create the filter like this: filter.put(parameter_name,
parameter_value); but it doesn't seem to work as expected.

Am I missing something about this filtering based on the command parameter?
Has someone managed to get this working? Any idea is appreciated.
If you need more details about this just let me know.


Time is what you make of it.
Re: Filter commands by parameter [message #484085 is a reply to message #483982] Fri, 04 September 2009 09:06 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

My command looks looks like this:

<command

defaultHandler="com.gcsf.books.handlers.TestOpenPerspectiveHandler "
id="com.gcsf.books.test.open.perspective.command"
name="TestOpenPerspective">
<commandParameter

id="org.eclipse.ui.perspectives.showPerspective.perspectiveId "
name="perspectiveId"
optional="false">
</commandParameter>
<state
class="org.eclipse.jface.commands.ToggleState"
id="org.eclipse.ui.commands.toggleState">
</state>
</command>

And the menu entries are:

<menu
label="TestMenu">
<command
commandId="com.gcsf.books.test.open.perspective.command"
label="TestOpenPerspective1"
style="toggle">
<parameter

name="org.eclipse.ui.perspectives.showPerspective.perspectiveId "
value="com.gcsf.books.perspective.horizontalsplit">
</parameter>
</command>
<command
commandId="com.gcsf.books.test.open.perspective.command"
label="TestOpenPerspective2"
style="toggle">
<parameter

name="org.eclipse.ui.perspectives.showPerspective.perspectiveId "
value="com.gcsf.books.perspective.verticalsplit">
</parameter>
</command>
</menu>

And finally my handler code contains:
/.../
Map filter = new HashMap();

filter.put("org.eclipse.ui.perspectives.showPerspective.perspectiveId ",
parameterId);
commandService.refreshElements(event.getCommand().getId(), filter);
/.../ (where parameterId =
event.getParameters().get("org.eclipse.ui.perspectives.showPerspective.perspectiveId "))

But what I get is that both 'TestOpenPerspective1' and
'TestOpenPerspective2' menu entries are checked/unchecked when one of them
is selected. Which is not the desired effect: only one of the menu entries
should be selected and not both of them.

Is this a bug? Or I miss something about updating the checked state for a
command and there is another solution for what I am trying to achieve?


Time is what you make of it.
Re: Filter commands by parameter [message #484678 is a reply to message #484085] Tue, 08 September 2009 17:47 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you are using ToggleState on the command, it is a single toggle command. You won't be able to parameterize it.

If you set a breakpoint in your updateElement(*) method, is it called with an element with the correct org.eclipse.ui.perspectives.showPerspective.perspectiveId?

PW


Re: Filter commands by parameter [message #486494 is a reply to message #484678] Thu, 17 September 2009 20:26 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

Hello Paul

1. The updateElement(*) method is called with the element with the correct
org.eclipse.ui.perspectives.showPerspective.perspectiveId.

2. I understand that I won't be able to parametrize a single toggle
command.

But what is the purpose of the filter in the ICommandService used in the
refreshElements(*) method? In the javadoc of the method there is only one
example and I was under the impression that I can use this filter to get
only the command with the desired parameter as the javadoc implies: If the
command is parameterized, some of the parameters can be specified to help
narrow down which elements to refresh.

Or am I misunderstanding something?

3. The desired effect for me (only one item modified in the menu) I
obtained using radio button commands as described here:
http://wiki.eclipse.org/Menu_Contributions/Radio_Button_Comm and.


Time is what you make of it.
Re: Filter commands by parameter [message #487049 is a reply to message #486494] Mon, 21 September 2009 16:34 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

re: refreshElements ... it appears that it can be used to filter based on parameter.

see org.eclipse.ui.internal.commands.CommandService.refreshEleme nts(String, Map)

It should be asking for a parameter for each entry in the filter, and then comparing that parameter to the filter value. If there's no match, it should return false and not issue an updateElement call.

PW


Previous Topic:How to disable ActionSets contributed by other plugins ?
Next Topic:Dynamically loading external files
Goto Forum:
  


Current Time: Thu Nov 20 21:14:10 GMT 2014

Powered by FUDForum. Page generated in 0.03382 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software