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: 206
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.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
Previous Topic:No way to Export my RCP Examples
Next Topic:How to change the language of Minimize/Maximize button in a PartStack?
Goto Forum:
  


Current Time: Fri Dec 06 10:07:49 GMT 2019

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

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

Back to the top