Reputation: 341
I've build about 10-15 Parts in differenet PartStacks. Every Part should have some Handled Tool Item, 4 of them are identical. Because of this I want to reuse this 4 toolbar-items without adding them manually to every part.
In Eclipse 3.x we had build these toolbars via inheritance - each view, which should have this toolbar-items extends a class, which adds these items.
Is there a proper way to have a "toolbar-template"?
Any ideas wanted ;)
Cheers, Steffen
SOLUTION: (thanks greg)
Thank you Greg, the Processor worked.
Here is the corresponding code:
@Inject
@Named("de.test.myperspective")
private MPerspective perspective;
@Inject
private MApplication application;
@Execute
public void execute(EModelService modelService) {
if (perspective != null) {
List<MPart> parts = modelService.findElements(perspective, null,
MPart.class, null);
for (MPart part : parts) {
MUIElement snip = modelService.cloneSnippet(application,
"de.test.mytoolbarsnippet", null);
MToolBar toolbar = (MToolBar) snip;
part.getToolbar().getChildren()
.addAll(0, toolbar.getChildren());
}
}
}
In the fragment.xmi I added a new ModelFragment to Application->Snippets and added a Toolbar with ID "de.test.mytoolbarsnippet" there.
Upvotes: 1
Views: 606
Reputation: 111217
You could use a Snippet
in your application model.
Use the EModelService
cloneSnippet
method to create the controls from the snippet.
You might do this in a Processor running on the application model - see the org.eclipse.e4.workbench.model
extension point processor
element.
Upvotes: 1