| Free tutorials for Java, Eclipse and Web programming |
You can access perferences in othe plugins via the PreferenceService. For this example create a new Eclipse plugin "de.vogella.preferences.access" (not RCP) and add the following command handler to the menu.
package de.vogella.preferences.access.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
public class AccessPreferences extends AbstractHandler {
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
String text = Platform.getPreferencesService().getString(
"de.vogella.preferences.page", "MySTRING1", "hello", null);
MessageDialog.openInformation(window.getShell(),
"Access for preferences in different plugin", text);
return null;
}
}
Add this plugin to the launch configuration of plugin "de.vogella.preferences.page" and you should be able to access the preferences of "de.vogella.preferences.page".