I do like to programmatically create a view with a working toolbar.
Creating the view is rather simple:
final EPartService partService = PlatformUI.getWorkbench().getService(EPartService.class);
// create part
final EModelService modelService = PlatformUI.getWorkbench().getService(EModelService.class);
final MPart part = modelService.createModelElement(MPart.class);
// final MPart part = MBasicFactory.INSTANCE.createPart();
part.setLabel("Dynamic");
part.setIconURI("platform:/plugin/org.eclipse.ease.modules.platform/icons/eview16/scripted_view.png");
part.setElementId("org.eclipse.ease.view.dynamic:" + fCounter++);
part.setCloseable(true);
part.getPersistedState().put(IWorkbench.PERSIST_STATE, Boolean.FALSE.toString());
partService.showPart(part, PartState.VISIBLE);
This works nicely and the view is displayed correctly. Now I wanted to add a toolbar to it and added:
final MToolBar toolBar = modelService.createModelElement(MToolBar.class);
toolBar.getPersistedState().put(IWorkbench.PERSIST_STATE, Boolean.FALSE.toString());
toolBar.setElementId(part.getElementId() + ".toolbar");
final MToolBarSeparator separator = modelService.createModelElement(MToolBarSeparator.class);
separator.getPersistedState().put(IWorkbench.PERSIST_STATE, Boolean.FALSE.toString());
separator.setElementId(part.getElementId() + "additions");
toolBar.getChildren().add(separator);
toolBar.setVisible(true);
toolBar.setToBeRendered(true);
part.setToolbar(toolBar);
This seems to work just partly. The model spy correctly shows me the toolbar for my view, but I cannot add any elements to it using the model spy. As this works for other toolbars I guess my toolbar initialization is missing something. This is also the reason why I tried to add something to it (the separator) before it gets rendered. Still this does not work.
Do I need to define renderers for my toolbar or is this done by the framework automatically?
Christian