Posts Tagged ‘Eclipse 4.0’

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.

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".]

Have you heard about Eclipse 4.0 (aka e4)? – Podcast

Friday, May 21st, 2010

I had the pleasure to connect Ken Rimple from Chariot Tech Cast and Boris Bokowski.

Learning about the upcoming Eclipse 4.0 release has never been easier.

Just tune into Chariot TechCast Episode 55 – Interview with Boris Bokowski on Eclipse e4.They talk about

  • the current Eclipse release strategy
  • the new programming model using dependency injection
  • UI components
  • CSS Styling

I always enjoy the technical interviews from Ken, which covers sound technical details. And now you have a chance to learn about Eclipse 4.0 directly from Boris, the leading figure behind Eclipse 4.0.

Eclipse 4.0 is different & Mascot stories

Tuesday, April 27th, 2010

What if you want to make a good first impression and show how different Eclipse 4.0 really is? How helpful is the following splash screen in this quest?

Lets replace this splash with something “cooler” for example this:


To do this open the folder “plugin/org.eclipse.e4.ui.examples.legacy.workbench+yourversionnumber”. Here you find the file “splash.bmp”. Rename it and put a new bitmap file “splash.bmp” at its place.

Ok, arguely the process is almost the same as for a standard Eclipse 3.x installation but I think its nicer to do this for e4 to make clear the difference.

I also need to thank Oisín Hurley who, to my understanding ;-) , expressed a strong affinity to mascots and encouraged me to promote the idea of a stuffed animal as a mascot for Eclipse. I think by this he earned a lot of our respect.

[just to avoid any misunderstanding the statement above is a joke, Oisin seems to dislike mascots...]


Switch to our mobile site