View Javadoc

1   package org.eparapher.rcp.preferences;
2   
3   import org.apache.log4j.Level;
4   import org.apache.log4j.Logger;
5   import org.eclipse.jface.preference.FieldEditorPreferencePage;
6   import org.eclipse.jface.preference.FileFieldEditor;
7   import org.eclipse.jface.preference.PathEditor;
8   import org.eclipse.jface.preference.RadioGroupFieldEditor;
9   import org.eclipse.ui.IWorkbench;
10  import org.eclipse.ui.IWorkbenchPreferencePage;
11  import org.eparapher.core.EParapherManager;
12  import org.eparapher.rcp.Activator;
13  import org.eparapher.rcp.EPReferences;
14  
15  
16  /**
17   * This class represents a preference page that
18   * is contributed to the Preferences dialog. By 
19   * subclassing <samp>FieldEditorPreferencePage</samp>, we
20   * can use the field support built into JFace that allows
21   * us to create a page that is small and knows how to 
22   * save, restore and apply itself.
23   * <p>
24   * This page is used to modify preferences only. They
25   * are stored in the preference store that belongs to
26   * the main plug-in class. That way, preferences can
27   * be accessed directly via the preference store.
28   */
29  
30  public class EParapherPreferencePage
31  	extends FieldEditorPreferencePage
32  	implements IWorkbenchPreferencePage {
33  	
34  	private static Logger log = Logger.getLogger(EParapherPreferencePage.class);
35  	
36  	public static final String ID = "org.eparapher.rcp.preferences.EParapherPreferencePage";
37  
38  	private final static String[][] LoglevelFamilies = { { "OFF",         Level.OFF.toString()    },
39  														 { "FATAL",       Level.FATAL.toString()  },
40  														 { "ERROR",       Level.ERROR.toString()  },
41  														 { "WARNING",     Level.WARN.toString()   },
42  														 { "INFO",        Level.INFO.toString()   },
43  														 { "DEBUG",       Level.DEBUG.toString()  },
44  														 { "ALL",         Level.ALL.toString()    } };
45  
46  	PathEditor 			 localdocspath;
47  	FileFieldEditor      localpsafepath;
48  	RadioGroupFieldEditor loglevel;
49  	
50  	public EParapherPreferencePage() {
51  		super(GRID);
52  		setPreferenceStore(Activator.getDefault().getPreferenceStore());
53  		setDescription("eParapher Configuration");
54  	}
55  
56  	/**
57  	 * Creates the field editors. Field editors are abstractions of
58  	 * the common GUI blocks needed to manipulate various types
59  	 * of preferences. Each field editor knows how to save and
60  	 * restore itself.
61  	 */
62  	public void createFieldEditors() {
63  		
64  		localdocspath = new PathEditor(PreferenceConstants.P_LOCALDOCPATH, "&Local documents Directories :", "Choose a Path", getFieldEditorParent());
65  		addField(localdocspath);
66  		
67  		//localpsafepath   = new FileFieldEditor( PreferenceConstants.P_LOCALPSAFEPATH, "&Local Personal Safe :", getFieldEditorParent());
68  		//localpsafepath.setEnabled(false, getFieldEditorParent());
69  		//localpsafepath.setStringValue("Not implemented yet");
70  		//addField(localpsafepath);
71  
72  		loglevel = new RadioGroupFieldEditor( PreferenceConstants.P_LOGLEVEL,"&eParapher Log level : ", 7, LoglevelFamilies, getFieldEditorParent(), true);
73  		addField(loglevel);
74  	}
75  
76  	/* (non-Javadoc)
77  	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
78  	 */
79  	public void init(IWorkbench workbench) {
80  		
81  	}
82  
83      public boolean performOk() {
84      	
85      	//First, save properties
86      	boolean save = super.performOk();
87      	
88      	//Hot reset for Log4J
89      	EParapherManager.setLogLevel(EParapherManager.getInstance().getSettings().getEPLogLevel());
90      	
91      	//Refresh document view
92      	if (EPReferences.getInstance().getDocviews()!=null)
93      		EPReferences.getInstance().getDocviews().refreshView();
94      	
95          return save;
96      }
97  }