View Javadoc

1   // KeepResidentPreferencePage.java, created Aug 14, 2004 1:20:44 AM by joewhaley
2   // Copyright (C) 2004 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the CPL; see LICENSE.txt for details.
4   package edu.stanford.suif.keepresident.preferences;
5   
6   import org.eclipse.jface.preference.BooleanFieldEditor;
7   import org.eclipse.jface.preference.FieldEditorPreferencePage;
8   import org.eclipse.ui.IWorkbench;
9   import org.eclipse.ui.IWorkbenchPreferencePage;
10  import edu.stanford.suif.keepresident.KeepResidentPlugin;
11  import edu.stanford.suif.keepresident.KernelException;
12  import edu.stanford.suif.keepresident.LabelledScaleFieldEditor;
13  
14  /***
15   * This class represents a preference page that is contributed to the
16   * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage </samp>,
17   * we can use the field support built into JFace that allows us to create a page
18   * that is small and knows how to save, restore and apply itself.
19   * <p>
20   * This page is used to modify preferences only. They are stored in the
21   * preference store that belongs to the main plug-in class. That way,
22   * preferences can be accessed directly via the preference store.
23   */
24  public class KeepResidentPreferencePage extends FieldEditorPreferencePage
25      implements
26          IWorkbenchPreferencePage {
27      public static final String P_MIN = "minPreference";
28      public static final String P_MAX = "maxPreference";
29      public static final String P_LOCK = "lockPreference";
30  
31      LabelledScaleFieldEditor minEditor;
32      LabelledScaleFieldEditor maxEditor;
33      BooleanFieldEditor lockEditor;
34      
35      public KeepResidentPreferencePage() {
36          super(GRID);
37          setPreferenceStore(KeepResidentPlugin.getDefault().getPreferenceStore());
38          setDescription("Adjust size of working set.");
39      }
40  
41      /***
42       * Creates the field editors. Field editors are abstractions of the common
43       * GUI blocks needed to manipulate various types of preferences. Each field
44       * editor knows how to save and restore itself.
45       */
46      public void createFieldEditors() {
47          int min = KeepResidentPlugin.getDefault().getHardMinimum();
48          int max = KeepResidentPlugin.getDefault().getHardMaximum();
49          minEditor = new LabelledScaleFieldEditor(
50              P_MIN, "Mi&nimum working set size:", getFieldEditorParent(),
51              min, max, 1048576, 10485760);
52          addField(minEditor);
53          maxEditor = new LabelledScaleFieldEditor(
54              P_MAX, "Ma&ximum working set size:", getFieldEditorParent(),
55              min, max, 1048576, 10485760);
56          addField(maxEditor);
57          lockEditor = new BooleanFieldEditor(P_LOCK,
58              "Use Virtual&Lock to force working set to stay resident (potentially unstable)",
59              getFieldEditorParent());
60          addField(lockEditor);
61      }
62  
63      public void init(IWorkbench workbench) {
64          KeepResidentPlugin.getDefault().updateProcessWorkingSetSize();
65      }
66      
67      public boolean performOk() {
68          boolean b = super.performOk();
69          boolean success = false;
70          try {
71              KeepResidentPlugin.getDefault().update();
72              success = true;
73          } catch (KernelException x) {
74              this.setErrorMessage(x.getMessage());
75              try {
76                  KeepResidentPlugin.getDefault().updateProcessWorkingSetSize();
77              } catch (KernelException y) {
78              }
79          }
80          minEditor.load();
81          maxEditor.load();
82          if (success) {
83              int lockedBytes = KeepResidentPlugin.getDefault().getLockedBytes();
84              if (lockedBytes != 0) {
85                  this.setMessage(lockedBytes+" bytes locked into memory.");
86              }
87          }
88          return b;
89      }
90  }