Home » Eclipse Projects » Rich Client Platform (RCP) » Menu items added by <dynamic> provider cannot be disabled(When I try to disable menu items added by a dynamic provider, instead of being "greyed" out, they are never visible. )
Menu items added by <dynamic> provider cannot be disabled [message #654265] |
Mon, 14 February 2011 14:52  |
Eclipse User |
|
|
|
I am adding menu items using the <dynamic> tag under <menu>. My dynamic class extends CompoundContributionItem and creates a dozen CommandContributionItems in the getContributionItems() function. Depending on state, some of these items created should be greyed out. I have tried multiple ways of doing this, and each way instead of becoming greyed out, they just don't show up in my menu.
Here are the ways I have tried:
1. Overriding methods on CommandContributionItem:
CommandContributionItem item = new CommandContributionItem(...) {
@Override
public boolean isEnabled() {
return customEnabled;
}
}
2. When that caused the item to not show up in the menu, I tried this as well:
CommandContributionItem item = new CommandContributionItem(...) {
@Override
public boolean isEnabled() {
return customEnabled;
}
@Override
public boolean isVisible() {
return true;
}
}
3. That still didn't work, so I tried out using a different command for the items that shouldn't be enabled. My different command's handler was simple:
public class DisabledHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
return null;
}
@Override
public void setEnabled(Object evaluationContext) {
setBaseEnabled(false);
}
@Override
public boolean isEnabled() {
return false;
}
}
That still just caused the items to not be visible. I'm all out of things to try. Any ideas?
Thanks,
Max
|
|
|
Re: Menu items added by <dynamic> provider cannot be disabled [message #654371 is a reply to message #654265] |
Tue, 15 February 2011 07:51   |
Eclipse User |
|
|
|
On 02/14/2011 02:52 PM, Max wrote:
>
> 3. That still didn't work, so I tried out using a different command for
> the items that shouldn't be enabled. My different command's handler was
> simple:
>
> public class DisabledHandler extends AbstractHandler {
>
provide a "disabled" handler how? Commands have handlers, and the
handlers are responsible for the enabled state. The active handler for
that command (and there can only be one handler active for a command at
a given time) determines the state by calling setBaseEnabled(*) so that
state change events are generated. The state applies to everywhere that
Command is used.
I created 2 commands, one with an enabled handler and one with a
disabled handler. Then I used "dynamic" to add CCIs to a submenu:
protected IContributionItem[] getContributionItems() {
CommandContributionItemParameter p1 = new CommandContributionItemParameter(
locator, "one", "z.ex.cmpd.en",
CommandContributionItem.STYLE_PUSH);
CommandContributionItemParameter p2 = new CommandContributionItemParameter(
locator, "two", "z.ex.cmpd.dis",
CommandContributionItem.STYLE_PUSH);
CommandContributionItemParameter p3 = new CommandContributionItemParameter(
locator, "three", "z.ex.cmpd.en",
CommandContributionItem.STYLE_PUSH);
CommandContributionItemParameter p4 = new CommandContributionItemParameter(
locator, "four", "z.ex.cmpd.dis",
CommandContributionItem.STYLE_PUSH);
CommandContributionItemParameter p5 = new CommandContributionItemParameter(
locator, "five", "z.ex.cmpd.en",
CommandContributionItem.STYLE_PUSH);
IContributionItem[] items = new IContributionItem[] {
new CommandContributionItem(p1),
new CommandContributionItem(p2),
new CommandContributionItem(p3),
new CommandContributionItem(p4),
new CommandContributionItem(p5), };
return items;
}
This worked fine, and the z.ex.cmpd.dis menu entries were disabled. Is
there anything in your error log? Or barring that, step through an
update(String) of one of your disabled CommandContributionItem.
PW
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
|
|
| | |
Goto Forum:
Current Time: Wed Jul 23 10:37:24 EDT 2025
Powered by FUDForum. Page generated in 0.07275 seconds
|