2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.preference
;
13 import java
.io
.FileInputStream
;
14 import java
.io
.FileOutputStream
;
15 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.Collections
;
21 import java
.util
.HashMap
;
22 import java
.util
.List
;
24 import java
.util
.Properties
;
25 import java
.util
.StringTokenizer
;
26 import java
.util
.UUID
;
28 import org
.apache
.commons
.lang
.StringUtils
;
29 import org
.apache
.log4j
.Logger
;
30 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
31 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
32 import org
.eclipse
.equinox
.internal
.p2
.ui
.model
.MetadataRepositoryElement
;
33 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
34 import org
.eclipse
.jface
.window
.Window
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Control
;
37 import org
.eclipse
.swt
.widgets
.Shell
;
38 import org
.eclipse
.ui
.PlatformUI
;
39 import org
.osgi
.service
.prefs
.BackingStoreException
;
40 import org
.osgi
.service
.prefs
.Preferences
;
42 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
43 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeConfigurator
;
44 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
45 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
46 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindTaxaAndNamesConfiguratorImpl
;
47 import eu
.etaxonomy
.cdm
.api
.service
.config
.IFindTaxaAndNamesConfigurator
;
48 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
49 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
50 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
51 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
53 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
54 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
55 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
56 import eu
.etaxonomy
.cdm
.model
.metadata
.IPreferencePredicate
;
57 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
58 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
59 import eu
.etaxonomy
.cdm
.model
.metadata
.TermDisplayEnum
;
60 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
61 import eu
.etaxonomy
.cdm
.model
.term
.FeatureTree
;
62 import eu
.etaxonomy
.cdm
.model
.term
.IDefinedTerm
;
63 import eu
.etaxonomy
.cdm
.model
.term
.ISimpleTerm
;
64 import eu
.etaxonomy
.cdm
.model
.term
.TermBase
;
65 import eu
.etaxonomy
.cdm
.strategy
.match
.DefaultMatchStrategy
;
66 import eu
.etaxonomy
.cdm
.strategy
.match
.FieldMatcher
;
67 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategy
;
68 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchException
;
69 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
70 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
71 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
72 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
73 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
74 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
75 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
76 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.DefaultLanguageDialog
;
80 * PreferencesUtil class.
87 public class PreferencesUtil
implements IPreferenceKeys
{
88 private final static String EDITOR_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor";
90 public static final String PREFERRED_TERMS_CHANGE
= "preferred_terms";
92 public static final String P2_REPOSITORIES_DELIM
= ",";
93 public static final String P2_REPOSITORY_FIELDS_DELIM
= ";";
94 public static final String SUBJECT_DELIM
= "/";
95 private final static Logger logger
= Logger
.getLogger(PreferencesUtil
.class);
97 public static IPreferenceStore
getPreferenceStore() {
98 return TaxeditorStorePlugin
.getDefault().getPreferenceStore();
101 public static String
[] extractSubjectParts(String subject
){
102 String
[] result
= subject
.split("/");
106 public static IEclipsePreferences
getEditorPreferences(){
107 return ConfigurationScope
.INSTANCE
.getNode(EDITOR_PREFERENCES_NODE
);
110 public static String
getPreferenceValue(PrefKey prefKey
){
112 if(getEditorPreferences().nodeExists(prefKey
.getPredicate())){
113 Preferences predicateNode
= getEditorPreferences().node(prefKey
.getPredicate());
114 String
[] splittedSubject
= extractSubjectParts(prefKey
.getSubject());
115 String value
= predicateNode
.get(splittedSubject
[splittedSubject
.length
-1], PreferencePredicate
.getByKey(prefKey
.getPredicate()).getDefaultValue() != null? PreferencePredicate
.getByKey(prefKey
.getPredicate()).getDefaultValue().toString(): "");
116 int index
= splittedSubject
.length
-2;
117 while (value
!= null && index
>= 0){
118 value
= predicateNode
.get(splittedSubject
[index
], prefKey
.getPredicate());
124 } catch (BackingStoreException e
) {
125 // TODO Auto-generated catch block
131 public static List
<CdmPreference
> getPreference(PreferencePredicate prefPredicate
){
133 List
<CdmPreference
> prefs
= new ArrayList();
135 PreferenceSubject subject
;
136 if(getEditorPreferences().nodeExists(prefPredicate
.getKey())){
137 Preferences predicateNode
= getEditorPreferences().node(prefPredicate
.getKey());
138 for (String childName
: predicateNode
.childrenNames()){
139 Preferences child
= predicateNode
.node(childName
);
140 String subjectString
= "";
141 subjectString
= createSubjectStringForChildNodes(childName
, child
);
142 String value
= child
.get(subjectString
, "");
143 subject
= PreferenceSubject
.NewInstance(subjectString
);
144 pref
= CdmPreference
.NewInstance(subject
, prefPredicate
, value
);
150 } catch (BackingStoreException e
) {
151 // TODO Auto-generated catch block
161 private static String
createSubjectStringForChildNodes(String subject
, Preferences parent
) {
163 for (String childName
: parent
.childrenNames()){
164 subject
= childName
+SUBJECT_DELIM
+subject
;
165 Preferences child
= parent
.node(childName
);
166 createSubjectStringForChildNodes(subject
, child
);
168 } catch (BackingStoreException e
) {
169 // TODO Auto-generated catch block
176 private static String
prefKey(String name
) {
177 return name
+ "_"+ ((CdmRemoteSource
)CdmStore
.getActiveCdmSource()).toString();
180 public static String
prefOverrideKey(String name
) {
181 return name
+ "_OVERRIDE_";
184 public static void setStringValue(String name
, String value
) {
186 getPreferenceStore().setValue(prefKey(name
), value
);
188 getPreferenceStore().setToDefault(name
);
192 public static void setIntValue(String name
, int value
) {
193 getPreferenceStore().setValue(prefKey(name
), value
);
196 public static void setBooleanValue(String name
, boolean value
) {
197 getPreferenceStore().setValue(prefKey(name
), value
);
200 public static void setDoubleValue(String name
, double value
) {
201 getPreferenceStore().setValue(prefKey(name
), value
);
204 public static void setFloatValue(String name
, float value
) {
205 getPreferenceStore().setValue(prefKey(name
), value
);
208 public static void setLongValue(String name
, long value
) {
209 getPreferenceStore().setValue(prefKey(name
), value
);
212 public static String
getStringValue(String name
, boolean local
) {
214 CdmPreference pref
= getDBPreferenceValue(name
);
215 String prefValue
= null;
216 String overrideKey
= createPreferenceString(createOverridePreferenceString(name
));
217 boolean override
= getPreferenceStore().getBoolean(overrideKey
);
219 if (local
|| pref
== null || (pref
!= null && pref
.isAllowOverride() && override
)){
220 String dbSpecific
= prefKey(name
);
221 if (getPreferenceStore().contains(dbSpecific
)){
222 prefValue
= getPreferenceStore().getString(dbSpecific
);
224 prefValue
= getPreferenceStore().
227 }else if (pref
!= null){
228 prefValue
= pref
.getValue();
234 public static String
getStringValue(String name
){
235 return getStringValue(name
, false);
238 private static CdmPreference
getDBPreferenceValue(String name
) {
239 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
240 CdmPreference pref
= null;
242 pref
= cache
.get(name
);
244 //get default value for Predicate
245 IPreferencePredicate pred
= PreferencePredicate
.getByKey(name
);
247 if (pred
.getDefaultValue() != null){
248 pref
= CdmPreference
.NewTaxEditorInstance(pred
, pred
.getDefaultValue().toString());
250 pref
= CdmPreference
.NewTaxEditorInstance(pred
, null);
252 pref
.setAllowOverride(true);
258 public static int getIntValue(String name
, boolean local
) {
259 CdmPreference pref
= getDBPreferenceValue(name
);
260 String prefValue
= null;
262 prefValue
= pref
.getValue();
264 Integer result
= null;
266 result
= Integer
.parseInt(prefValue
);
267 }catch(NumberFormatException e
){
268 logger
.debug("Preference value of " + name
+ " is not a number");
271 String overrideKey
= createPreferenceString(createOverridePreferenceString(name
));
272 boolean override
= true;
273 if (getPreferenceStore().contains(overrideKey
)){
274 override
= getPreferenceStore().getBoolean(overrideKey
);
276 if (local
|| pref
== null || (pref
!= null && pref
.isAllowOverride() && override
)){
277 String dbSpecific
= prefKey(name
);
278 if (getPreferenceStore().contains(dbSpecific
)){
279 result
= getPreferenceStore().getInt(dbSpecific
);
281 result
= getPreferenceStore().
289 public static boolean getBooleanValue(String name
) {
290 Boolean result
= getBooleanValue(name
, false);
299 public static Boolean
getBooleanValue(String name
, boolean local
) {
300 if (CdmStore
.isActive()){
301 CdmPreference pref
= getDBPreferenceValue(name
);
303 String overrideKey
= createPreferenceString(createOverridePreferenceString(name
));
304 boolean override
= getPreferenceStore().getBoolean(overrideKey
);
306 if (local
|| pref
== null || (pref
!= null && pref
.isAllowOverride() && override
)){
307 String dbSpecific
= prefKey(name
);
308 if (getPreferenceStore().contains(dbSpecific
)){
309 return getPreferenceStore().getBoolean(dbSpecific
);
314 return Boolean
.valueOf(pref
.getValue());
318 return getPreferenceStore().getBoolean(name
);
323 public static double getDoubleValue(String name
) {
324 CdmPreference pref
= getDBPreferenceValue(name
);
325 String prefValue
= null;
327 prefValue
= pref
.getValue();
329 Double result
= null;
331 result
= Double
.parseDouble(prefValue
);
332 }catch(NumberFormatException e
){
333 logger
.debug("Preference value of " + name
+ " is not a number");
336 String dbSpecific
= prefKey(name
);
337 if (getPreferenceStore().contains(dbSpecific
)){
338 result
= getPreferenceStore().getDouble(dbSpecific
);
340 result
= getPreferenceStore().
348 public static float getFloatValue(String name
, boolean local
) {
349 CdmPreference pref
= getDBPreferenceValue(name
);
350 String prefValue
= null;
352 prefValue
= pref
.getValue();
356 result
= Float
.parseFloat(prefValue
);
357 }catch(NumberFormatException e
){
358 logger
.debug("Preference value of " + name
+ " is not a number");
360 String overrideKey
= createPreferenceString(createOverridePreferenceString(name
));
361 boolean override
= true;
362 if (getPreferenceStore().contains(overrideKey
)){
363 override
= getPreferenceStore().getBoolean(overrideKey
);
365 if (local
|| pref
== null || (pref
!= null && pref
.isAllowOverride() && override
)){
366 String dbSpecific
= prefKey(name
);
367 if (getPreferenceStore().contains(dbSpecific
)){
368 result
= getPreferenceStore().getFloat(dbSpecific
);
370 result
= getPreferenceStore().
378 public static long getLongValue(String name
) {
379 CdmPreference pref
= getDBPreferenceValue(name
);
380 String prefValue
= null;
382 prefValue
= pref
.getValue();
386 result
= Long
.parseLong(prefValue
);
387 }catch(NumberFormatException e
){
388 logger
.debug("Preference value of " + name
+ " is not a number");
391 String dbSpecific
= prefKey(name
);
392 if (getPreferenceStore().contains(dbSpecific
)){
393 result
= getPreferenceStore().getLong(dbSpecific
);
395 result
= getPreferenceStore().
402 public static CdmPreference
setPreferredNomenclaturalCode(
403 String preferenceValue
, boolean local
) {
405 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
409 ICdmRepository controller
;
410 controller
= CdmStore
.getCurrentApplicationConfiguration();
411 if (controller
== null){
416 key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
417 }catch (Exception e
){
418 System
.out
.println(e
.getStackTrace());
420 CdmPreference preference
= null;
422 if (preferenceValue
== null){
423 preference
= controller
.getPreferenceService().find(key
);
424 if (preference
== null){
427 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
428 preference
.getValue());
433 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
, preferenceValue
);
434 controller
.getPreferenceService().set(preference
);
444 public static void setPreferredNomenclaturalCode(
445 CdmPreference preference
) {
447 ICdmRepository controller
;
448 controller
= CdmStore
.getCurrentApplicationConfiguration();
449 if (controller
== null){
454 key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
455 }catch (Exception e
){
456 System
.out
.println(e
.getStackTrace());
459 controller
.getPreferenceService().set(preference
);
463 public static NomenclaturalCode
getPreferredNomenclaturalCode() {
465 CdmPreference pref
= getPreferenceFromDB(PreferencePredicate
.NomenclaturalCode
);
468 String preferredCode
;
469 if(pref
== null || (pref
.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate
.NomenclaturalCode
.getKey())))){
470 preferredCode
= getStringValue(
471 PreferencePredicate
.NomenclaturalCode
.getKey(), true);
474 preferredCode
= pref
.getValue();
476 if (StringUtils
.isBlank(preferredCode
)){
477 preferredCode
= getPreferenceKey((NomenclaturalCode
)PreferencePredicate
.NomenclaturalCode
.getDefaultValue());
480 return getPreferredNomenclaturalCode(preferredCode
);
484 public static NomenclaturalCode
getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode
) {
486 for (NomenclaturalCode code
: NomenclaturalCodeHelper
.getAllCodes()) {
487 if (getPreferenceKey(code
).equals(preferenceKeyNomenclaturalCode
)) {
494 public static boolean isShowTaxonAssociations(){
495 boolean result
= getBooleanValue(PreferencePredicate
.ShowTaxonAssociations
.getKey());
499 public static boolean isShowLifeForm(){
500 boolean result
= getBooleanValue(PreferencePredicate
.ShowLifeForm
.getKey());
504 public static boolean isDeterminationOnlyForFieldUnits(){
505 boolean result
= getBooleanValue(PreferencePredicate
.DeterminationOnlyForFieldUnits
.getKey());
509 public static boolean isCollectingAreaInGeneralSection(){
510 boolean result
= getBooleanValue(PreferencePredicate
.ShowCollectingAreasInGeneralSection
.getKey());
514 public static CdmPreference
getPreferenceFromDB(IPreferencePredicate predicate
){
515 ICdmRepository controller
;
516 CdmPreference pref
= null;
519 if(CdmStore
.isActive()){
520 controller
= CdmStore
.getCurrentApplicationConfiguration();
521 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), predicate
);
522 pref
= controller
.getPreferenceService().find(key
);
532 public static List
<CdmPreference
> getPreferencesFromDB(IPreferencePredicate predicate
){
533 ICdmRepository controller
;
534 List
<CdmPreference
> prefs
= null;
537 if(CdmStore
.isActive()){
538 controller
= CdmStore
.getCurrentApplicationConfiguration();
539 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), predicate
);
540 prefs
= controller
.getPreferenceService().list(predicate
);
550 public static void setPreferencesToDB(CdmPreference preference
, boolean setDefault
){
551 ICdmRepository controller
;
553 if(CdmStore
.isActive()){
554 controller
= CdmStore
.getCurrentApplicationConfiguration();
557 controller
.getPreferenceService().remove(preference
.getKey());
559 controller
.getPreferenceService().set(preference
);
570 public static CdmPreference
getPreferenceFromDB(PrefKey key
){
571 ICdmRepository controller
;
572 CdmPreference pref
= null;
575 if(CdmStore
.isActive()){
576 controller
= CdmStore
.getCurrentApplicationConfiguration();
577 pref
= controller
.getPreferenceService().find(key
);
587 public static void setPreferenceToDB(CdmPreference preference
){
588 ICdmRepository controller
;
590 if(CdmStore
.isActive()){
591 controller
= CdmStore
.getCurrentApplicationConfiguration();
592 if (preference
.getValue() == null && preference
.isAllowOverride()){
593 controller
.getPreferenceService().remove(preference
.getKey());
595 controller
.getPreferenceService().set(preference
);
597 CdmPreferenceCache
.instance().put(preference
);
605 public static String
getPreferredDefaultLangugae(){
606 String preferredLanguage
= getStringValue(DEFAULT_LANGUAGE_EDITOR
);
607 if(StringUtils
.isNotEmpty(preferredLanguage
) && StringUtils
.isNotBlank(preferredLanguage
)){
608 return preferredLanguage
;
613 public static boolean isShowMediaPreview(){
614 boolean isShowMediaPreview
= getBooleanValue(SHOW_MEDIA_PREVIEW
);
615 return isShowMediaPreview
;
619 * Get the match strategy for the given class that was stored in preferences
620 * or the default strategy if it was not stored in preferences
623 * a {@link java.lang.Class} object.
624 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
626 public static IMatchStrategy
getMatchStrategy(Class
<?
> clazz
) {
627 String className
= clazz
.getName();
628 if (getBooleanValue(MATCH_STRATEGY_PREFIX
+ className
)) {
629 IMatchStrategy matchStrategy
= getDefaultMatchStrategy(clazz
);
631 //TODO CacheMatchers (or multiple field matchers in future) are missing here
632 for (FieldMatcher fieldMatcher
: matchStrategy
.getMatching().getFieldMatchers(false)) {
633 String fieldName
= fieldMatcher
.getPropertyName();
634 String matchModeName
= getStringValue(
635 getMatchStrategyFieldName(className
, fieldName
));
636 MatchMode matchMode
= MatchMode
.valueOf(matchModeName
);
638 matchStrategy
.setMatchMode(fieldName
, matchMode
);
639 } catch (MatchException e
) {
640 MessagingUtils
.error(PreferencesUtil
.class, e
);
641 throw new RuntimeException(e
);
645 return matchStrategy
;
647 return getDefaultMatchStrategy(clazz
);
651 * Stores a matchStrategy into the preference store.
653 * @param matchStrategy
654 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
657 public static void setMatchStrategy(IMatchStrategy matchStrategy
) {
658 String className
= "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
659 setBooleanValue(MATCH_STRATEGY_PREFIX
+ className
, true);
661 List
<FieldMatcher
> fieldMatchers
= matchStrategy
.getMatching().getFieldMatchers(false);
663 for (FieldMatcher fieldMatcher
: fieldMatchers
) {
664 String fieldName
= fieldMatcher
.getPropertyName();
666 getMatchStrategyFieldName(className
, fieldName
),
667 fieldMatcher
.getMatchMode().name());
672 * Helper method to create the preference property for a match field.
678 private static String
getMatchStrategyFieldName(String className
,
680 return MATCH_STRATEGY_PREFIX
+ className
+ "." + fieldName
;
684 * Returns the default match strategy for a given class.
687 * a {@link java.lang.Class} object.
688 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
690 public static IMatchStrategy
getDefaultMatchStrategy(Class clazz
) {
691 return DefaultMatchStrategy
.NewInstance(clazz
);
694 public static String
getDateFormatPattern() {
695 // TODO make this configurable in properties
696 String pattern
= "Y-M-d H:m";
700 public static <T
extends TermBase
> void addTermToPreferredTerms(T term
) {
702 // VocabularyEnum vocabulary =
703 // VocabularyEnum.getVocabularyEnum(term.getClass());
705 // getPreferenceStore().setValue(getPreferenceKey(term),
706 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
708 // firePreferencesChanged(term.getClass());
712 * Construct a unique key using the CdmBase object's uuid
717 private static String
getPreferenceKey(ICdmBase cdmBase
) {
718 cdmBase
= HibernateProxyHelper
.deproxy(cdmBase
);
720 String key
= cdmBase
.getClass().getName().concat(".")
721 .concat(cdmBase
.getUuid().toString());
722 if (key
.contains("javassist")) {
723 MessagingUtils
.info("proxy");
729 * Construct a unique key using the CdmBase object's uuid
734 public static String
getPreferenceKey(ISimpleTerm simpleTerm
) {
735 simpleTerm
= HibernateProxyHelper
.deproxy(simpleTerm
);
736 String key
= simpleTerm
.getClass().getName().concat(".")
737 .concat(simpleTerm
.getUuid().toString());
738 if (key
.contains("javassist")) {
739 MessagingUtils
.warn(PreferencesUtil
.class,
740 "Trying to persist a preference based on a proxy class.");
748 * Construct a unique key using the CdmBase object's uuid
753 public static String
getPreferenceKey(IDefinedTerm definedTerm
) {
754 definedTerm
= HibernateProxyHelper
.deproxy(definedTerm
);
755 String key
= definedTerm
.getClass().getName().concat(".")
756 .concat(definedTerm
.getUuid().toString());
757 if (key
.contains("javassist")) {
758 MessagingUtils
.warn(PreferencesUtil
.class,
759 "Trying to persist a preference based on a proxy class.");
765 * Retrieves search preferences from the preference store
767 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
769 public static IFindTaxaAndNamesConfigurator
getSearchConfigurator() {
770 IFindTaxaAndNamesConfigurator configurator
= initializeSearchConfigurator();
772 configurator
.setDoTaxa(getBooleanValue(
773 TAXON_SERVICE_CONFIGURATOR_TAXA
));
774 configurator
.setDoSynonyms(getBooleanValue(
775 TAXON_SERVICE_CONFIGURATOR_SYNONYMS
));
776 configurator
.setDoNamesWithoutTaxa(getBooleanValue(
777 TAXON_SERVICE_CONFIGURATOR_NAMES
));
778 configurator
.setDoTaxaByCommonNames(getBooleanValue(
779 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
));
780 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
786 * create new preferences, setting all search options to true
789 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
792 public static IFindTaxaAndNamesConfigurator
initializeSearchConfigurator() {
793 IFindTaxaAndNamesConfigurator configurator
= FindTaxaAndNamesConfiguratorImpl
.NewInstance();
795 configurator
.setDoTaxa(true);
796 configurator
.setDoSynonyms(true);
797 configurator
.setDoNamesWithoutTaxa(true);
798 configurator
.setDoTaxaByCommonNames(true);
800 configurator
.setTaxonPropertyPath(Arrays
.asList("$", "titleCache",
801 "name", "name.$", "relationsFromThisTaxon.$"));
803 configurator
.setSynonymPropertyPath(Arrays
.asList("$", "titleCache",
804 "name", "name.$", "synonyms.relatedTo.*"));
807 // match mode is a simple like, actually all other match modes are kind
810 .setMatchMode(eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
.ANYWHERE
);
811 // we set page number and size here as this should always be unlimited
812 configurator
.setPageNumber(0);
813 // TODO currently limit results to 10000
814 configurator
.setPageSize(10000);
815 //setSearchConfigurator(configurator) ;
820 * Store search preferences
822 * @param configurator
824 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
827 public static void setSearchConfigurator(
828 IFindTaxaAndNamesConfigurator configurator
) {
829 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA
,
830 configurator
.isDoTaxa());
831 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
832 configurator
.isDoSynonyms());
833 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES
,
834 configurator
.isDoNamesWithoutTaxa());
835 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
,
836 configurator
.isDoTaxaByCommonNames());
839 public static void firePreferencesChanged(Class clazz
) {
840 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE
,
844 public static String
createPreferenceString(String property
){
845 return prefKey(property
);
848 public static String
createOverridePreferenceString(String property
){
849 return prefOverrideKey(property
);
854 * Set default values for preferences
856 public static void setDefaults() {
857 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
858 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
860 getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT
),
861 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
862 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
863 getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP
), false);
864 getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT
),
865 "http://www.biodiversitylibrary.org/openurl");
866 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH
), "1000");
867 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT
), "1000");
868 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
869 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
, true);
870 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_NAMES
, true);
871 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
, true);
873 //Distribution Editor:
874 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
875 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
876 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
880 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.NameDetailsView
.getKey()), new NameDetailsConfigurator(false).toString());
882 //Navigator preferences
883 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.TaxonNodeOrder
.getKey()), NavigatorOrderEnum
.RankAndNameOrder
.getKey());
885 //getPreferenceStore().setDefault(createPreferenceString(Prefe), true);
887 getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION
), false);
889 getPreferenceStore().setDefault(createPreferenceString(SHOW_MEDIA_PREVIEW
), false);
890 //override db preferences
891 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey())), false);
892 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.ShowSpecimen
.getKey())), true);
893 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.NameDetailsView
.getKey())), false);
894 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.DistributionEditorActivated
.getKey())), true);
895 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.AvailableDistributionStatus
.getKey())), true);
896 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey())), true);
897 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey())), true);
898 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate
.CommonNameAreaVocabularies
.getKey())), false);
899 getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES
), false);
900 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.ShowTaxonNodeWizard
.getKey()), Boolean
.valueOf(PreferencePredicate
.ShowTaxonNodeWizard
.getDefaultValue().toString()));
901 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.ShowNamespaceInSource
.getKey()), Boolean
.valueOf(PreferencePredicate
.ShowNamespaceInSource
.getDefaultValue().toString()));
902 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.ShowIdInSource
.getKey()), Boolean
.valueOf(PreferencePredicate
.ShowIdInSource
.getDefaultValue().toString()));
903 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.DisableMultiClassification
.getKey()), Boolean
.valueOf(PreferencePredicate
.DisableMultiClassification
.getDefaultValue().toString()));
904 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.ShowImportExportMenu
.getKey()), Boolean
.valueOf(PreferencePredicate
.ShowImportExportMenu
.getDefaultValue().toString()));
905 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate
.ShowSpecimen
.getKey()), Boolean
.valueOf(PreferencePredicate
.ShowSpecimen
.getDefaultValue().toString()));
909 public static void checkNomenclaturalCode() {
910 // First time Editor is opened, no nomenclatural code has been set
911 if (PreferencesUtil
.getPreferredNomenclaturalCode() == null) {
912 PreferencesUtil
.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode
.ICNAFP
), true);
918 public static void setNomenclaturalCodePreferences(){
919 ICdmRepository controller
;
920 controller
= CdmStore
.getCurrentApplicationConfiguration();
921 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
922 CdmPreference preference
= null;
923 if (controller
== null){
926 preference
= controller
.getPreferenceService().find(key
);
927 if (preference
== null){
930 // setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
932 int index
= StringUtils
.lastIndexOf(preference
.getValue(), ".");
933 UUID uuid
= UUID
.fromString(preference
.getValue().substring(index
+1, preference
.getValue().length()));
934 NomenclaturalCode preferredCode
= NomenclaturalCode
.getByUuid(uuid
);
936 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
937 getPreferenceKey(preferredCode
));
941 public static void checkDefaultLanguage(){
942 if(PreferencesUtil
.getPreferredDefaultLangugae() == null){
943 Shell shell
= AbstractUtility
.getShell();
944 int open
= new DefaultLanguageDialog(shell
).open();
945 if(open
== Window
.OK
){
946 PlatformUI
.getWorkbench().restart();
949 //TODO:In case of a reinstall, the config.ini will be overwritten
950 // here you create config.ini with the stored key from preferences
954 public static String
getMapServiceAccessPoint() {
955 return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT
);
958 public static boolean shouldConnectAtStartUp() {
959 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
960 //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
964 public static FeatureTree
getDefaultFeatureTreeForTextualDescription() {
965 String uuidString
= getStringValue(
966 FEATURE_TREE_DEFAULT_TEXT
);
967 if (StringUtils
.isBlank(uuidString
)) {
970 FeatureTree tree
= CdmStore
.getService(
971 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
972 if (tree
.getId() == 0) {
978 public static FeatureTree
getDefaultFeatureTreeForStructuredDescription() {
979 String uuidString
= getStringValue(
980 FEATURE_TREE_DEFAULT_STRUCTURE
);
981 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
982 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
985 public static void setSortRanksHierarchichally(boolean selection
) {
986 setBooleanValue(SORT_RANKS_HIERARCHICHALLY
, selection
);
989 public static boolean getSortRanksHierarchichally() {
990 return getBooleanValue(SORT_RANKS_HIERARCHICHALLY
);
993 public static boolean isMultilanguageTextEditingCapability() {
994 return getBooleanValue(
995 MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
998 public static Language
getGlobalLanguage() {
1001 String languageUuidString
= getStringValue(
1002 GLOBAL_LANGUAGE_UUID
);
1004 if(!CdmStore
.isActive()) {
1005 MessagingUtils
.noDataSourceWarningDialog(languageUuidString
);
1009 if (CdmUtils
.isBlank(languageUuidString
)) {
1010 return Language
.getDefaultLanguage();
1013 UUID languageUuid
= UUID
.fromString(languageUuidString
);
1014 return (Language
) CdmStore
.getService(ITermService
.class).load(
1018 public static void setGlobalLanguage(Language language
) {
1019 if(language
!= null) {
1020 setStringValue(GLOBAL_LANGUAGE_UUID
,language
.getUuid().toString());
1021 CdmStore
.setDefaultLanguage(language
);
1026 public static Map
<MarkerType
, Boolean
> getEditMarkerTypePreferences() {
1027 List
<MarkerType
> markerTypes
= CdmStore
.getTermManager()
1028 .getPreferredTerms(MarkerType
.class);
1030 Map
<MarkerType
, Boolean
> result
= new HashMap
<MarkerType
, Boolean
>();
1032 for (MarkerType markerType
: markerTypes
) {
1033 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
1034 Boolean value
= getBooleanValue(name
);
1036 result
.put(markerType
, value
);
1042 public static void setEditMarkerTypePreferences(
1043 Map
<MarkerType
, Boolean
> markerTypeEditingMap
) {
1044 for (MarkerType markerType
: markerTypeEditingMap
.keySet()) {
1045 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
1046 setBooleanValue(name
,
1047 markerTypeEditingMap
.get(markerType
));
1052 private static String
getMarkerTypeEditingPreferenceKey(
1053 MarkerType markerType
) {
1054 markerType
= HibernateProxyHelper
.deproxy(markerType
);
1055 return markerType
.getClass().getName() + EDIT_MARKER_TYPE_PREFIX
;
1058 public static void setEditMarkerTypePreference(MarkerType markerType
,
1061 getMarkerTypeEditingPreferenceKey(markerType
), edit
);
1064 public static DerivedUnitFacadeConfigurator
getDerivedUnitConfigurator() {
1065 DerivedUnitFacadeConfigurator configurator
= DerivedUnitFacadeConfigurator
1067 configurator
.setMoveDerivedUnitMediaToGallery(true);
1068 configurator
.setMoveFieldObjectMediaToGallery(true);
1069 return configurator
;
1073 * This method will write language properties to the config.ini located in the configuration folder
1074 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
1076 * @param setLanguage 0 is for german and 1 for english.
1077 * @throws IOException
1079 public void writePropertyToConfigFile(int setLanguage
) throws IOException
{
1080 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
1081 //give warning to user if the directory has no write access
1083 throw new IOException();
1085 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
1086 switch(setLanguage
){
1088 properties
.setProperty("osgi.nl", "de");
1089 setStringValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
1092 properties
.setProperty("osgi.nl", "en");
1093 setStringValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
1098 save(file
+"/config.ini", properties
);
1102 * This method loads a property from a given file and returns it.
1106 * @throws IOException
1108 private Properties
load(String filename
) throws IOException
{
1109 FileInputStream in
= new FileInputStream(filename
);
1110 Properties prop
= new Properties();
1117 * This method saves a property to the specified file.
1121 * @throws IOException
1123 private void save(String filename
, Properties properties
) throws IOException
{
1124 FileOutputStream fos
= new FileOutputStream(filename
);
1125 properties
.store(fos
, "");
1130 * Saves a list of P2 Metadata Repositories as string with specified delimiters
1134 public static void setP2Repositories(List
<MetadataRepositoryElement
> p2Repos
) {
1135 StringBuilder sb
= new StringBuilder();
1136 for(MetadataRepositoryElement p2Repo
: p2Repos
) {
1137 sb
.append(P2_REPOSITORIES_DELIM
);
1138 if(p2Repo
.getName() == null || p2Repo
.getName().isEmpty()) {
1141 sb
.append(p2Repo
.getName());
1143 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
1144 sb
.append(p2Repo
.getLocation().toString());
1145 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
1146 sb
.append(String
.valueOf(p2Repo
.isEnabled()));
1148 getPreferenceStore().setValue(P2_REPOSITORY_LIST
, sb
.toString());
1153 * Retrieves a list of previously saved P2 repositories
1157 public static List
<MetadataRepositoryElement
> getP2Repositories() {
1158 List
<MetadataRepositoryElement
> p2Repos
= new ArrayList
<MetadataRepositoryElement
>();
1159 String p2ReposPref
= getStringValue(P2_REPOSITORY_LIST
);
1160 if(p2ReposPref
!= null && !p2ReposPref
.isEmpty()) {
1161 StringTokenizer p2ReposPrefST
= new StringTokenizer(p2ReposPref
,P2_REPOSITORIES_DELIM
);
1163 while(p2ReposPrefST
.hasMoreTokens()) {
1164 String p2RepoStr
= p2ReposPrefST
.nextToken();
1165 StringTokenizer p2ReposStrST
= new StringTokenizer(p2RepoStr
,P2_REPOSITORY_FIELDS_DELIM
);
1166 if(p2ReposStrST
.countTokens()==3) {
1167 String nickname
= p2ReposStrST
.nextToken();
1170 uri
= new URI(p2ReposStrST
.nextToken());
1171 } catch (URISyntaxException e
) {
1174 boolean enabled
= Boolean
.parseBoolean(p2ReposStrST
.nextToken());
1175 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, uri
, true);
1176 mre
.setNickname(nickname
);
1177 mre
.setEnabled(enabled
);
1187 * enables/disables nested composite. <br>
1189 * @param ctrl - Composite to be en-/disabeld
1190 * @param enabled - boolean
1192 public static void recursiveSetEnabled(Control ctrl
, boolean enabled
) {
1193 if (ctrl
instanceof Composite
) {
1194 Composite comp
= (Composite
) ctrl
;
1195 for (Control c
: comp
.getChildren()) {
1196 recursiveSetEnabled(c
, enabled
);
1199 ctrl
.setEnabled(enabled
);
1203 public static void setSortNodes(NavigatorOrderEnum nodesOrder
) {
1204 setStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey(), nodesOrder
.key
);
1208 public static NavigatorOrderEnum
getSortNodes() {
1209 return NavigatorOrderEnum
.valueOf(getStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey()));
1213 public static boolean isNodesSortedNaturally() {
1214 NavigatorOrderEnum value
= NavigatorOrderEnum
.valueOf(getStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey()));
1215 return value
.equals(NavigatorOrderEnum
.NaturalOrder
);
1219 public static boolean isNodesSortedByName() {
1220 NavigatorOrderEnum value
= NavigatorOrderEnum
.valueOf(getStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey()));
1221 return value
.equals(NavigatorOrderEnum
.AlphabeticalOrder
);
1225 public static boolean isNodesSortedByNameAndRank() {
1226 NavigatorOrderEnum value
= NavigatorOrderEnum
.valueOf(getStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey()));
1227 return value
.equals(NavigatorOrderEnum
.RankAndNameOrder
);
1231 public static boolean isStoreNavigatorState() {
1232 return getBooleanValue(RESTORE_NAVIGATOR_STATE
);
1236 public static void setStoreNavigatorState(boolean selection
) {
1237 setBooleanValue(RESTORE_NAVIGATOR_STATE
, selection
);
1241 public static boolean isShowUpWidgetIsDisposedMessages() {
1242 return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
);
1244 public static void setShowUpWidgetIsDisposedMessages(boolean selection
) {
1245 setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
, selection
);
1248 public static boolean isShowIdInVocabularyInChecklistEditor() {
1249 String area_display
= getStringValue(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
1250 if (area_display
.equals(TermDisplayEnum
.IdInVocabulary
.getKey())) {
1256 public static boolean isShowSymbol1InChecklistEditor() {
1257 String area_display
= getStringValue(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
1258 if (area_display
.equals(TermDisplayEnum
.Symbol1
.getKey())) {
1264 public static boolean isShowSymbol2InChecklistEditor() {
1265 String area_display
= getStringValue(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
1266 if (area_display
.equals(TermDisplayEnum
.Symbol2
.getKey())) {
1272 public static void setAreaDisplayInChecklistEditor(String selection
) {
1273 setStringValue(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey(), selection
);
1276 public static void setOwnDescriptionForChecklistEditor(boolean selection
) {
1277 setBooleanValue(PreferencePredicate
.OwnDescriptionForDistributionEditor
.getKey(), selection
);
1280 public static boolean isOwnDescriptionForChecklistEditor() {
1281 return getBooleanValue(PreferencePredicate
.OwnDescriptionForDistributionEditor
.getKey());
1284 public static String
displayAreaInChecklistEditor() {
1285 String result
= getStringValue(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
1286 if (StringUtils
.isBlank(result
)){
1287 return ((TermDisplayEnum
) PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getDefaultValue()).getKey();
1292 public static String
displayStatusInChecklistEditor() {
1293 String result
= getStringValue(PreferencePredicate
.DisplayOfStatus
.getKey());
1294 if (StringUtils
.isBlank(result
)){
1295 return((TermDisplayEnum
) PreferencePredicate
.DisplayOfStatus
.getDefaultValue()).getKey();
1299 public static void setDisplayStatusInChecklistEditor(String selection
) {
1300 setStringValue(PreferencePredicate
.DisplayOfStatus
.getKey(), selection
);
1304 public static boolean isShowRankInChecklistEditor() {
1305 return getBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey());
1307 public static void setShowRankInChecklistEditor(boolean selection
) {
1308 setBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey(), selection
);
1311 public static NameDetailsConfigurator
getPreferredNameDetailsConfiguration( boolean local
) {
1312 NameDetailsConfigurator config
= new NameDetailsConfigurator(true);
1313 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
1314 CdmPreference preference
= null;
1317 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.NameDetailsView
);
1318 preference
= cache
.findBestMatching(key
);
1319 if (preference
== null){
1323 // setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1324 value
= preference
.getValue();
1325 config
.setAllowOverride(preference
.isAllowOverride());
1326 //the preference value is build like this:
1327 //<section1>:true;<section2>:false....
1329 value
= getStringValue(PreferencePredicate
.NameDetailsView
.getKey(), local
);
1332 String
[] sections
= value
.split(";");
1333 Map
<String
, Boolean
> sectionMap
= new HashMap
<String
, Boolean
>();
1334 String
[] sectionValues
;
1335 for (String sectionValue
: sections
){
1336 sectionValues
= sectionValue
.split(":");
1337 sectionMap
.put(sectionValues
[0], Boolean
.valueOf(sectionValues
[1]));
1339 config
.setSimpleDetailsViewActivated(getValue(sectionMap
, "simpleViewActivated"));
1340 config
.setTaxonSectionActivated(getValue(sectionMap
, "taxon"));
1341 config
.setSecDetailsActivated(getValue(sectionMap
, "taxon.SecDetails"));
1342 config
.setSecEnabled(getValue(sectionMap
, "taxon.SecEnabled"));
1343 config
.setLSIDActivated(getValue(sectionMap
, "lsid"));
1344 config
.setNomenclaturalCodeActived(getValue(sectionMap
, "nc"));
1345 config
.setAppendedPhraseActivated(getValue(sectionMap
, "ap"));
1346 config
.setRankActivated(getValue(sectionMap
, "rank"));
1347 config
.setAtomisedEpithetsActivated(getValue(sectionMap
, "atomisedEpithets"));
1348 config
.setAuthorshipSectionActivated(getValue(sectionMap
,"author"));
1349 config
.setNomenclaturalReferenceSectionActivated(sectionMap
.get("nomRef"));
1350 config
.setNomenclaturalStatusSectionActivated(getValue(sectionMap
, "nomStat"));
1351 config
.setProtologueActivated(getValue(sectionMap
,"protologue"));
1352 config
.setTypeDesignationSectionActivated(getValue(sectionMap
,"typeDes"));
1353 config
.setNameRelationsSectionActivated(getValue(sectionMap
,"nameRelation"));
1354 config
.setHybridActivated(getValue(sectionMap
,"hybrid"));
1359 public static NameDetailsConfigurator
getPreferredNameDetailsConfiguration() {
1360 NameDetailsConfigurator config
= new NameDetailsConfigurator(true);
1364 value
= getStringValue(PreferencePredicate
.NameDetailsView
.getKey(), false);
1366 String
[] sections
= value
.split(";");
1367 Map
<String
, Boolean
> sectionMap
= new HashMap
<String
, Boolean
>();
1368 String
[] sectionValues
;
1369 for (String sectionValue
: sections
){
1370 sectionValues
= sectionValue
.split(":");
1371 sectionMap
.put(sectionValues
[0], Boolean
.valueOf(sectionValues
[1]));
1374 config
.setSimpleDetailsViewActivated(getValue(sectionMap
, "simpleViewActivated"));
1376 config
.setTaxonSectionActivated(getValue(sectionMap
, "taxon"));
1378 config
.setSecDetailsActivated(getValue(sectionMap
, "taxon.SecDetails"));
1379 config
.setSecEnabled(getValue(sectionMap
, "taxon.SecEnabled"));
1381 config
.setLSIDActivated(getValue(sectionMap
, "lsid"));
1383 config
.setNomenclaturalCodeActived(getValue(sectionMap
, "nc"));
1385 config
.setAppendedPhraseActivated(getValue(sectionMap
, "ap"));
1387 config
.setRankActivated(getValue(sectionMap
, "rank"));
1389 config
.setAtomisedEpithetsActivated(getValue(sectionMap
, "atomisedEpithets"));
1391 config
.setAuthorshipSectionActivated(getValue(sectionMap
,"author"));
1393 config
.setNomenclaturalReferenceSectionActivated(sectionMap
.get("nomRef"));
1395 config
.setNomenclaturalStatusSectionActivated(getValue(sectionMap
, "nomStat"));
1397 config
.setProtologueActivated(getValue(sectionMap
,"protologue"));
1399 config
.setTypeDesignationSectionActivated(getValue(sectionMap
,"typeDes"));
1401 config
.setNameRelationsSectionActivated(getValue(sectionMap
,"nameRelation"));
1403 config
.setHybridActivated(getValue(sectionMap
,"hybrid"));
1408 public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config
, boolean local
) {
1409 CdmPreference preference
= null;
1412 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.NameDetailsView
, config
.toString());
1414 setPreferenceToDB(preference
);
1417 setStringValue(PreferencePredicate
.NameDetailsView
.getKey(), config
.toString());
1423 private static Boolean
getValue(Map
<String
, Boolean
> sectionMap
, String string
) {
1424 if (sectionMap
.containsKey(string
)){
1425 return sectionMap
.get(string
);
1432 public static Abcd206ImportConfigurator
getDBAbcdImportConfigurationPreference() {
1434 Abcd206ImportConfigurator config
= Abcd206ImportConfigurator
.NewInstance(null,null);
1435 ICdmRepository controller
;
1436 controller
= CdmStore
.getCurrentApplicationConfiguration();
1437 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
);
1438 CdmPreference preference
= null;
1439 if (controller
== null){
1442 preference
= controller
.getPreferenceService().find(key
);
1443 if (preference
== null){
1446 String configString
= preference
.getValue();
1447 if(configString
!=null){
1448 String
[] configArray
= configString
.split(";");
1450 for (String configItem
: configArray
){
1451 String
[] keyValue
= configItem
.split(":");
1452 String keyString
= keyValue
[0];
1453 String valueString
= null;
1454 if (keyValue
.length
>1){
1455 valueString
= keyValue
[1];
1457 if (keyString
.equals("ignoreImportOfExistingSpecimen")){
1458 config
.setIgnoreImportOfExistingSpecimen(Boolean
.valueOf(valueString
));
1459 }else if (keyString
.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1460 config
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean
.valueOf(valueString
));
1461 }else if (keyString
.equals("reuseExistingTaxaWhenPossible")){
1462 config
.setReuseExistingTaxaWhenPossible(Boolean
.valueOf(valueString
));
1463 }else if (keyString
.equals("ignoreAuthorship")){
1464 config
.setIgnoreAuthorship(Boolean
.valueOf(valueString
));
1465 }else if (keyString
.equals("addMediaAsMediaSpecimen")){
1466 config
.setAddMediaAsMediaSpecimen(Boolean
.valueOf(valueString
));
1467 }else if (keyString
.equals("reuseExistingMetaData")){
1468 config
.setReuseExistingMetaData(Boolean
.valueOf(valueString
));
1469 }else if (keyString
.equals("reuseExistingDescriptiveGroups")){
1470 config
.setReuseExistingDescriptiveGroups(Boolean
.valueOf(valueString
));
1471 }else if (keyString
.equals("allowReuseOtherClassifications")){
1472 config
.setAllowReuseOtherClassifications(Boolean
.valueOf(valueString
));
1473 }else if (keyString
.equals("deduplicateReferences")){
1474 config
.setDeduplicateReferences(Boolean
.valueOf(valueString
));
1475 }else if (keyString
.equals("deduplicateClassifications")){
1476 config
.setDeduplicateClassifications(Boolean
.valueOf(valueString
));
1477 }else if (keyString
.equals("moveNewTaxaToDefaultClassification")){
1478 config
.setMoveNewTaxaToDefaultClassification(Boolean
.valueOf(valueString
));
1479 }else if (keyString
.equals("mapUnitIdToCatalogNumber")){
1480 config
.setMapUnitIdToCatalogNumber(Boolean
.valueOf(valueString
));
1481 }else if (keyString
.equals("mapUnitIdToAccessionNumber")){
1482 config
.setMapUnitIdToAccessionNumber(Boolean
.valueOf(valueString
));
1483 }else if (keyString
.equals("mapUnitIdToBarcode")){
1484 config
.setMapUnitIdToBarcode(Boolean
.valueOf(valueString
));
1485 }else if (keyString
.equals("overwriteExistingSpecimens")){
1486 config
.setOverwriteExistingSpecimens(Boolean
.valueOf(valueString
));
1487 }else if (keyString
.equals("nomenclaturalCode")){
1488 config
.setNomenclaturalCode(NomenclaturalCode
.fromString(valueString
));
1490 logger
.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString
);
1498 public static Abcd206ImportConfigurator
getLocalAbcdImportConfigurator(){
1499 Abcd206ImportConfigurator config
= Abcd206ImportConfigurator
.NewInstance(null,null);
1501 config
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS
));
1503 config
.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN
));
1505 config
.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS
));
1506 config
.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS
));
1507 config
.setDeduplicateReferences(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES
));
1508 config
.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT
));
1509 config
.setGetSiblings(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS
));
1510 config
.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP
));
1511 config
.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN
));
1512 config
.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER
));
1513 config
.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE
));
1514 config
.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER
));
1515 config
.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION
));
1516 config
.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN
));
1517 config
.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS
));
1518 config
.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA
));
1519 config
.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE
));
1520 config
.setNomenclaturalCode(NomenclaturalCode
.getByKey(getStringValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE
)));
1522 config
.setDnaSoure(!StringUtils
.isBlank(getStringValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DNA_PROVIDER
))? URI
.create(getStringValue(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DNA_PROVIDER
)):null);
1523 }catch(Exception e
){
1524 config
.setDnaSoure(null);
1530 public static void updateAbcdImportConfigurationPreference() {
1531 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
1533 CdmPreference pref
= cache
.findBestMatching(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
));
1535 if (!getBooleanValue(prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey())) || !pref
.isAllowOverride()){
1536 resetToDBPreferenceAbcdCOnfigurator();
1541 public static void resetToDBPreferenceAbcdCOnfigurator(){
1542 Abcd206ImportConfigurator config
= getDBAbcdImportConfigurationPreference();
1543 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS
, config
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1544 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN
, config
.isAddMediaAsMediaSpecimen());
1546 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS
, config
.isAllowReuseOtherClassifications());
1547 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS
, config
.isDeduplicateClassifications());
1548 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES
, config
.isDeduplicateReferences());
1550 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS
, config
.isGetSiblings());
1551 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP
, config
.isIgnoreAuthorship());
1552 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN
, config
.isIgnoreImportOfExistingSpecimen());
1553 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER
, config
.isMapUnitIdToAccessionNumber());
1554 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE
, config
.isMapUnitIdToBarcode());
1555 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER
, config
.isMapUnitIdToCatalogNumber());
1556 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION
, config
.isMoveNewTaxaToDefaultClassification());
1557 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN
, config
.isOverwriteExistingSpecimens());
1558 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS
, config
.isReuseExistingDescriptiveGroups());
1559 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA
, config
.isReuseExistingMetaData());
1560 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE
, config
.isReuseExistingTaxaWhenPossible());
1561 if (config
.getNomenclaturalCode() != null){
1562 setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE
, config
.getNomenclaturalCode().getKey());
1566 public static boolean isSortTaxaByRankAndName() {
1568 return getBooleanValue(IPreferenceKeys
.SORT_TAXA_BY_RANK_AND_NAME
);
1571 public static String
getSortNamedAreasInDistributionEditor() {
1573 return getStringValue(PreferencePredicate
.AreasSortedInDistributionEditor
.getKey());
1576 public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder
) {
1577 setStringValue(PreferencePredicate
.AreasSortedInDistributionEditor
.getKey(), isSortByVocabularyOrder
);
1581 public static void setLastSelectedReference(
1582 List
<String
> lastSelectedReferences
) {
1584 setStringValue(PreferencesUtil
.LAST_SELECTED_REFERENCES
, lastSelectedReferences
.toString());
1587 public static List
<String
> getLastSelectedReferences() {
1589 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1590 String lastSelected
= getStringValue(PreferencesUtil
.LAST_SELECTED_REFERENCES
);
1591 List
<String
> result
= new ArrayList
<>();
1592 if (!StringUtils
.isBlank(lastSelected
)){
1593 Collections
.addAll(result
, lastSelected
.substring(1,lastSelected
.length()-1).split(", "));
1598 public static void setPreferredNamedAreasForDistributionEditor(
1599 String saveCheckedElements
, String saveGrayedElements
, boolean local
) {
1601 setStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), saveCheckedElements
);
1605 CdmPreference preference
= null;
1607 if (saveCheckedElements
== null){
1608 preference
= getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaTerms
);
1610 if (preference
== null){
1613 setStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(),
1614 saveCheckedElements
);
1615 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionAreaTerms
, saveCheckedElements
);
1616 setPreferenceToDB(preference
);
1620 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionAreaTerms
, saveCheckedElements
);
1621 setPreferenceToDB(preference
);
1622 setStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(),
1623 saveCheckedElements
);
1630 public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements
,
1631 boolean local
, boolean isOverride
) {
1633 setStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey(), saveCheckedElements
);
1634 setBooleanValue(prefOverrideKey(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey()), isOverride
);
1637 ICdmRepository controller
;
1638 CdmPreference preference
= null;
1640 if (saveCheckedElements
== null){
1641 preference
= getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
);
1643 if (preference
== null){
1646 setStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey(),
1647 saveCheckedElements
);
1648 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionAreaVocabularies
, saveCheckedElements
);
1649 preference
.setAllowOverride(isOverride
);
1650 setPreferenceToDB(preference
);
1653 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionAreaVocabularies
, saveCheckedElements
);
1654 preference
.setAllowOverride(isOverride
);
1655 setPreferenceToDB(preference
);
1656 setStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey(),
1657 saveCheckedElements
);
1663 public static String
getPreferredVocabulariesForDistributionEditor(boolean local
) {
1666 String pref
= getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey(), local
);
1670 CdmPreference preference
= null;
1671 preference
= getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
);
1672 if (preference
== null){
1675 return preference
.getValue();
1681 public static List
<UUID
> createUUIDListFromStringPref(String prefKey
) {
1682 String prefValue
= PreferencesUtil
.getStringValue(prefKey
);
1683 if (prefValue
== null){
1686 String
[] stringArray
= prefValue
.split(";");
1687 List
<UUID
> uuidList
= new ArrayList();
1688 for (String uuid
: stringArray
){
1689 if (!StringUtils
.isBlank(uuid
)){
1690 uuidList
.add(UUID
.fromString(uuid
));
1696 public static boolean getFilterCommonNameReferences(){
1697 Boolean result
= getBooleanValue(PreferencesUtil
.FILTER_COMMON_NAME_REFERENCES
);
1698 if (result
== null){
1704 public static void updateDBPreferences() {
1707 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
1708 cache
.getAllTaxEditorDBPreferences();
1712 updateAbcdImportConfigurationPreference();
1715 NameDetailsConfigurator config
= getPreferredNameDetailsConfiguration(false);
1716 // if (config != null ){
1717 // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1718 // setPreferredNameDetailsConfiguration(config, false);
1724 public static void setPreferencesToDB(List
<CdmPreference
> preferences
) {
1726 ICdmRepository controller
;
1728 if(CdmStore
.isActive()){
1729 controller
= CdmStore
.getCurrentApplicationConfiguration();
1730 for (CdmPreference preference
: preferences
){
1731 if (preference
.getValue() == null && preference
.isAllowOverride()){
1732 controller
.getPreferenceService().remove(preference
.getKey());
1735 controller
.getPreferenceService().set(preference
);
1740 CdmPreferenceCache
.instance().getAllTaxEditorDBPreferences();
1743 /*}catch(Exception e){
1744 e.printStackTrace();
1749 * Returns whether the named preference is known.
1750 * @param prefKey the key of the preference
1751 * @return <code>true</code> if the preference is known, <code>false</code> otherwise
1753 public static boolean contains(String prefKey
){
1754 return getPreferenceStore().contains(prefKey(prefKey
));