ref #5969: get the preference NC from db when initialize preference store and save...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
index 9a8c1668f7bc4587416447e2c5753c1b6371b1c2..d6a8f6bf71a0e092cb73595ff550e783dac2e12b 100644 (file)
@@ -1,28 +1,43 @@
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
 
 package eu.etaxonomy.taxeditor.preference;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
+import java.util.StringTokenizer;
 import java.util.UUID;
 
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
 
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
+import eu.etaxonomy.cdm.api.service.IPreferenceService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
@@ -30,25 +45,32 @@ import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.IDefinedTerm;
+import eu.etaxonomy.cdm.model.common.ISimpleTerm;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.common.TermBase;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
 import eu.etaxonomy.cdm.strategy.match.MatchException;
 import eu.etaxonomy.cdm.strategy.match.MatchMode;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
 
 /**
  * <p>
  * PreferencesUtil class.
  * </p>
- * 
+ *
  * @author p.ciardelli
  * @author n.hoffmann
  * @created 05.12.2008
@@ -57,15 +79,20 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 public class PreferencesUtil implements IPreferenceKeys {
 
        /**
-        * 
+        *
         */
        public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
 
+       public static final String P2_REPOSITORIES_DELIM = ",";
+       public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+
+
+
        /**
         * <p>
         * getPreferenceStore
         * </p>
-        * 
+        *
         * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
         */
        public static IPreferenceStore getPreferenceStore() {
@@ -76,29 +103,67 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setPreferredNomenclaturalCode
         * </p>
-        * 
+        *
         * @param preferredCode
         *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
         *            object.
         */
        public static void setPreferredNomenclaturalCode(
                        NomenclaturalCode preferredCode) {
+               ICdmApplicationConfiguration controller;
+               controller = CdmStore.getCurrentApplicationConfiguration();
+               PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+               CdmPreference preference = null;
+               if (preferredCode == null){
+                       preference = controller.getPreferenceService().find(key);
+                       int index = StringUtils.lastIndexOf(preference.getValue(), ".");
+                       UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
+                       preferredCode = NomenclaturalCode.getByUuid(uuid);
+               } else{
+                       preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
+                       controller.getPreferenceService().set(preference);
+               }
+                
+           
                getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
-                               getPreferenceKey(preferredCode));
+                               getPreferenceKey(preferredCode));
        }
 
+       public static NomenclaturalCode getPreferredNomenclaturalCode(){
+               return getPreferredNomenclaturalCode(false);
+       }
+       
        /**
         * <p>
         * getPreferredNomenclaturalCode
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
         */
-       public static NomenclaturalCode getPreferredNomenclaturalCode() {
-
-               for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
-                       String preferredCode = getPreferenceStore().getString(
+       public static NomenclaturalCode getPreferredNomenclaturalCode(boolean preConnected) {
+               ICdmApplicationConfiguration controller;
+               CdmPreference pref = null;
+               if (!preConnected){
+                       try{
+                               controller = CdmStore.getCurrentApplicationConfiguration();
+                               PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+                           pref = controller.getPreferenceService().find(key);
+                       }catch(Exception e){
+                               e.printStackTrace();
+                       }
+               }
+               
+           String preferredCode;
+           if(pref == null){
+               preferredCode = getPreferenceStore().getString(
                                        PREFERRED_NOMENCLATURAL_CODE_KEY);
+           }else{
+               preferredCode = pref.getValue();
+           }
+           
+               for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
+//                     String preferredCode = getPreferenceStore().getString(
+//                                     PREFERRED_NOMENCLATURAL_CODE_KEY);
                        if (getPreferenceKey(code).equals(preferredCode)) {
                                return code;
                        }
@@ -106,10 +171,18 @@ public class PreferencesUtil implements IPreferenceKeys {
                return null;
        }
 
+       public static String getPreferredDefaultLangugae(){
+           String preferredLanguage = getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR);
+           if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
+               return preferredLanguage;
+           }
+           return null;
+       }
+
        /**
         * Get the match strategy for the given class that was stored in preferences
         * or the default strategy if it was not stored in preferences
-        * 
+        *
         * @param clazz
         *            a {@link java.lang.Class} object.
         * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
@@ -126,7 +199,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                                try {
                                        matchStrategy.setMatchMode(fieldName, matchMode);
                                } catch (MatchException e) {
-                                       StoreUtil.error(PreferencesUtil.class, e);
+                                       MessagingUtils.error(PreferencesUtil.class, e);
                                        throw new RuntimeException(e);
                                }
                        }
@@ -138,7 +211,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Stores a matchStrategy into the preference store.
-        * 
+        *
         * @param matchStrategy
         *            a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
         *            object.
@@ -158,7 +231,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Helper method to create the preference property for a match field.
-        * 
+        *
         * @param className
         * @param fieldName
         * @return
@@ -170,7 +243,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Returns the default match strategy for a given class.
-        * 
+        *
         * @param clazz
         *            a {@link java.lang.Class} object.
         * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
@@ -183,7 +256,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getDateFormatPattern
         * </p>
-        * 
+        *
         * @return a {@link java.lang.String} object.
         */
        public static String getDateFormatPattern() {
@@ -196,7 +269,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * addTermToPreferredTerms
         * </p>
-        * 
+        *
         * @param term
         *            a T object.
         * @param <T>
@@ -215,33 +288,52 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Construct a unique key using the CdmBase object's uuid
-        * 
+        *
         * @param cdmBase
         * @return
         */
        private static String getPreferenceKey(ICdmBase cdmBase) {
-               cdmBase = (ICdmBase) HibernateProxyHelper.deproxy(cdmBase);
+               cdmBase = HibernateProxyHelper.deproxy(cdmBase);
 
                String key = cdmBase.getClass().getName().concat(".")
                                .concat(cdmBase.getUuid().toString());
                if (key.contains("javassist")) {
-                       StoreUtil.info("proxy");
+                       MessagingUtils.info("proxy");
+               }
+               return key;
+       }
+
+       /**
+        * Construct a unique key using the CdmBase object's uuid
+        *
+        * @param cdmBase
+        * @return
+        */
+       public static String getPreferenceKey(ISimpleTerm simpleTerm) {
+               simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
+               String key = simpleTerm.getClass().getName().concat(".")
+                               .concat(simpleTerm.getUuid().toString());
+               if (key.contains("javassist")) {
+                       MessagingUtils.warn(PreferencesUtil.class,
+                                       "Trying to persist a preference based on a proxy class.");
                }
                return key;
        }
 
+
+
        /**
         * Construct a unique key using the CdmBase object's uuid
-        * 
+        *
         * @param cdmBase
         * @return
         */
        public static String getPreferenceKey(IDefinedTerm definedTerm) {
-               definedTerm = (IDefinedTerm) HibernateProxyHelper.deproxy(definedTerm);
+               definedTerm = HibernateProxyHelper.deproxy(definedTerm);
                String key = definedTerm.getClass().getName().concat(".")
                                .concat(definedTerm.getUuid().toString());
                if (key.contains("javassist")) {
-                       StoreUtil.warn(PreferencesUtil.class,
+                       MessagingUtils.warn(PreferencesUtil.class,
                                        "Trying to persist a preference based on a proxy class.");
                }
                return key;
@@ -249,7 +341,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Retrieves search preferences from the preference store
-        * 
+        *
         * @return an {@link ITaxonServiceConfigurator} to pass to search methods
         */
        public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
@@ -263,13 +355,14 @@ public class PreferencesUtil implements IPreferenceKeys {
                                TAXON_SERVICE_CONFIGURATOR_NAMES));
                configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
                                TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
+               //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
 
                return configurator;
        }
 
        /**
         * create new preferences, setting all search options to true
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
         *         object.
@@ -292,7 +385,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                // match mode is a simple like, actually all other match modes are kind
                // of bogus
                configurator
-                               .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.LIKE);
+                               .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
                // we set page number and size here as this should always be unlimited
                configurator.setPageNumber(0);
                // TODO currently limit results to 10000
@@ -303,7 +396,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Store search preferences
-        * 
+        *
         * @param configurator
         *            a
         *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
@@ -325,7 +418,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * firePreferencesChanged
         * </p>
-        * 
+        *
         * @param clazz
         *            a {@link java.lang.Class} object.
         */
@@ -342,12 +435,15 @@ public class PreferencesUtil implements IPreferenceKeys {
                getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
                                true);
                getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT,
-                               "http://edit.br.fgov.be/edit_wp5/v1/areas.php");
-               getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, true);
+                               "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
+               //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
+               getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, false);
                getPreferenceStore().setDefault(OPENURL_ACCESS_POINT,
                                "http://www.biodiversitylibrary.org/openurl");
                getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000");
                getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT, "1000");
+               getPreferenceStore().setDefault(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, false);
+               getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY, true);
        }
 
        /**
@@ -357,13 +453,17 @@ public class PreferencesUtil implements IPreferenceKeys {
         */
        public static void checkNomenclaturalCode() {
                // First time Editor is opened, no nomenclatural code has been set
-               if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
+
+
+               if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
+                       PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP);
+                       /*
 
                        StoreUtil.info("No nomencatural code set.");
 
                        Shell shell = StoreUtil.getShell();
 
-                       // Query user re: preferred nom. code
+                Query user re: preferred nom. code
                        Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
                        dialog.open();
 
@@ -377,15 +477,28 @@ public class PreferencesUtil implements IPreferenceKeys {
                                                        "The following has been set as your preferred nomenclatural code:\n\n\t"
                                                                        + NomenclaturalCodeHelper
                                                                                        .getDescription(code)
-                                                                       + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
+                                                                       + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
                }
        }
 
+       public static void checkDefaultLanguage(){
+           if(PreferencesUtil.getPreferredDefaultLangugae() == null){
+              Shell shell = AbstractUtility.getShell();
+              int open = new DefaultLanguageDialog(shell).open();
+              if(open == Window.OK){
+                  PlatformUI.getWorkbench().restart();
+              }
+           }else{
+               //TODO:In case of a reinstall, the config.ini will be overwritten
+               //     here you create config.ini with the stored key from preferences
+           }
+       }
+
        /**
         * <p>
         * getMapServiceAccessPoint
         * </p>
-        * 
+        *
         * @return a {@link java.lang.String} object.
         */
        public static String getMapServiceAccessPoint() {
@@ -396,18 +509,20 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * shouldConnectAtStartUp
         * </p>
-        * 
+        *
         * @return a boolean.
         */
        public static boolean shouldConnectAtStartUp() {
-               return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
+               //FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
+               //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
+               return false;
        }
 
        /**
         * <p>
         * getDefaultFeatureTreeForTextualDescription
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
         */
        public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
@@ -421,7 +536,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getDefaultFeatureTreeForStructuredDescription
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
         */
        public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
@@ -435,7 +550,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setSortRanksHierarchichally
         * </p>
-        * 
+        *
         * @param selection
         *            a boolean.
         */
@@ -447,7 +562,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getSortRanksHierarchichally
         * </p>
-        * 
+        *
         * @return a boolean.
         */
        public static boolean getSortRanksHierarchichally() {
@@ -460,11 +575,18 @@ public class PreferencesUtil implements IPreferenceKeys {
        }
 
        public static Language getGlobalLanguage() {
+
+
                String languageUuidString = getPreferenceStore().getString(
                                GLOBAL_LANGUAGE_UUID);
 
-               if (CdmUtils.isEmpty(languageUuidString)) {
-                       return Language.DEFAULT();
+               if(!CdmStore.isActive()) {
+            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
+            return null;
+        }
+
+               if (CdmUtils.isBlank(languageUuidString)) {
+                       return Language.getDefaultLanguage();
                }
 
                UUID languageUuid = UUID.fromString(languageUuidString);
@@ -473,9 +595,11 @@ public class PreferencesUtil implements IPreferenceKeys {
        }
 
        public static void setGlobalLanguage(Language language) {
-               getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,
-                               language.getUuid().toString());
-               CdmStore.setDefaultLanguage(language);
+           if(language != null) {
+               getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
+               CdmStore.setDefaultLanguage(language);
+           }
+
        }
 
        /**
@@ -512,7 +636,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        private static String getMarkerTypeEditingPreferenceKey(
                        MarkerType markerType) {
-               markerType = (MarkerType) HibernateProxyHelper.deproxy(markerType);
+               markerType = HibernateProxyHelper.deproxy(markerType);
                return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
        }
 
@@ -520,7 +644,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setEditMarkerTypePreference
         * </p>
-        * 
+        *
         * @param input
         *            a {@link org.eclipse.ui.IEditorInput} object.
         * @param markerType
@@ -545,4 +669,238 @@ public class PreferencesUtil implements IPreferenceKeys {
                return configurator;
        }
 
+       /**
+        * This method will write language properties to the config.ini located in the configuration folder
+        * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
+        *
+        * @param setLanguage 0 is for german and 1 for english.
+        * @throws IOException
+        */
+    public void writePropertyToConfigFile(int setLanguage) throws IOException {
+        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
+        //give warning to user if the directory has no write access
+        if(file == null){
+            throw new IOException();
+        }
+        Properties properties = load(file.getAbsolutePath()+"/config.ini");
+        switch(setLanguage){
+        case 0:
+            properties.setProperty("osgi.nl", "de");
+            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
+            break;
+        case 1:
+            properties.setProperty("osgi.nl", "en");
+            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
+            break;
+        default:
+            break;
+        }
+        save(file+"/config.ini", properties);
+    }
+
+    /**
+     * This method loads a property from a given file and returns it.
+     *
+     * @param filename
+     * @return
+     * @throws IOException
+     */
+    private Properties load(String filename) throws IOException {
+        FileInputStream in = new FileInputStream(filename);
+        Properties prop = new Properties();
+        prop.load(in);
+        in.close();
+        return prop;
+    }
+
+    /**
+     * This method saves a property to the specified file.
+     *
+     * @param filename
+     * @param properties
+     * @throws IOException
+     */
+    private void save(String filename, Properties properties) throws IOException{
+        FileOutputStream fos =  new FileOutputStream(filename);
+        properties.store(fos, "");
+        fos.close();
+    }
+
+    /**
+     * Saves a list of P2 Metadata Repositories as string with specified delimiters
+     *
+     * @param p2Repos
+     */
+    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
+        StringBuilder sb = new StringBuilder();
+        for(MetadataRepositoryElement p2Repo : p2Repos) {
+            sb.append(P2_REPOSITORIES_DELIM);
+            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
+                sb.append("-");
+            } else {
+                sb.append(p2Repo.getName());
+            }
+            sb.append(P2_REPOSITORY_FIELDS_DELIM);
+            sb.append(p2Repo.getLocation().toString());
+            sb.append(P2_REPOSITORY_FIELDS_DELIM);
+            sb.append(String.valueOf(p2Repo.isEnabled()));
+        }
+        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
+    }
+
+
+    /**
+     * Retrieves a list of previously saved P2 repositories
+     *
+     * @return
+     */
+    public static List<MetadataRepositoryElement> getP2Repositories() {
+        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
+        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
+        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
+            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
+
+            while(p2ReposPrefST.hasMoreTokens()) {
+                String p2RepoStr = p2ReposPrefST.nextToken();
+                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
+                if(p2ReposStrST.countTokens()==3) {
+                    String nickname = p2ReposStrST.nextToken();
+                    URI uri = null;
+                    try {
+                        uri = new URI(p2ReposStrST.nextToken());
+                    } catch (URISyntaxException e) {
+                        continue;
+                    }
+                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
+                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
+                    mre.setNickname(nickname);
+                    mre.setEnabled(enabled);
+                    p2Repos.add(mre);
+                }
+            }
+        }
+
+        return p2Repos;
+    }
+
+    /**
+     * enables/disables nested composite. <br>
+     *
+     * @param ctrl - Composite to be en-/disabeld
+     * @param enabled - boolean
+     */
+    public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
+        if (ctrl instanceof Composite) {
+            Composite comp = (Composite) ctrl;
+            for (Control c : comp.getChildren()) {
+                recursiveSetEnabled(c, enabled);
+            }
+        } else {
+            ctrl.setEnabled(enabled);
+        }
+    }
+
+    /**
+        * <p>
+        * getSortRanksNaturally
+        * </p>
+        *
+        * @return a boolean.
+        */
+       public static boolean getSortNodesNaturally() {
+               return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY);
+       }
+
+       /**
+        * <p>
+        * setSortRanksNaturally
+        * </p>
+        *
+        * @param selection
+        *            a boolean.
+        */
+       public static void setSortNodesNaturally(boolean selection) {
+               getPreferenceStore().setValue(SORT_NODES_NATURALLY, selection);
+       }
+
+
+       /**
+        * <p>
+        * getSortRanksNaturally
+        * </p>
+        *
+        * @return a boolean.
+        */
+       public static boolean getSortNodesStrictlyAlphabetically() {
+               return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY);
+       }
+
+       /**
+        * <p>
+        * setSortRanksNaturally
+        * </p>
+        *
+        * @param selection
+        *            a boolean.
+        */
+       public static void setSortNodesStrictlyAlphabetically(boolean selection) {
+               getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY, selection);
+       }
+
+       /**
+        * <p>
+        * setStoreNavigatorState
+        * </p>
+        *
+        * @param selection
+        *            a boolean.
+        */
+       public static boolean isStoreNavigatorState() {
+               return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE);
+
+       }
+
+       /**
+        * <p>
+        * setStoreNavigatorState
+        * </p>
+        *
+        * @param selection
+        *            a boolean.
+        */
+       public static void setStoreNavigatorState(boolean selection) {
+               getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE, selection);
+
+       }
+
+    /**
+     * @return
+     */
+    public static boolean isShowUpWidgetIsDisposedMessages() {
+       return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED);
+    }
+    public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
+        getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
+    }
+
+    /**
+     * @return
+     */
+    public static boolean isShowIdInVocabularyInChecklistEditor() {
+       return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY);
+    }
+    public static void setShowIdInVocabularyInChecklistEditor(boolean selection) {
+        getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY, selection);
+    }
+
+    /**
+     * @return
+     */
+    public static boolean isShowRankInChecklistEditor() {
+        return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SHOW_RANK);
+    }
+    public static void setShowRankInChecklistEditor(boolean selection) {
+        getPreferenceStore().setValue(CHECKLIST_SHOW_RANK, selection);
+    }
+
 }