Posts Tagged ‘E4’

Eclipse e4 – Creating a new part dynamically

Tuesday, December 7th, 2010

Eclipse e4 allows to create application elements dynamically. The following is a small example how to create a part dynamically in a handler. This assumes that you have a class “de.vogella.e4.modelservice.part.NewPart” defined in plugin “de.vogella.e4.modelservice”.


	@Execute
	public void execute(EPartService partService, MApplication application,
			EModelService modelService) {
		MPart part = MBasicFactory.INSTANCE.createPart();
		part.setLabel("New Part");
		part.setContributionURI("platform:/plugin/de.vogella.e4.modelservice/de.vogella.e4.modelservice.part.NewPart");
		 List<MPartStack> stacks = modelService.findElements(application, null,
				MPartStack.class, null);
		 stacks.get(0).getChildren().add(part);
		 partService.showPart(part, PartState.ACTIVATE);
	}

The nice thing of this example is that it demonstrates how you can use the dynamic creating of application elements together with the part and the model service. Via the model service with use for a stack and this part is assigned to the first stack found.

You find more information in my Eclipse e4 tutorial.

Eclipse e4 and the EModelService

Wednesday, December 1st, 2010

One of the nicest things in my option in Eclipse e4 is that you have access to the model at runtime and can change it. To get access to the model you can use dependency injection to get the related model elements injected into your class or in you can use the EModelService.

The EModelService is pretty useful in my opinion as it allows you to access multiple model elements and you can use different filters, e.g. id, class name or tags. The following example is the implementation of a e4 handler. The first few statements will get get a few model elements and the last one will actually change the width of the first window to demonstrate that you can directly change model elements.

@Execute
	public void execute(MApplication application, EModelService service, Display display) {
		System.out.println("Got Model Service: " + (service != null));
		// Alternatively get the model service from the application
		EModelService modelService = (EModelService) application.getContext()
				.get(EModelService.class.getName());
		// both services are identical
		System.out.println("Got Model Service: " + (service != modelService));
		// Find objects by ID
		List<MPart> findElements = service.findElements(application, "mypart",
				MPart.class, null);
		System.out.println("Found part(s) : " + findElements.size());
		// Find objects by type
		List<MPart> parts = service.findElements(application, null,
				MPart.class, null);
		System.out.println("Found parts(s) : " + parts.size());
		// Find objects by tags
		List<String> tags = new ArrayList<String>();
		tags.add("justatag");
		List<MUIElement> elementsWithTags = modelService.findElements(application, null,
				null, tags);
		System.out.println("Found parts(s) : " + elementsWithTags.size());
		// Get the MWindow and change its size
		List<MWindow> windows = modelService.findElements(application, null, MWindow.class,
				 null);
		if (windows.size()>=1){
			 MWindow mWindow = windows.get(0);
			 System.out.println("Got the window");
			for (int i = mWindow.getWidth(); i >= mWindow.getWidth() - 100; i--) {
				while (!display.readAndDispatch()){
					mWindow.setWidth(i);
					wait10();
				}
			}
		}
	}
	private void wait10(){
		try {
			Thread.sleep(5);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

As usually find more details about Eclipse e4 in my Eclipse e4 tutorial.

Eclipse e4 Renderer – Google Maps

Tuesday, November 9th, 2010

As you might know Eclipse e4 decouples the application model from the rendering engines. For example you have a MPart model element which describes that the application should display a certain UI element (view) in your application. How this model element is drawn is determined by the renderer.

Another very nice thing about the renderer framework and the model is that the e4 application model can get extended and that you can define your own renderer for your own model element.

For example you can define a model element “GoogleMap” which will be renderered via your own renderer as a Google Map (using the SWT Browser widget).

Please find a complete description how to set this up in my Eclipse e4 renderer tutorial. You can also follow me on Twitter here if you want.

Take Eclipse 4.1 M3 for a spin

Wednesday, November 3rd, 2010

Andrew Niefer announced the availability of the Eclipse 4.1 M3 builds.

You can download it from http://download.eclipse.org/e4/sdk/drops/S-4.1M3-201010291118.

The e4 build provides a repo that can be used to install the source bundles for e4 UI and e4 UI CSS, as well as other e4 functionailty like the modeling tools, XWT, and SFS (resources). This has been a big problem for Eclipes 4.1 M2 and seems to be solved now. Congrats for providing the p2 update site!

Unfortunately the p2 update in Eclipse 4.1 M3 takes very, very, very, very long. So be patient if you try to install the e4 tooling.

In preparation of the Eclipse Summit Europe I have heavily extended my Eclipse e4 tutorial. Please give Eclipse 4.1 M3 a test drive and open bugs against Eclipse E4/UI (or appropriate component).

Modify the e4 model at startup via processors

Tuesday, October 26th, 2010

Eclipse e4 offers two ways to contribute to the application model, via fragments and processors. Fragments describe via static xmi additonal model elements and processors allow to add and modify existing model elements.

I added an example to my Eclipse 4.0 Tutorial how you could use a processor to remove certain model elements (in my case menu entries) and how to add a new one.


package de.vogella.e4.todo.contribute;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;

public class MenuProcessor {
	// I get this via the parameter of the process definition
	@Inject
	@Named("de.vogella.e4.todo.filemenu")
	private MMenu menu;

	@Execute
	public void execute() {
		// Remove the old exit menu entry
		if (menu != null && menu.getChildren() != null) {
			List<MMenuElement> list = new ArrayList<MMenuElement>();
			for (MMenuElement element : menu.getChildren()) {
				if (element.getLabel().contains("Exit")) {
					list.add(element);
				}
			}
			menu.getChildren().removeAll(list);
		}

               // Add a new menu entry
		MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
		menuItem.setLabel("Another Exit");
		menuItem.setContributionURI("platform:/plugin/de.vogella.e4.todo.contribute/de.vogella.e4.todo.contribute.handler.ExitHandlerWithCheck");
		menu.getChildren().add(menuItem);
	}
}

I hope this shows how simple the application model can be modified. For details check out Eclipse 4.0 Tutorial .

Drag and drop support for your parts within the workbench in Eclipse e4

Wednesday, October 20th, 2010

Some of you may have noticed that you cannot drag and drop your parts (views and editors) within an Eclipse e4 application by default.

To make this work add a dependency to the plugin “org.eclipse.e4.ui.workbench.addons.swt” and add the Add-On “org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon” to your “Application.e4xmi”. For example you could add it via the following:

I also updated my Eclipse e4 Tutorial.

Many thanks to Tom Schindl for the tip.

[Update] The D&D in the user interface creates additional containers. To get ride of them use the Add-On platform:/plugin/org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.cleanupaddon.CleanupAddon

The persistence of e4

Sunday, October 17th, 2010

In Eclipse 3.x you can remember the current application state (the user’s layout and window size) between application sessions, via the setting configurer.setSaveAndRestore(true); in the initialize method of ApplicationWorkbenchAdvisor. See Eclipse RCP Tips and Tricks for details.

Eclipse e4 has no ApplicationWorkbenchAdvisor class and the application model has no property to set this. Therefore you may assume that you cannot influence the e4 behavior.

But of course this is not true. :-)

e4 has two command line options to get a similar behavior then in Eclipse 3.6. If you use the command line option “-clearPersistedState” then the user changes will be deleted.

I believe “-deltaRestore” is intended to work similar to setSaveAndRestore(true). Currently in Eclipse 4.1 M2 the state is always saved but I think that is a minor bug. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=313883 for details.

Many thanks to Remy Suen for the tip on these parameters.

Once the bug discussion has been finished I will update my Eclipse 4.0 Tutorial.

[UPDATE: The parameter is not called deltaIgnore instead of "deltaRestore".]

Eclipse 4.0 Talk on 26.08 in Dresden / Germany

Thursday, August 5th, 2010

Are you around the Dresden area?

If so it would be great if you join my presentation about Eclipse 4.0 / Eclipse e4. The german title roughly translates into “the unexpected simplicity of developing Eclipse plugin and Eclipse RCP applications”.

The talk will be in German and details can be found on Saxony Website. I’m looking forward to meet you.

Eclipse 4.0 Application Platform – Tutorial Updated

Thursday, July 29th, 2010

As you know the Eclipse 4.0 SDK is out.

It also appears in discussions that some people don’t think Eclipse e4 is a good idea.

Other people seem to like it.

To help you to decide yourself I updated my Eclipse e4 Tutorial to Eclipse 4.0 Application Platform – Tutorial.

Together with Tom Schindls Tutorial you should be able to have a good start with Eclipse 4.0 SDK.

Please remember that the target of the core e4 Project is to improve the programming model of Eclipse and to provide an improved way of influencing the UI. The standard plugins are still the same and behave the same way.

My Tutorial also needs improvements, unfortunately it is not as far and deep as I like, but I hope that is will give you a good start. If you find issues, problems with my tutorial please let me know. The “more to come” section of my tutorial lists my future plans.

Eclipse e4 git mirror

Tuesday, July 20th, 2010

After some time and effort mainly by Denis Roy and Bernhard Merkle the e4 git mirrors are working.

You find the e4 repos listed Eclipes Git overview.

EGit is also kind enough to be able to import all the projects from the different levels of the projects.

So give it a try via EGit and check out the e4 source code, e.g. the e4 UI projects via git://dev.eclipse.org/org.eclipse.e4/org.eclipse.e4.ui.git or if you want to use http via http://dev.eclipse.org/git/org.eclipse.e4/org.eclipse.e4.ui.git.


Switch to our mobile site