[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.rcp] Command Parameter and dynamic menu
|
- From: Till Amma <till@xxxxxxxxxxx>
- Date: Thu, 10 Sep 2009 13:11:35 +0200
- Newsgroups: eclipse.platform.rcp
- Organization: EclipseCorner
- User-agent: Thunderbird 2.0.0.23 (X11/20090817)
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().getUView().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().getActiveWorkbenchWindow(),
"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()]);
}