Dynamic radio menu items in RCP - eclipse-rcp

I'm trying to populate a menu in an RCP application dynamically with radio menu items. The intention is that these menu items correspond to different "modes" for the application.
I'm creating the menu through a dynamic contribution:
#AboutToShow
public void aboutToShow(
final List<MMenuElement> items,
final EModelService modelService) {
// Code to get list of modes
for (Mode m : modeList) {
final MDirectMenuItem menuItem;
menuItem = modelService.createModelElement(MDirectMenuItem.class);
menuItem.setType(ItemType.RADIO);
menuItem.setLabel(m.getName());
/* Set the "handler" instance */
menuItem.setObject(new ModeMenuHandler(m));
items.add(menuItem);
}
When I click on the individual menu items, the corresponding handler is correctly being called. However, the menu items don't behave as Radio items.
How can dynamically created radio menu items be made part of a single radio-item-group?

The problem here is that each time the menu is shown the old menu items are destroyed and the #AboutToShow method is called again to recreate the menu. So any old radio selection is lost.
So you would need to save the current selection each time it changes and call setSelected(true) on the appropriate menu item when the menu is created again.
Alternatively if the number of items in the menu doesn't change (your modeList is a fixed size) you could create the menu once using a processor (the processor element of the org.eclipse.e4.workbench.model extension point).

Related

Use same keyEquivalent in NSPopupButton menu as in Main menu

I have an NSPopUpButton that has a few menu items that expose identical functionality to some main menu items. Those are actions most relevant to the users current context.
To signal that those items also have keyEquivalents (shortcuts), I wanted to set their keyEquivalents to the same keys as the items in the main menu.
Unfortunately that doesn't seem to work, since the conflicting items now have their keyEquivalents removed in the main menu (presumably automatically by AppKit).
Is it somehow possible to show the same keyEquivalent in the NSPopUpButton menu?
Normally context menus are not the most logical place to show shortcut info. However, if you really want this, then the best / probably only working option is to reuse the menu in the main menu that you want to show in your NSPopUpButton, like this:
myPopUpButton.menu = (NSApp.delegate as! AppDelegate).myMenu
In this example, myMenu is an #IBOutlet to one of the NSMenu items of the application main menu.
If you want to show a slightly different menu in your popup, then you can implement menuWillOpen of the NSMenuDelegate to dynamically hide or add menu items.

C++ Builder 6 Different Popup menu on Items and Subitems of a TreeView and No Popup on empty area

I want to have different popup menu on Items and SubItems and NO Popup menu on empty area of a TTreeView is that possible ?
I want something like the pictures bellow
There are two ways you can do that.
Create 2 separate TPopupMenu objects with the desired menu items, do not assign either one of them to the TreeView's PopupMenu property, and then use the TreeView's OnContextMenu event to call the Popup() method of whichever TPopupMenu you need based on which node the user is clicking on.
Create 1 TPopupMenu object and put both menu items in it, and assign it to the TreeView's PopupMenu property, then use the TPopupMenu.OnPopup event to show/hide the menu items based on which node the user is clicking on.
In either case, you can use the TTreeView.GetNodeAt() method to determine which node is located at the coordinates of a mouse click, if any.

How can i hide toolbar menu item or whole toolbar depending on perspective in eclipse rcp?

I want to hide the toolbar item or whole toolbar when I m in specific perspective .
Till now I have tried to define a perspective extension and inside it i defined all the menubar and toolbar item needed to be hidden and linked them with the respective id.But contrary to my expectation when i opened the application all the menu item are gone as expected but toolbar item are still visible.Is there anything which I am doing wrong here.
2nd approach :
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
window.setCoolBarVisible(b.getSelection());
// window.toggleToolbarVisibility();
But here as window is an internal class so I donot want to use this approach.
Any light on my first approach is appreciated ..

modal dialog in gwt with clicklistener

I've a huge panel with drop-down lists and checkboxes. To manage them I have to implement the ClickListener interface so that on expanding the drop-down list or clicking on the checkbox some actions are executed.
Then I have to show the dialog box with just one 'OK' button and this dialog should be modal. I create it using via the following constructor
final DialogBox msg = new DialogBox(false, true);
so it should be modal and it is except for drop-down lists and checkboxes because clicking on them calls to the onClick(Widget sender) method which knows nothing about the modality of the dialog box so it could expand the drop-down list or tick the checkbox.
I see that this could be resolved by just one if in that onClick() method where it should check if there is no modal window or there is one. But is there another option to resolve this issue?
Are you looking for setGlassEnabled(boolean)?

Programatically change icon for a eclipse RCP command

I have a menu drop down action in the coolbar. It has 3 sub items that form a radio group. I would like to change the icon shown in the coolbar when the user selects one of these options.
I've googled and seen that I should look at:
org.eclipse.ui.commands.ICommandService.refreshElements(String, Map)
and
org.eclipse.ui.commands.IElementUpdater
Its probably the right thing to look at exception its not enough information. One or two small code snippets will be excellent.
Thanks in advance.
Ok basically if you don't want to use a "custom" control the what to do it is to have your handler (handler that is linked to the specific command) implement IElementUpdater. When every the toolbar item gets shown or clicked on (i.e if the user selects on the the radio buttons) the method: updateElement(UIElement element, Map parameters) gets called.
The element has a setIcon() method and this is what i used to change the icon of the menu drop down action.
Every update to the Coolbar points to the specialization of the WorkbenchWindowControlContribution class.
This bug 186800 has some code example in it which can be of interest.