|
|
|
Re: Part actionbar contributor [message #939375 is a reply to message #939333] |
Wed, 10 October 2012 17:58 |
Eclipse User |
|
|
|
As Dirk mentioned, first figure out how to do it using the model editor. Everything in the model editor is done by manipulating an EMF model, so you can do the same steps in code. The only trick is to figure out which factory you need to create the different objects (E4 has just shy of a dozen, i believe) -- the factories are all in org.eclipse.e4.ui.model.workbench and are named something like M*Factory.
Brian.
|
|
|
Re: Part actionbar contributor [message #940007 is a reply to message #939375] |
Thu, 11 October 2012 08:19 |
Dirk Fauth Messages: 2902 Registered: July 2012 |
Senior Member |
|
|
Hi,
I'm not sure if this is the preferred way as I'm quite new to Eclipse 4, but for adding items to a part toolbar I've found the following.
The Eclipse 4 Application model is a dynamic model. So you can add/remove/modify everything at runtime.
As Brian said, there are some factory classes that help on creating new model elements.
With the help of the EModelService you are able to find model elements that you want to modify.
The following code will search for a part in the application model and add a toolbar with one item to the part. It is in the constructor of the part to modify.
@Inject
public MyPart(MApplication application, EModelService service) {
List<MPart> parts = service.findElements(application, ID, MPart.class, null);
if (parts != null && !parts.isEmpty()) {
MPart myPart = parts.get(0);
//create the toolbar programmatically
MToolBar toolbar = MMenuFactory.INSTANCE.createToolBar();
//create the tool item programmatically
MDirectToolItem element = MMenuFactory.INSTANCE.createDirectToolItem();
element.setElementId("myToolItemId");
element.setIconURI("platform:/plugin/myBundle/icons/someicon.gif");
element.setContributionURI("bundleclass://myBundle/myBundle.handler.MyTestHandler");
element.setVisible(true);
element.setEnabled(true);
toolbar.getChildren().add(element);
myPart.setToolbar(toolbar);
}
}
Making programmatical contributions to the menu of the window should work in a similar way, but you need to find the window menu bar instead of the part toolbar.
Hope it works for you and this is really the Eclipse 4 way to do so.
Greez,
Dirk
|
|
|
Re: Part actionbar contributor [message #940029 is a reply to message #940007] |
Thu, 11 October 2012 08:47 |
Eclipse User |
|
|
|
You can also inject the MPart in the @PostConstruct method of the part so you don't have to do the searching. Create a method annotated with @PostConstruct and put a MPart p argument on it. After that do with p what Dirk did with myPart.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04039 seconds