Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » dynamically create view with toolbar
dynamically create view with toolbar [message #1810841] Tue, 20 August 2019 12:33
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 220
Registered: July 2009
Location: Graz, Austria
Senior Member
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.setElementId("org.eclipse.ease.view.dynamic:" + fCounter++);
				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");



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?

Previous Topic:No way to Export my RCP Examples
Next Topic:Handler enable/disable not working
Goto Forum:

Current Time: Mon Apr 19 12:02:18 GMT 2021

Powered by FUDForum. Page generated in 0.01890 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top