001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.preferences;
024:
025: import net.sf.jmoney.JMoneyPlugin;
026: import net.sf.jmoney.VerySimpleDateFormat;
027:
028: import org.eclipse.jface.preference.BooleanFieldEditor;
029: import org.eclipse.jface.preference.DirectoryFieldEditor;
030: import org.eclipse.jface.preference.FieldEditorPreferencePage;
031: import org.eclipse.jface.preference.IPreferenceStore;
032: import org.eclipse.jface.preference.RadioGroupFieldEditor;
033: import org.eclipse.jface.preference.StringFieldEditor;
034: import org.eclipse.ui.IWorkbench;
035: import org.eclipse.ui.IWorkbenchPreferencePage;
036:
037: /**
038: * This class represents a preference page that
039: * is contributed to the Preferences dialog. By
040: * subclassing <samp>FieldEditorPreferencePage</samp>, we
041: * can use the field support built into JFace that allows
042: * us to create a page that is small and knows how to
043: * save, restore and apply itself.
044: * <p>
045: * This page is used to modify preferences only. They
046: * are stored in the preference store that belongs to
047: * the main plug-in class. That way, preferences can
048: * be accessed directly via the preference store.
049: */
050:
051: public class PreferencePage extends FieldEditorPreferencePage implements
052: IWorkbenchPreferencePage {
053: public static final String P_PATH = "pathPreference";
054:
055: public PreferencePage() {
056: super (GRID);
057: setPreferenceStore(JMoneyPlugin.getDefault()
058: .getPreferenceStore());
059: setDescription("JMoney preferences");
060: initializeDefaults();
061:
062: // The title of this page is picked up and used by the
063: // preference dialog as the text in the preferences
064: // navigation tree.
065: setTitle("core JMoney preferences");
066: }
067:
068: /**
069: * Sets the default values of the preferences.
070: */
071: private void initializeDefaults() {
072: IPreferenceStore store = getPreferenceStore();
073: store.setDefault("booleanPreference", true);
074: store.setDefault("dateFormat", "yyyy-MM-dd");
075: store.setDefault("stringPreference", "Default value");
076: }
077:
078: /**
079: * Creates the field editors. Field editors are abstractions of the common
080: * GUI blocks needed to manipulate various types of preferences. Each field
081: * editor knows how to save and restore itself.
082: */
083: @Override
084: public void createFieldEditors() {
085: addField(new DirectoryFieldEditor(P_PATH,
086: "&Directory preference:", getFieldEditorParent()));
087: addField(new BooleanFieldEditor("booleanPreference",
088: "&An example of a boolean preference",
089: getFieldEditorParent()));
090:
091: String dateOptions[] = VerySimpleDateFormat.DATE_PATTERNS;
092: String dateOptions2[][] = new String[dateOptions.length][];
093: for (int i = 0; i < dateOptions.length; i++) {
094: dateOptions2[i] = new String[] { dateOptions[i],
095: dateOptions[i] };
096: }
097:
098: addField(new RadioGroupFieldEditor("dateFormat", "Date Format",
099: 1, dateOptions2, getFieldEditorParent()));
100:
101: addField(new StringFieldEditor("stringPreference",
102: "A &text preference:", getFieldEditorParent()));
103: }
104:
105: public void init(IWorkbench workbench) {
106: }
107: }
|