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 Go to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
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
Re: dynamically create view with toolbar [message #1852133 is a reply to message #1810841] Sun, 01 May 2022 20:09 Go to previous message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Hi, I have a very similar problem with e4 in eclipse 2022.03.
This line
part.setToolbar(toolBar);
leads to a NPE because another injected method in the framework (due to a topc sent by the event broker) tries to access the parent of the parent of the toolbar which is null.. Although i did a very good analysis to the track of the problem, I cannot yet solve it.
Previous Topic:org/eclipse/jdt/internal/ui/javaeditor/JavaEditor
Next Topic:Different behavior for changes of "active selection"
Goto Forum:
  


Current Time: Fri Apr 26 14:04:45 GMT 2024

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

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

Back to the top