Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » display the PreferencePage
display the PreferencePage [message #1038860] Thu, 11 April 2013 12:41 Go to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Hello,

I used the PrefernecePage tutorial by Lars Vogella.

Unfortunately it does not happen correctly.

Here are my classes:
public class MyPreferencePage1 extends FieldEditorPreferencePage implements
    IWorkbenchPreferencePage {

  public MyPreferencePage1() {
    super(GRID);

  }

  public void createFieldEditors() {
    addField(new DirectoryFieldEditor("PATH", "&Directory preference:",
        getFieldEditorParent()));
    addField(new BooleanFieldEditor("BOOLEAN_VALUE",
        "&An example of a boolean preference", getFieldEditorParent()));

    addField(new RadioGroupFieldEditor("CHOICE",
        "An example of a multiple-choice preference", 1,
        new String[][] { { "&Choice 1", "choice1" },
            { "C&hoice 2", "choice2" } }, getFieldEditorParent()));
    addField(new StringFieldEditor("MySTRING1", "A &text preference:",
        getFieldEditorParent()));
    addField(new StringFieldEditor("MySTRING2", "A &text preference:",
        getFieldEditorParent()));
  }

  @Override
  public void init(IWorkbench workbench) {
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
    setDescription("A demonstration of a preference page implementation");
  }
} 



package de.vogella.preferences.page;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;



public class Activator extends AbstractUIPlugin {
	
	// The shared instance
		private static Activator plugin;

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}
	
	public static Activator getDefault() {
		return plugin;
	}

}


/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package de.vogella.preferences.page.handlers;

import javax.inject.Named;

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.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

public class PreferenceHandlerHandler {
	@Execute 
	public void execute(IEclipseContext context, ECommandService commandService, EHandlerService handlerService){ 
		
		ParameterizedCommand cmd = commandService.createCommand("org.eclipse.ui.window.preferences", null); 
		handlerService.executeHandler(cmd); 
		System.out.println(cmd.getCommand().isDefined()); 
		
		} 
}


I have linked the class PreferenceHandler with a menu item.
But when I run this menu item, it does not open the Prefernce Page. What is wrong?

thanks for your help

Marc
Re: display the PreferencePage [message #1038990 is a reply to message #1038860] Thu, 11 April 2013 15:39 Go to previous messageGo to next message
Phil Beauvoir is currently offline Phil BeauvoirFriend
Messages: 62
Registered: October 2012
Member
Do you set the static variable

plugin = this;

in your Activator? Looking at the code you posted, you aren't doing this.
Re: display the PreferencePage [message #1039407 is a reply to message #1038990] Fri, 12 April 2013 06:06 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Yes thats true, i have changed it ... but the Preference Page does not open.

		ParameterizedCommand cmd = commandService.createCommand("org.eclipse.ui.window.preferences", null); 
		handlerService.executeHandler(cmd); 


Is this Code correctly ?
Re: display the PreferencePage [message #1039478 is a reply to message #1038860] Fri, 12 April 2013 08:01 Go to previous messageGo to next message
Mateusz Malinowski is currently offline Mateusz MalinowskiFriend
Messages: 36
Registered: March 2013
Location: Bristol
Member
If you are using E4 (what I believe you do), I would suggest to get rid of IWorkbenchPreferencePage.

Simply create your class as you do, put things from init() method to the constructor (you won't be using this interface), give the method createFieldEditors() annotation @Override.

Have you also created an extension point org.eclipse.ui.preferencePages in your plugin?

You may find this thread worthy viewing: http://www.eclipse.org/forums/index.php/t/246345/

edit:
I just saw that in your Activator you are extending AbstractUIPlugin which uses RCP 3. Personally, I would suggest extending Plugin from org.eclipse.core.runtime package. You don't use there any AbstractUIPlugin's methods, so that should be fine. Even if you need them, you can easily write them yourself.

[Updated on: Fri, 12 April 2013 08:07]

Report message to a moderator

Re: display the PreferencePage [message #1045431 is a reply to message #1038860] Sat, 20 April 2013 08:20 Go to previous message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

The example you referening too, has been written for Eclipse 3.x and does not yet work on Eclipse4.x.

Best regards, Lars Vogel
Previous Topic:ActionHandler behavior change in Eclipse 4?
Next Topic:ContextInjectionFactory.invoke with own annotations.
Goto Forum:
  


Current Time: Fri Mar 29 02:22:39 GMT 2024

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

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

Back to the top