Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 Preferences Dialog(Problems to display PreferencePages)
E4 Preferences Dialog [message #1727698] Fri, 25 March 2016 12:04 Go to next message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 25
Registered: January 2015
Junior Member
Hi,
I am migrating to E4 right now. I am wondering how to implement the Window -> Preferences Menu. Its quite a basic use case and I tried the approach mentioned here (https://www.eclipse.org/forums/index.php/t/282692/).

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.log.Logger;

@SuppressWarnings("restriction")
public class PreferencesHandler {

	@Execute
	void execute(ECommandService commandService, EHandlerService handlerService, Logger logger) {

		
		Command command = commandService.getCommand("org.eclipse.ui.window.preferences");

		// check if the command is defined
		System.out.println(command.isDefined());

		// activate handler, assumption: the AboutHandler() class exists already
		handlerService.activateHandler("my.fancy.app.ui.app.command.preferences", 
		    new PreferencesHandler());

		// prepare execution of command
		ParameterizedCommand cmd =
		  commandService.createCommand("org.eclipse.ui.window.preferences", null);

		// check if the command can get executed
		if (handlerService.canExecute(cmd)){
		  // execute the command
		  handlerService.executeHandler(cmd);
		} else {
			System.err.println("NEIN");
		}
	}
}


Unfortunately, When I try to execute the command using the handlerService,
handlerService.canExecute(cmd)
always returns false.

How can I get the PreferencesPages working?
Many thanks!

[Updated on: Fri, 25 March 2016 12:20]

Report message to a moderator

Re: E4 Preferences Dialog [message #1727705 is a reply to message #1727698] Fri, 25 March 2016 14:47 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I have implemented a plain e4 solution for preferences based on osgi declarative services.
https://github.com/fipro78/e4-preferences

IIRC there is also a solution by Olivier Prouvost with a slight different approach. Can't find the link right now.

Choose which solution matches best for you
Re: E4 Preferences Dialog [message #1727708 is a reply to message #1727705] Fri, 25 March 2016 14:58 Go to previous messageGo to next message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 25
Registered: January 2015
Junior Member
Hi Dirk,

many thanks for the link, I will give it a try!

Best,
Re: E4 Preferences Dialog [message #1727750 is a reply to message #1727708] Sat, 26 March 2016 19:24 Go to previous message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 25
Registered: January 2015
Junior Member
Hi Dirk,
this works like a charm!
Many thanks!
Previous Topic:Using File oriented editors and package explorer in e4
Next Topic:Styling MPartStack tab-height with relative height
Goto Forum:
  


Current Time: Thu Apr 25 13:16:26 GMT 2024

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

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

Back to the top