[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: Radio Context Menu in View

Guillaume Boivin wrote:
Hi,

I want to achieve the same goal. I want to add a new group in the any popup menu (popup menu activated on a package explorer/project explorer resource). In that group, one command is to choose a compilation target, basically you choose an element from a sub menu. From an existing Eclipse Plug In, the CDT popup menu Build Configurations -> Set Active -> 1 Target Choice #1
-> 2 Target Choice #2
-> N Target Choice #N
is exactly what I would like to reproduce.


I'm using the org.eclipse.ui.menus extension. Here's my plugin.xml for this extension:

<extension
point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=group.properties">
<menu
id="aMenuId"
label="aLabel">
<command
commandId="aCommandId">
</command>
<dynamic
class="aDynamicSubMenuClass"
id="anId">
</dynamic>
<visibleWhen>
<iterate>
<adapt
type="org.eclipse.core.resources.IResource">
<test
property="org.eclipse.core.resources.projectNature"
value="aCustomNature">
</test>
</adapt>
</iterate>
</visibleWhen>
</menu>
</menuContribution>
</extension>


The questions I have are:

How can I had my menu so it appears at the very end of the any popup menu? My locationURI is: locationURI="popup:org.eclipse.ui.popup.any?after=group.properties".
For the moment, my menu shows just before the properties menu but I want to show it as the last element of the any popup menu. I tried with ?after=additions or ?after=group.additions but it didn't worked.

The menu contributions are applied after any programmatic actions (Properties is added by the Package Explorer) but before any action contributions (like popupMenus). If the Properties action had an ID you could place yourself after it, but I wasn't able to find an ID for that action. There are enhancements to the locationURI to include some other options (append maybe, or after/before) but they won't be available until 3.4.



How can I had a dynamic sub menu?
For the moment my class under the dynamic element (aDynamicSubMenuClass extending CompoundContributionItem) works well. I extended the IContributionItem[] getContributionItems() method and I'm able to generate the sub menu under the "aLabel" menu. Here's a simplified version of the getContributionItems() method:


  IContributionItem[] array = new IContributionItem[aCertainLength];
    for (int i=0; i<aCertainLength; i++)
  {
     array[i] = new CommandContributionItem(
         PlatformUI.getWorkbench(),
           aName,
           "org.eclipse.ui.help.aboutAction",
           null,
           null,
           null,
           null,
           aName,
           null,
           null,
           CommandContributionItem.STYLE_RADIO
     );
  }
  return array

What's not working properly is that the subMenu items aren't shown as radio button but simply as push button.

I copied your example and the menu items are shown as radio buttons ... just none of them are selected.


Also, I don't know what commandId to insert in my subMenu item (CommandContributionItem) as no command is intended to be called when a CommandContributionItem is selected. I temporarly put the existing org.eclipse.ui.help.aboutAction just to be able to show my subMenu.

When you select a menu item, you have to do something ... even if it is just update your model with the currently selected target.


Use the commandId that will execute that action. One "way" of providing the effect you want is to have the command take an optional parameter. Selecting the menu item executes the command with the "target" parameter. In your handler, you would then update whatever model you have to the correct "target" and then you can "refresh" your command UI elements (your handler implements IElementUpdater). You can then update each UI element as to whether or not it is checked.

Later,
PW