skip the dialog for setting the default nomenclatural code. The default is the botani...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
index 9a8c1668f7bc4587416447e2c5753c1b6371b1c2..0d96ea053a24f394643add22c6cee84d021ae262 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * 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.
  */
@@ -30,6 +30,7 @@ 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;
@@ -48,7 +49,7 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
  * <p>
  * PreferencesUtil class.
  * </p>
- * 
+ *
  * @author p.ciardelli
  * @author n.hoffmann
  * @created 05.12.2008
@@ -57,7 +58,7 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 public class PreferencesUtil implements IPreferenceKeys {
 
        /**
-        * 
+        *
         */
        public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
 
@@ -65,7 +66,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getPreferenceStore
         * </p>
-        * 
+        *
         * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
         */
        public static IPreferenceStore getPreferenceStore() {
@@ -76,7 +77,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setPreferredNomenclaturalCode
         * </p>
-        * 
+        *
         * @param preferredCode
         *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
         *            object.
@@ -91,7 +92,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getPreferredNomenclaturalCode
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
         */
        public static NomenclaturalCode getPreferredNomenclaturalCode() {
@@ -109,7 +110,7 @@ public class PreferencesUtil implements IPreferenceKeys {
        /**
         * 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.
@@ -138,7 +139,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 +159,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Helper method to create the preference property for a match field.
-        * 
+        *
         * @param className
         * @param fieldName
         * @return
@@ -170,7 +171,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 +184,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getDateFormatPattern
         * </p>
-        * 
+        *
         * @return a {@link java.lang.String} object.
         */
        public static String getDateFormatPattern() {
@@ -196,7 +197,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * addTermToPreferredTerms
         * </p>
-        * 
+        *
         * @param term
         *            a T object.
         * @param <T>
@@ -215,7 +216,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Construct a unique key using the CdmBase object's uuid
-        * 
+        *
         * @param cdmBase
         * @return
         */
@@ -232,7 +233,26 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Construct a unique key using the CdmBase object's uuid
-        * 
+        *
+        * @param cdmBase
+        * @return
+        */
+       public static String getPreferenceKey(ISimpleTerm simpleTerm) {
+               simpleTerm = (ISimpleTerm) HibernateProxyHelper.deproxy(simpleTerm);
+               String key = simpleTerm.getClass().getName().concat(".")
+                               .concat(simpleTerm.getUuid().toString());
+               if (key.contains("javassist")) {
+                       StoreUtil.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
         */
@@ -249,7 +269,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() {
@@ -269,7 +289,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * create new preferences, setting all search options to true
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
         *         object.
@@ -292,7 +312,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 +323,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
        /**
         * Store search preferences
-        * 
+        *
         * @param configurator
         *            a
         *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
@@ -325,7 +345,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * firePreferencesChanged
         * </p>
-        * 
+        *
         * @param clazz
         *            a {@link java.lang.Class} object.
         */
@@ -342,8 +362,9 @@ 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");
@@ -357,13 +378,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) {
+                       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,7 +402,7 @@ 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.");*/
                }
        }
 
@@ -385,7 +410,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getMapServiceAccessPoint
         * </p>
-        * 
+        *
         * @return a {@link java.lang.String} object.
         */
        public static String getMapServiceAccessPoint() {
@@ -396,18 +421,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 +448,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 +462,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setSortRanksHierarchichally
         * </p>
-        * 
+        *
         * @param selection
         *            a boolean.
         */
@@ -447,7 +474,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * getSortRanksHierarchichally
         * </p>
-        * 
+        *
         * @return a boolean.
         */
        public static boolean getSortRanksHierarchichally() {
@@ -520,7 +547,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         * <p>
         * setEditMarkerTypePreference
         * </p>
-        * 
+        *
         * @param input
         *            a {@link org.eclipse.ui.IEditorInput} object.
         * @param markerType