Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Command Parameter and dynamic menu
Command Parameter and dynamic menu [message #485044] Thu, 10 September 2009 11:11 Go to next message
Eclipse UserFriend
Originally posted by: till.tillamma.de

Hello,

I'm trying to combine the nice turorials from Prakash about the command
framework (http://wiki.eclipse.org/Platform_Command_Framework) and those
about menu contributions (http://wiki.eclipse.org/Menu_Contributions).

What I try to accomplish is a dynamic submenu populated with a
parameterized command. (a couple of items with the same command)

So, I defined the command with a parameter in the manifest. Also I
defined the menu with a dynamic field which uses a CompoundContributionItem.

During the call from CompoundContributionItem#getContributionItems() I
create CommandContributionItem s using CommandContributionItemParameter.

It actually works fine when there are no parameters given - the menu is
populated with the Command and the label set in
CommandContributionItemParameter.
But once I set a parameter the whole submenu is set inactive (grayed out).

Maybe I don't see the obvious solution but up to now i couldn't find one.
Creating a breakpoint during those calls causes eclipse, java and parts
of the operating system to hang. (I assume because it stops during a
system call, right?)

Using ISelectionService instead of a CommandParameter won't work for me
because the information I need is not in a selection - if I understood
the concepts right.

#######
#######

Code:
Some parts are shortened.

####
# plugin.xml (most interesting parts)
####
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="my.commandhandler"
description="%command.description"
id="my.commandid"
name="%command.name">
<commandParameter
id="my.parameterid"
name="ID"
optional="true">
</commandParameter>
</command>
</extension>

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:my.menu">

<menu
label="Add from Repository">
<dynamic
class="my.MyContributionItem"
id="my.dynamicMenu">
</dynamic>
</menu>
</menuContribution>
</extension>

####
# my CompoundContributionItem#getContributionItems()
####

@Override
protected IContributionItem[] getContributionItems()
{
URepository repo =
URepositoryUtils.getRepository(Activator.getDefault().getUVi ew().getEditingDomain());
EList<U> us = repo.getUs();

Map<String, String> params;
LinkedList<IContributionItem> list = new LinkedList<IContributionItem>();
for(U u : us)
{
params = new HashMap<String, String>();
params.put("ID", Long.toString(u.getId()));

CommandContributionItemParameter para = new
CommandContributionItemParameter(PlatformUI.getWorkbench().g etActiveWorkbenchWindow(),
"my.parameterid",
"my.commandid",
params,
null, // icon
null, // disabled icon
null, // hover icon
u.getName(), // label
null, // mnemonic
u.getName(), // tooltip
CommandContributionItem.STYLE_PUSH,
null, // help context id
true // visibleEnable
);
list.add(new CommandContributionItem(para));
}

return (IContributionItem[]) list.toArray(new
IContributionItem[list.size()]);
}
Re: Command Parameter and dynamic menu [message #485086 is a reply to message #485044] Thu, 10 September 2009 14:00 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

it's probably:
params.put("ID", Long.toString(u.getId()));

You want the id of the commandParameter (and ID is technically its name)

PW


Re: Command Parameter and dynamic menu [message #485165 is a reply to message #485086] Thu, 10 September 2009 16:46 Go to previous message
Eclipse UserFriend
Originally posted by: till.tillamma.de

Paul Webster wrote:
> it's probably:
> params.put("ID", Long.toString(u.getId()));
>
> You want the id of the commandParameter (and ID is technically its name)
>
> PW
>

Hi Paul,

thanks a lot! It seems to work (doing a quick evaluation).
Now that I see it, it totally makes sense - silly me!

Anyways, the tooltip for the CommandContributionItemParameter
constructor only talks about parameter "names and values".

Also, the tutorial about commands by Prakash and the ones about menu
contribution seem to use the "name" as the first argument in the map.
It's either misleading/wrong or a diffrent usecase. But actually i don't
see the difference.

Thanks, again.

Till
Previous Topic:implementing global action in ApplicationWorkbench
Next Topic:User MY View of variables
Goto Forum:
  


Current Time: Fri Apr 26 13:40:49 GMT 2024

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

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

Back to the top