package org.csstudio.platform.workspace;


import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.service.prefs.Preferences;

/** To store preferences which are independent from workspace. 
 * 	These preferences are stored at <code>Install_Location/configuration/.settings</code>
 *  You can add your own preference by inheriting this class
 *  @author Xihui Chen
 */
public class WorkspaceIndependentStore
{
    /** Qualifier used as preference store ID */
    private static final String PREF_QUALIFIER = WorkspaceIndependentStore.class.getName();

    /** Preference ID */
    private static final String LAST_LOGIN_USER = "last_login_user"; //$NON-NLS-1$

    
    /**
     * @return last login user
     */
    public static String readLastLoginUser()
    {
        return getString(LAST_LOGIN_USER);      
    }
    
    /** write the last logged in user's name into ConfigurationScope preference store
     * @param lastLoginUserName
     */
    public static void writeLastLoginUser(String lastLoginUserName) {
    	writeString(LAST_LOGIN_USER, lastLoginUserName);
    }
    
    /**Get the value of the input preference ID.
     * @param preferenceID the key trying to get its value
     * @return value associated with preferenceID
     */
    protected static String getString(final String preferenceID) {
    	final IPreferenceStore store = new ScopedPreferenceStore(
                new ConfigurationScope(), PREF_QUALIFIER);
    	return store.getString(preferenceID);
    }
    
    /**Write the value of the input preference ID into ConfigurationScope preference store
     * @param preferenceID the key trying to save its value
     * @param value value associated with preferenceID
     */
    protected static void writeString(final String preferenceID, final String value) {
    	 final Preferences node =
            new ConfigurationScope().getNode(PREF_QUALIFIER);
    	 node.put(preferenceID, value);    
    }

}
@@ -72,38 +72,55 @@
 ime.
-preferences.ConfigurationScope
+IStatus;%0Aimport org.eclipse.core.runtime.Status
 ;%0Aim
@@ -140,12 +140,19 @@
 pse.
-jfac
+core.runtim
 e.pr
@@ -163,82 +163,81 @@
 ence
-.IPreferenceStore;%0Aimport org.eclipse.ui.preferences.ScopedPreferenceStore
+s.ConfigurationScope;%0Aimport org.osgi.service.prefs.BackingStoreException
 ;%0Aim
@@ -663,50 +663,45 @@
 R = 
-WorkspaceIndependentStore.class.getName();
+%22org.csstudio.platform%22;//$NON-NLS-1$
 %0A%0A  
@@ -1380,32 +1380,60 @@
 ith preferenceID
+. return %22%22 if no value got.
 %0A     */%0A    pro
@@ -1501,15 +1501,8 @@
    %09
-final I
 Pref
@@ -1511,64 +1511,29 @@
 ence
-Store store = new ScopedPreferenceStore(%0A               
+s configurationNode =
  new
@@ -1553,18 +1553,25 @@
 nScope()
-, 
+.getNode(
 PREF_QUA
@@ -1588,45 +1588,86 @@
    %09
-return store.getString(preferenceID);
+String value = configurationNode.get(preferenceID, %22%22);%0A    %09return value;    
 %0A   
@@ -2105,20 +2105,311 @@
 value);    %0A
+    %09 try %7B%0A%09%09%09node.flush();%0A%09%09%7D catch (BackingStoreException e) %7B%0A%09%09    Activator.getInstance().getLog().log(%0A                    new Status(IStatus.ERROR, Activator.ID,%0A                            %22Cannot persist %22 + preferenceID + %22: %22%0A                            + e.getMessage()));%0A%09%09%7D%0A
     %7D%0A%0A%7D

add node.flush()