Is there a possibility to send ToolbarItems bounds as paramter to an command handler? - eclipse-rcp

In my E4 Application I have a Toolbar with ToolbarItems, on click on one of them I want to display a small dialog directly under the Toolbaritem. To achieve that I need the coordinates of the button.
Is there a way to pass it via paramters to the #Execute annotated method in my handler?
I solved it via injection of MPart into my Handler and a call of getToolbar. But it looks very dirty.

You can inject the MToolItem to get the item rather than injecting the MPart.
#Execute
public void execute(MToolItem mitem)
{
ToolItem item = (ToolItem)mitem.getWidget();
...
}
But you can associate a menu with a tool item by checking the "Menu" check box in the 'Handled Tool Item' entry in the e4xmi file. You will then be able to define menu items as children of the tool item.

Related

How to create a toggle/radio item in the menu/toolbar of an Eclipse e4 application?

What is the canonical way of creating a menu item that implements a toggle or radio state in an eclipse e4 rcp application?
It seems such a basic thing, but all the documentation I found relies on e3 API and creates dependencies to org.eclipse.ui, which is not allowed in e4.
One possible way that I use for a radio button menu which saves the radio button state in the part class.
I use multiple Direct Menu Item entries with the type set to Radio.
I set a Tag value (on the supplementary page of the menu item) to the value I want to associate with the menu item.
I use the same handler for all of the menu items.
In the handler I inject the MPart and the MItem:
#Execute
public void execute(final MPart part, final MItem mitem)
{
// Only take action on the selected radio item
if (!mitem.isSelected())
return;
// The tag value specifying the radio state
String tag = mitem.getTags().get(0);
// Get the part class
MyPart myPart = (MyPart)part.getObject();
// tell the part about the state change
myPart.setState(tag);
}
Instead of the MPart you could also use any class that is in the Eclipse Context - such as one declared as #Creatable and #Singleton.

Customizing properties dialog screen in IBM Content Navigator

I need to develop a functionality in IBM Content Navigator where after search for an item, right click it-> Properties, I need to either:
1 - add a button in properties dialog screen that will call a service and open another dialog;
2 - or extend the Save button functionality to also call a service and open another dialog;
What's quickest way to achieve that ?
Have a look # ecm.widget.dialog.EditPropertiesDialog and onSave() method. This might help you to extend save button functionality.
You can add your customized code by using aspect before/after:
(choose either depending on your functionality)
aspect.after(ecm.widget.dialog.EditPropertiesDialog.prototype,"onSave", function(event){
......
});
aspect.before(ecm.widget.dialog.EditPropertiesDialog.prototype,"onSave", function(event){
......
});

How to create context menu or right click menu on button

when i right click on button open a context menu. how i will do it. i try this code also
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(btn.getText());
btn.getText().setMenu(menu);
getSite().registerContextMenu(menuManager, btn);
getSite().setSelectionProvider(btn);
I got problem in createContextMenu. Please Help me
createContextMenu requires a Control as its argument, you are passing the button text String. The setMenu method also belongs to Control. So:
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(btn);
btn.setMenu(menu);
getSite().registerContextMenu(menuManager, btn);
Button does not implement ISelectionProvider so you will have to write one if you want to use the button as the selection provider.
Note that a part can only register one context menu like this and there can only be one selection provider for a part.
If you want context menu contributions from other parts of Eclipe to be added to the menu you must add the line:
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

Change the Part selection in RCP Application when Button click in different Part

In Eclipse RCP Application UI design of my project will be as below:
PartSashContainer->PartStack->Part1, Part2,Part3.,Part4,Part5
|
->PartStack->Part6
Part6 contains the button. If button click in Part6 should set the selection to Part1.
Can you please provide how to achieve the Part selection from different Part.
Use the EPartService showPart method:
#Inject
EPartService partService;
...
partService.showPart("part id", PartState.ACTIVATE);
Use an injected EPartService where your button is, then pass the Part1's ID to the service to find the part:
final MPart part1 = partService.findPart("part1.id");
part1.setToBeRendered(true);
part1.setVisible(true);
This snippet creates it if it wasn't there. TBH I don't really know if this grants focus or not.

Update Eclipse menu item enabled state

I created the menu item in the "File" menu as a command. For this command there is a handler implementing the IHandler interface. This handler contains the isEnabled method. I am trying to use this method to enable/disable my menu item, but that method is called only once when I click on the "File" menu. When clicked for the second, third etc. times, the isEnabled method is not called again even if I changed the state of page (open/close editors) before.
What should I do? Maybe this method is not intended for control menu items?
Are you subclassing org.eclipse.core.commands.AbstractHandler? You should use setBaseEnabled(boolean) to update the state of your handler (which would update your command).
It's only valid to change enabled state in your handler as long as you also fire the HandlerEvent. It's usually easier to call setBaseEnabled(boolean) which will fire the event for you.
If you're trying to enable/disable the menu, than you should use core expressions.
I've already explained how to do that in this answer:
Eclipse RCP menus & actions: Configure or code?
The part that you're interested in starts with:
For activating/deactivating a menu[...]
I hope this is what you're looking for.