net.openchrom.xxd.processor.supplier.rscripting.ui.preferences.PreferencePage.java Source code

Java tutorial

Introduction

Here is the source code for net.openchrom.xxd.processor.supplier.rscripting.ui.preferences.PreferencePage.java

Source

/*******************************************************************************
 * Copyright (c) 2017 Lablicate GmbH.
 *
 * 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:
 *
 * Dr. Philip Wenig - initial API and implementation
 *******************************************************************************/
package net.openchrom.xxd.processor.supplier.rscripting.ui.preferences;

import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import net.openchrom.xxd.processor.supplier.rscripting.ui.Activator;
import net.openchrom.xxd.processor.supplier.rscripting.ui.Util;
import net.openchrom.xxd.processor.supplier.rscripting.ui.code.PreferenceConstants;

public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    public PreferencePage() {
        super(GRID);
        setPreferenceStore(Activator.getDefault().getPreferenceStore());
        setDescription("R-Scripting");
    }

    /**
     * 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() {

        String os = Util.getOS();
        if (os.equals("Windows")) {
            addField(new LabelFieldEditor(
                    "* Select Path of R Server directory, i.e. C:\\Program Files\\Microsoft\\R Client\\R_SERVER\\",
                    getFieldEditorParent()));
        } else if (os.equals("Linux")) {
            addField(new LabelFieldEditor("* Select Path for /bin/R directory, i.e. /usr", getFieldEditorParent()));
        } else if (os.equals("Mac")) {
            addField(new LabelFieldEditor("* Select Path for /bin/R directory, i.e. /usr", getFieldEditorParent()));
        }
        addField(new DirectoryFieldEditor(PreferenceConstants.PATH_R, "&Path to R:", getFieldEditorParent()));
        addField(new DirectoryFieldEditor(PreferenceConstants.D_SCRIPT_R, "&Path to R Scripts:",
                getFieldEditorParent()));
        addField(new DirectoryFieldEditor(PreferenceConstants.D_RSHELL_SCRIPTS, "&Path to R Shell Scripts:",
                getFieldEditorParent()));
    }

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

        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        try {
            if (Util.getOS().equals("Windows")) {
                store.setDefault(PreferenceConstants.PATH_R, Reg.setPrefReg(PreferenceConstants.PATH_R));
            }
        } catch (RuntimeException e) {
        }
    }
}