Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How can I get the IContributionManager for a MPart?
How can I get the IContributionManager for a MPart? [message #765204] Tue, 13 December 2011 11:06 Go to next message
Josh Davis is currently offline Josh Davis
Messages: 20
Registered: August 2011
Junior Member
Now that we have converted from e3 to e4, we are trying to refactor the logic that uses the compatibility layer.

I have ran into this issue.
In e3 our views would get the toolbar IContributionManager using getViewSite().getActionBars().getToolBarManager().

Now that we are on e4 we have removed this code (we no longer extend ViewPart) and instead get the toolbar using this logic
part.getToolbar()
Where part is a MPart

Is there a way to a IContributionManager for a MPart?

I have looked around and the best I could find is if
part.getToolbar() returns a MRenderedToolBar. The MRenderedToolBar has a getContributionManager() method but it returns an object, not necessarily a IContributionManager. I haven't stepped through the code yet to see where this object get set or what the possible types are. I am going to look into it now, but I wanted to get this out there in case I am overlooking an easier solution.

Is there a class or method that I am overlooking that will give me a IContributionManager?
Re: How can I get the IContributionManager for a MPart? [message #765220 is a reply to message #765204] Tue, 13 December 2011 11:48 Go to previous messageGo to next message
Josh Davis is currently offline Josh Davis
Messages: 20
Registered: August 2011
Junior Member
Nevermind. Another member of my team came up with a solution by using MenuFactoryImpl.eINSTANCE.createRenderedToolBar(). She then set the contribution manager on this new object to a new ToolbarManager(). This way when I get the toolbar from the MPart I will know that it will be a MRenderedToolbar that contains a ToolbarManager, which is a IContributionManager.
Re: How can I get the IContributionManager for a MPart? [message #765689 is a reply to message #765220] Wed, 14 December 2011 09:33 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That's an implementation detail, and not a good idea. In Eclipse 4, you need to provide commands, activate handlers in your view POJO using EHandlerService, and if you need to update the toolbar then add MHandledToolItems to the view's MToolBar.

Doing anything else will probably not work by the end of 4.2

PW


Re: How can I get the IContributionManager for a MPart? [message #769894 is a reply to message #765689] Thu, 22 December 2011 16:29 Go to previous messageGo to next message
Josh Davis is currently offline Josh Davis
Messages: 20
Registered: August 2011
Junior Member
What is a MHandledToolItem? I am using a MDirectToolItem, why can't this be used?

Looks like MDirectToolItem extends MContribution, and MHandledToolItem extends MHandledItem. That appears to be a difference. I looked at those APIs and am still at a lost as to when I should use which one.

All of our toolbar buttons are added through the code. We don't use the plugin.xml or Application.e4xmi to add things.

Here is what I am trying to accomplish
1) Get a jface IContributionManager from the mToolbar and mMenu to pass to my consumers if they need it. We are doing this to not force them to change all of their code at once.
2) Allow my consumers to add items to the toolbar and menu using my APIs. We use our own APIs and model objects to allow for us to change eclipse versions. The implementation of the APIs call the eclipse code to add toolbar item, menu items, etc.

Is there source or a tutorial I am missing that shows how to do things in the code instead of using the application.e4xmi? All I have found is tutorials that show you how to set things up using the application.e4xmi




Re: How can I get the IContributionManager for a MPart? [message #770184 is a reply to message #769894] Fri, 23 December 2011 10:11 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de Alwis
Messages: 242
Registered: July 2009
Senior Member
Handled items take a command which is used at execution time to find a matching handler.

Direct items either specify a class (the contruibutionURI) or an object instance whose @CanExecute/@Execute methods are called on execution.

So you should be able to wrap your objects and provide them as direct items.

Brun.
Re: How can I get the IContributionManager for a MPart? [message #774740 is a reply to message #770184] Wed, 04 January 2012 09:03 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Josh, it depends on what you want to do. If you are providing an IViewPart and are using the IActionBars, those will continue to work in 4.2. But using actions is the "old way", and it's supported by compatibility. MRendered* things will be going away, as they bypass the renderers (passing though a contribution manager).

Eclipse 4 is command/handler based, MHandledToolItem pointing to a command (and the handler is looked up at runtime). In Eclipse 4 you would add your MHandledToolItems to the model and make them visible/invisible as needed, and (in theory Smile the renderers would dynamically show them.

MDirectToolItem is kind of a nod to the simplest usecase. You are writing an Eclipse 4 view and you want to react to an SWT.Selection event ... it ties the object mentioned to Brian directly to calling the @CanExecute/@Execute methods with no access to the general command/keybinding framework, and only access to whatever's in the application context.

PW




Re: How can I get the IContributionManager for a MPart? [message #775352 is a reply to message #770184] Thu, 05 January 2012 15:30 Go to previous messageGo to next message
Josh Davis is currently offline Josh Davis
Messages: 20
Registered: August 2011
Junior Member

Quote:
Direct items either specify a class (the contruibutionURI) or an object instance whose @CanExecute/@Execute methods are called on execution.


How does this work? I created a MDirectToolItem and set the Object on it to be an instance of a class that uses the @CanExecute and @Execute on two different methods. When I run the code and press the buttons it gives me this exception


org.eclipse.e4.core.di.InjectionException: Unable to find matching method to invoke
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:200)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:86)
at org.eclipse.e4.ui.workbench.renderers.swt.DirectContributionItem.executeItem(DirectContributionItem.java:409)
at org.eclipse.e4.ui.workbench.renderers.swt.DirectContributionItem.handleWidgetSelection(DirectContributionItem.java:334)
at org.eclipse.e4.ui.workbench.renderers.swt.DirectContributionItem.access$1(DirectContributionItem.java:318)
at org.eclipse.e4.ui.workbench.renderers.swt.DirectContributionItem$2.handleEvent(DirectContributionItem.java:283)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:969)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:885)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:539)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:519)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.cerner.genesis.app.client.RCPApplicationEventHandler.runEventQueue(RCPApplicationEventHandler.java:286)
at com.cerner.genesis.app.core.Application$3.run(Application.java:287)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:337)
at com.cerner.genesis.app.core.Application.start(Application.java:282)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

I think this means that it can't find a method that has @CanExecute and @Execute

On a different note (still around MDirectToolItems)
I have also noticed that if I add items to the toolbar during the part creation they show up
If I add items to the toolbar after the part creation, the first new item shows but then additional items do not show.
I debugged the code and found that the items are being added to MToolBar.getChildren(). The other new items only show up if I switch to a new perspective and then switch back. I am guessing this means that the MToolBar is not being refreshed after adding the new items. I can't seem to find a method of MToolBar to refresh it. Is there a method I should be calling each time I dynamically add a new toolbar item to the toolbar?
Re: How can I get the IContributionManager for a MPart? [message #775701 is a reply to message #775352] Fri, 06 January 2012 09:43 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

re: added items not showing up. They are probably being added to the rendering ToolBarManager in org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.childAdditionUpdater

If the view toolbar is not being re-layed out by that code path, that's a bug in the renderer: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform&component=UI

PW


Re: How can I get the IContributionManager for a MPart? [message #775705 is a reply to message #775701] Fri, 06 January 2012 09:51 Go to previous message
Josh Davis is currently offline Josh Davis
Messages: 20
Registered: August 2011
Junior Member
I looked at it some more and when I add one item to the toolbar it covers up the down arrow for the part menu. When I add a second toolbar item it doesn't show. I am assuming because its being added but not to a visible part of the toolbar. As I said above if I switch to a different perspective and then switch back all the buttons show and the menu is accessible again. I checked the instance of mToolBar and the getRenderer() method returns null.

Shouldn't I be able to access the renderer from MToolBar and just force it to refresh?
Previous Topic:Eclipse 4.2 and No Server Tab
Next Topic:Eclipse Search in e4
Goto Forum:
  


Current Time: Fri Aug 22 11:47:38 EDT 2014

Powered by FUDForum. Page generated in 0.07478 seconds