com.ultimatetech.cim.preferences.CIMPreferencePage.java Source code

Java tutorial

Introduction

Here is the source code for com.ultimatetech.cim.preferences.CIMPreferencePage.java

Source

/*******************************************************************************
 * Copyright (c) 2006 Ultimate Technology, Inc.
 * 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:
 *     Bojan Vukojevic - initial API and implementation
 *******************************************************************************/
package com.ultimatetech.cim.preferences;

import javax.wbem.client.CIMClient;

import org.eclipse.jface.preference.*;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbench;
import com.ultimatetech.cim.CIMPlugin;

/**
 * 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 CIMPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    public interface PreferenceNames {
        static final String IS_SECURE = "is-secure";
        static final String CIM_HOST = "cim-host";
        static final String CIM_PORT = "cim-port";
        static final String CIM_NAMESPACE = "cim-namespace";
        static final String CIM_FILTER = "cim-filter";
    }

    interface DefaultPreferenceValues {
        static final boolean IS_SECURE = false;
        static final String CIM_HOST = "localhost";
        static final String CIM_PORT = "5988";
        static final String CIM_NAMESPACE = "/root/cimv2";
        static final String CIM_FILTER = "";
    }

    public CIMPreferencePage() {
        super(GRID);
        setPreferenceStore(CIMPlugin.getDefault().getPreferenceStore());

        getPreferenceStore().setDefault(PreferenceNames.IS_SECURE, DefaultPreferenceValues.IS_SECURE);
        getPreferenceStore().setDefault(PreferenceNames.CIM_HOST, DefaultPreferenceValues.CIM_HOST);
        getPreferenceStore().setDefault(PreferenceNames.CIM_PORT, DefaultPreferenceValues.CIM_PORT);
        getPreferenceStore().setDefault(PreferenceNames.CIM_NAMESPACE, DefaultPreferenceValues.CIM_NAMESPACE);
        getPreferenceStore().setDefault(PreferenceNames.CIM_FILTER, DefaultPreferenceValues.CIM_FILTER);
        setDescription("Enter properties for connection to CIMOM. "
                + "Leave filter blank to retrieve all class names from CIMOM "
                + "or specify first few characters to filter class names "
                + "(i.e. ABC - return all classnames that start with ABC)");
    }

    /**
     * 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() {
        StringFieldEditor sfe = new StringFieldEditor(PreferenceConstants.P_STRING, "CIM &Host:",
                getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        sfe.setPreferenceName(PreferenceNames.CIM_HOST);
        addField(sfe);
        sfe = new StringFieldEditor(PreferenceConstants.P_STRING, "CIM &Port:", getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        sfe.setPreferenceName(PreferenceNames.CIM_PORT);
        addField(sfe);
        sfe = new StringFieldEditor(PreferenceConstants.P_STRING, "CIM &Name Space:", getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        sfe.setPreferenceName(PreferenceNames.CIM_NAMESPACE);
        addField(sfe);
        RadioGroupFieldEditor rfe = new RadioGroupFieldEditor(
                PreferenceConstants.P_CHOICE, "Protocol", 1, new String[][] { { "http/XML", "http" },
                        { "https/XML", "https" }, { CIMClient.CIM_RMI, CIMClient.CIM_RMI } },
                getFieldEditorParent());
        rfe.setPreferenceName(PreferenceNames.IS_SECURE);
        addField(rfe);
        sfe = new StringFieldEditor(PreferenceConstants.P_STRING, "CIM Class Name &Filter:",
                getFieldEditorParent());
        sfe.setEmptyStringAllowed(true);
        sfe.setPreferenceName(PreferenceNames.CIM_FILTER);
        addField(sfe);

    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
     */
    public void init(IWorkbench workbench) {
    }

}