display the PreferencePage [message #1038860] |
Thu, 11 April 2013 12:41 |
Marc Meier 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 #1039478 is a reply to message #1038860] |
Fri, 12 April 2013 08:01 |
Mateusz Malinowski 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04320 seconds