org.openmaji.implementation.tool.eclipse.editor.common.preference.MeemDefinitionPreferencePage.java Source code

Java tutorial

Introduction

Here is the source code for org.openmaji.implementation.tool.eclipse.editor.common.preference.MeemDefinitionPreferencePage.java

Source

/*
 * @(#)MeemDefinitionPreferencePage.java
 *
 * Copyright 2003 by EkoLiving Pty Ltd.  All Rights Reserved.
 *
 * This software is the proprietary information of EkoLiving Pty Ltd.
 * Use is subject to license terms.
 */

/* ToDo:
 * - None, yet.
 */
package org.openmaji.implementation.tool.eclipse.editor.common.preference;

import org.eclipse.jface.preference.*;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.openmaji.implementation.tool.eclipse.plugin.MajiPlugin;

/**
 * This class represents a preference page that
 * is contributed to the Preferences dialog. By 
 * subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows
 * us to create a page that is small and knows how to 
 * save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They
 * are stored in the preference store that belongs to
 * the main plug-in class. That way, preferences can
 * be accessed directly via the preference store.
 */

public class MeemDefinitionPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    public static final String P_BOOLEAN = "booleanPreference";
    public static final String P_CHOICE = "choicePreference";
    public static final String P_STRING = "stringPreference";

    public MeemDefinitionPreferencePage() {
        super(GRID);
        setPreferenceStore(MajiPlugin.getDefault().getPreferenceStore());
        setDescription("A demonstration of a preference page implementation");
        initializeDefaults();
    }

    /**
     * Sets the default values of the preferences.
     */
    private void initializeDefaults() {
        IPreferenceStore store = getPreferenceStore();
        store.setDefault(P_BOOLEAN, true);
        store.setDefault(P_CHOICE, "choice2");
        store.setDefault(P_STRING, "Default value");
    }

    /**
     * Creates the field editors. Field editors are abstractions of
     * the common GUI blocks needed to manipulate various types
     * of preferences. Each field editor knows how to save and
     * restore itself.
     */

    public void createFieldEditors() {
        addField(new FileListEditor("jarsPaths", "&Jars:", getFieldEditorParent()));
        addField(new BooleanFieldEditor(P_BOOLEAN, "&An example of a boolean preference", getFieldEditorParent()));

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

    public void init(IWorkbench workbench) {
    }

    public boolean performOk() {
        if (super.performOk()) {
            MajiPlugin.getDefault().savePluginPreferences();
            return true;
        }
        return false;
    }
}