Package hidb2.gui.preferences

Source Code of hidb2.gui.preferences.PrefPage

/**
* This file is part of HIDB2.
*
* PoJamas is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HIDB2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2.  If not, see <http://www.gnu.org/licenses/>.
*/

package hidb2.gui.preferences;

import hidb2.Activator;
import hidb2.gui.Application;
import hidb2.gui.node.DefaultNode;

import java.util.logging.Logger;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.FontFieldEditor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
* 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 PrefPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
  {
  final static Logger log = Logger.getLogger("hidb2.gui.preferences");

  private String _dbDir = null;

  public PrefPage()
    {
    super(GRID);
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
    setDescription("HIDB2 Preference page");

    // Keep previous DB dir
    _dbDir = Activator.getDefault().getPreferenceStore().getString(PrefConst.P_DB_DIR);

    }

  /**
   * 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 DirectoryFieldEditor(PrefConst.P_DB_DIR, "&Db Dir:", getFieldEditorParent()));

    addField(new FileFieldEditor(PrefConst.P_TEXT_EDITOR_CMD, "&External Text Editor:", getFieldEditorParent()));

    addField(new FontFieldEditor(PrefConst.P_FNT_TREE_STD, "Default Tree Font", getFieldEditorParent()));
   
    addField(new FontFieldEditor(PrefConst.P_FNT_TREE_POSERFILE, "Default Font", getFieldEditorParent()));
    }

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

  /* (non-Javadoc)
   * @see org.eclipse.jface.preference.PreferencePage#performOk()
   */
  @Override
  public boolean performOk()
    {
    boolean res = super.performOk();

    String newDbDir = Activator.getDefault().getPreferenceStore().getString(PrefConst.P_DB_DIR);
    if (!newDbDir.equals(_dbDir))
      {
      // Database diectory changed
      log.info("Database directory changed to:" + newDbDir);
     
      MessageDialog.openInformation(getShell(), "Restart", "Database directory changed to:" + newDbDir + "\nHIDB2 shall restart");
     
      Application.restart();
      }

    // Shall signal to other components, that preferences have been changed.
    DefaultNode.init(Display.getDefault());
   
    Application.restartViews();

    return res;
    }

  }
TOP

Related Classes of hidb2.gui.preferences.PrefPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.