Modify the e4 model at startup via processors

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;

public class MenuProcessor {
	// I get this via the parameter of the process definition
	private MMenu menu;

	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")) {

               // Add a new menu entry
		MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
		menuItem.setLabel("Another Exit");

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

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse and tagged , , . Bookmark the permalink.