I have an RCP application and I need to set some values in the preference page as defaults when the RCP run as an application. I need to hide the Fast View bar and some menus from a certain peresepective that is why I need to set these settings from the preference page.
My application is not a product yet, so I cant use the plugin_customization.ini file to change in it.
Can anyone tell me a way to change the default values programmatically via the preference page or any other way?
To invoke this dialog, click on the Window menu and select the Preferences menu item. The preference pages are organized by category. You can locate a preference page by expanding the nodes of the tree in the left hand side of the dialog box.
Preferences are stored in the workspace of your application in the . metadata/. plugins/org. eclipse.
While the Eclipse platform is designed to serve as an open tools platform, it is architected so that its components could be used to build just about any client application. The minimal set of plug-ins needed to build a rich client application is collectively known as the Rich Client Platform.
Define extension points for your preference page, and for that page's initializer class:
An example preference page implementation might look like:
public class MyPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public static final String PREF_USE_METRIC_UNITS = "PREF_USE_METRIC_UNITS";
public static final String PREF_AUTO_UPDATE = "PREF_AUTO_UPDATE";
public static final String PREF_USER_FILES_DIR = "PREF_USER_FILES_DIR";
public static final String PREF_FAVORITE_ANIMAL = "PREF_FAVORITE_ANIMAL";
public MyPreferencePage() {
super(GRID);
}
public void createFieldEditors() {
Composite parent = getFieldEditorParent();
addField(new BooleanFieldEditor(PREF_USE_METRIC_UNITS, "Use &metric units", parent));
addField(new BooleanFieldEditor(PREF_AUTO_UPDATE, "&Auto update", parent));
addField(new DirectoryFieldEditor(PREF_USER_FILES_DIR, "User files &path:", parent));
addField(new StringFieldEditor(PREF_FAVORITE_ANIMAL, "Favorite &animal:", parent));
}
public void init(IWorkbench workbench) {
setPreferenceStore(Plugin.getPlugin().getPreferenceStore());
}
}
You then set the actual default values in your AbstractPreferenceInitializer class:
public class MyPreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Plugin.getPlugin().getPreferenceStore();
store.setDefault(MyPreferencePage.PREF_USE_METRIC_UNITS, true);
store.setDefault(MyPreferencePage.PREF_AUTO_UPDATE, false);
String userHome = System.getProperty("user.home");
String defaultPath = userHome + "\\Local Settings\\Temp\\";
store.setDefault(MyPreferencePage.PREF_USER_FILES_DIR, defaultPath);
store.setDefault(MyPreferencePage.PREF_FAVORITE_ANIMAL, "platypus");
}
}
You can use the extension point org.eclipse.core.runtime.preferences
<extension
point="org.eclipse.core.runtime.preferences">
<scope name="SamplePreferencePage" class="com.example.SamlePreferencePage"/>
<initializer
class="com.example.PreferenceInitializer">
</initializer>
</extension>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With