Merge branch 'release/5.8.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.preference;
11
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.net.URI;
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;
23 import java.util.Map;
24 import java.util.Properties;
25 import java.util.StringTokenizer;
26 import java.util.UUID;
27
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;
41
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;
77
78 /**
79 * <p>
80 * PreferencesUtil class.
81 * </p>
82 *
83 * @author p.ciardelli
84 * @author n.hoffmann
85 * @created 05.12.2008
86 */
87 public class PreferencesUtil implements IPreferenceKeys {
88 private final static String EDITOR_PREFERENCES_NODE = "eu.etaxonomy.taxeditor";
89
90 public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
91
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);
96
97 public static IPreferenceStore getPreferenceStore() {
98 return TaxeditorStorePlugin.getDefault().getPreferenceStore();
99 }
100
101 public static String[] extractSubjectParts(String subject){
102 String[] result = subject.split("/");
103 return result;
104 }
105
106 public static IEclipsePreferences getEditorPreferences(){
107 return ConfigurationScope.INSTANCE.getNode(EDITOR_PREFERENCES_NODE);
108 }
109
110 public static String getPreferenceValue(PrefKey prefKey){
111 try {
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());
119 index--;
120 }
121 return value;
122 }
123
124 } catch (BackingStoreException e) {
125 // TODO Auto-generated catch block
126 e.printStackTrace();
127 }
128 return null;
129 }
130
131 public static List<CdmPreference> getPreference(PreferencePredicate prefPredicate){
132 try {
133 List<CdmPreference> prefs = new ArrayList();
134 CdmPreference pref;
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);
145 prefs.add(pref);
146 }
147
148 }
149
150 } catch (BackingStoreException e) {
151 // TODO Auto-generated catch block
152 e.printStackTrace();
153 }
154 return null;
155 }
156
157 /**
158 * @param childName
159 * @param child
160 */
161 private static String createSubjectStringForChildNodes(String subject, Preferences parent) {
162 try {
163 for (String childName: parent.childrenNames()){
164 subject = childName+SUBJECT_DELIM+subject;
165 Preferences child = parent.node(childName);
166 createSubjectStringForChildNodes(subject, child);
167 }
168 } catch (BackingStoreException e) {
169 // TODO Auto-generated catch block
170 e.printStackTrace();
171 }
172 return subject;
173
174 }
175
176 private static String prefKey(String name) {
177 return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
178 }
179
180 public static String prefOverrideKey(String name) {
181 return name + "_OVERRIDE_";
182 }
183
184 public static void setStringValue(String name, String value) {
185 if (value != null){
186 getPreferenceStore().setValue(prefKey(name), value);
187 }else{
188 getPreferenceStore().setToDefault(name);
189 }
190 }
191
192 public static void setIntValue(String name, int value) {
193 getPreferenceStore().setValue(prefKey(name), value);
194 }
195
196 public static void setBooleanValue(String name, boolean value) {
197 getPreferenceStore().setValue(prefKey(name), value);
198 }
199
200 public static void setDoubleValue(String name, double value) {
201 getPreferenceStore().setValue(prefKey(name), value);
202 }
203
204 public static void setFloatValue(String name, float value) {
205 getPreferenceStore().setValue(prefKey(name), value);
206 }
207
208 public static void setLongValue(String name, long value) {
209 getPreferenceStore().setValue(prefKey(name), value);
210 }
211
212 public static String getStringValue(String name, boolean local) {
213
214 CdmPreference pref = getDBPreferenceValue(name);
215 String prefValue = null;
216 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
217 boolean override = getPreferenceStore().getBoolean(overrideKey);
218
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);
223 }else{
224 prefValue = getPreferenceStore().
225 getString(name);
226 }
227 }else if (pref != null){
228 prefValue = pref.getValue();
229 }
230 return prefValue;
231
232 }
233
234 public static String getStringValue(String name){
235 return getStringValue(name, false);
236 }
237
238 private static CdmPreference getDBPreferenceValue(String name) {
239 CdmPreferenceCache cache = CdmPreferenceCache.instance();
240 CdmPreference pref = null;
241 //
242 pref = cache.get(name);
243 if (pref == null ){
244 //get default value for Predicate
245 IPreferencePredicate pred = PreferencePredicate.getByKey(name);
246 if (pred != null){
247 if (pred.getDefaultValue() != null){
248 pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString());
249 }else{
250 pref = CdmPreference.NewTaxEditorInstance(pred, null);
251 }
252 pref.setAllowOverride(true);
253 }
254 }
255 return pref;
256 }
257
258 public static int getIntValue(String name, boolean local) {
259 CdmPreference pref= getDBPreferenceValue(name);
260 String prefValue = null;
261 if (pref != null){
262 prefValue = pref.getValue();
263 }
264 Integer result = null;
265 try{
266 result = Integer.parseInt(prefValue);
267 }catch(NumberFormatException e){
268 logger.debug("Preference value of " + name + " is not a number");
269 }
270
271 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
272 boolean override = true;
273 if (getPreferenceStore().contains(overrideKey)){
274 override = getPreferenceStore().getBoolean(overrideKey);
275 }
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);
280 }else{
281 result = getPreferenceStore().
282 getInt(name);
283 }
284 }
285 return result;
286
287 }
288
289 public static boolean getBooleanValue(String name) {
290 Boolean result = getBooleanValue(name, false);
291 if (result == null){
292 return false;
293 }else{
294 return result;
295 }
296
297 }
298
299 public static Boolean getBooleanValue(String name, boolean local) {
300 if (CdmStore.isActive()){
301 CdmPreference pref = getDBPreferenceValue(name);
302
303 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
304 boolean override = getPreferenceStore().getBoolean(overrideKey);
305
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);
310 }else{
311 return null;
312 }
313 }else{
314 return Boolean.valueOf(pref.getValue());
315 }
316
317 }else{
318 return getPreferenceStore().getBoolean(name);
319 }
320
321 }
322
323 public static double getDoubleValue(String name) {
324 CdmPreference pref = getDBPreferenceValue(name);
325 String prefValue = null;
326 if (pref != null){
327 prefValue = pref.getValue();
328 }
329 Double result = null;
330 try{
331 result = Double.parseDouble(prefValue);
332 }catch(NumberFormatException e){
333 logger.debug("Preference value of " + name + " is not a number");
334 }
335 if (result == null){
336 String dbSpecific = prefKey(name);
337 if (getPreferenceStore().contains(dbSpecific)){
338 result = getPreferenceStore().getDouble(dbSpecific);
339 }else{
340 result = getPreferenceStore().
341 getDouble(name);
342 }
343 }
344 return result;
345
346 }
347
348 public static float getFloatValue(String name, boolean local) {
349 CdmPreference pref = getDBPreferenceValue(name);
350 String prefValue = null;
351 if (pref != null){
352 prefValue = pref.getValue();
353 }
354 Float result = null;
355 try{
356 result = Float.parseFloat(prefValue);
357 }catch(NumberFormatException e){
358 logger.debug("Preference value of " + name + " is not a number");
359 }
360 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
361 boolean override = true;
362 if (getPreferenceStore().contains(overrideKey)){
363 override = getPreferenceStore().getBoolean(overrideKey);
364 }
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);
369 }else{
370 result = getPreferenceStore().
371 getFloat(name);
372 }
373 }
374 return result;
375
376 }
377
378 public static long getLongValue(String name) {
379 CdmPreference pref = getDBPreferenceValue(name);
380 String prefValue = null;
381 if (pref != null){
382 prefValue = pref.getValue();
383 }
384 Long result = null;
385 try{
386 result = Long.parseLong(prefValue);
387 }catch(NumberFormatException e){
388 logger.debug("Preference value of " + name + " is not a number");
389 }
390 if (result == null){
391 String dbSpecific = prefKey(name);
392 if (getPreferenceStore().contains(dbSpecific)){
393 result = getPreferenceStore().getLong(dbSpecific);
394 }else{
395 result = getPreferenceStore().
396 getLong(name);
397 }
398 }
399 return result;
400 }
401
402 public static CdmPreference setPreferredNomenclaturalCode(
403 String preferenceValue, boolean local) {
404 if (local){
405 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
406 preferenceValue);
407 }
408 else{
409 ICdmRepository controller;
410 controller = CdmStore.getCurrentApplicationConfiguration();
411 if (controller == null){
412 return null;
413 }
414 PrefKey key = null;
415 try{
416 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
417 }catch (Exception e){
418 System.out.println(e.getStackTrace());
419 }
420 CdmPreference preference = null;
421
422 if (preferenceValue == null){
423 preference = controller.getPreferenceService().find(key);
424 if (preference == null){
425 return null;
426 } else{
427 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
428 preference.getValue());
429
430 return preference;
431 }
432 } else{
433 preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
434 controller.getPreferenceService().set(preference);
435
436 }
437 }
438 return null;
439
440
441
442 }
443
444 public static void setPreferredNomenclaturalCode(
445 CdmPreference preference) {
446
447 ICdmRepository controller;
448 controller = CdmStore.getCurrentApplicationConfiguration();
449 if (controller == null){
450 return;
451 }
452 PrefKey key = null;
453 try{
454 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
455 }catch (Exception e){
456 System.out.println(e.getStackTrace());
457 }
458
459 controller.getPreferenceService().set(preference);
460
461 }
462
463 public static NomenclaturalCode getPreferredNomenclaturalCode() {
464
465 CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
466
467
468 String preferredCode;
469 if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
470 preferredCode = getStringValue(
471 PreferencePredicate.NomenclaturalCode.getKey(), true);
472
473 }else{
474 preferredCode = pref.getValue();
475 }
476 if (StringUtils.isBlank(preferredCode)){
477 preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
478 }
479
480 return getPreferredNomenclaturalCode(preferredCode);
481
482 }
483
484 public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
485
486 for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
487 if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
488 return code;
489 }
490 }
491 return null;
492 }
493
494 public static boolean isShowTaxonAssociations(){
495 boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
496 return result;
497 }
498
499 public static boolean isShowLifeForm(){
500 boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
501 return result;
502 }
503
504 public static boolean isDeterminationOnlyForFieldUnits(){
505 boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
506 return result;
507 }
508
509 public static boolean isCollectingAreaInGeneralSection(){
510 boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
511 return result;
512 }
513
514 public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
515 ICdmRepository controller;
516 CdmPreference pref = null;
517
518 try{
519 if(CdmStore.isActive()){
520 controller = CdmStore.getCurrentApplicationConfiguration();
521 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
522 pref = controller.getPreferenceService().find(key);
523 }
524 }catch(Exception e){
525 e.printStackTrace();
526 }
527
528 return pref;
529
530 }
531
532 public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
533 ICdmRepository controller;
534 List<CdmPreference> prefs = null;
535
536 try{
537 if(CdmStore.isActive()){
538 controller = CdmStore.getCurrentApplicationConfiguration();
539 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
540 prefs = controller.getPreferenceService().list(predicate);
541 }
542 }catch(Exception e){
543 e.printStackTrace();
544 }
545
546 return prefs;
547
548 }
549
550 public static void setPreferencesToDB(CdmPreference preference, boolean setDefault){
551 ICdmRepository controller;
552 try{
553 if(CdmStore.isActive()){
554 controller = CdmStore.getCurrentApplicationConfiguration();
555
556 if (setDefault){
557 controller.getPreferenceService().remove(preference.getKey());
558 }else{
559 controller.getPreferenceService().set(preference);
560 }
561 }
562 }catch(Exception e){
563 e.printStackTrace();
564 }
565
566
567
568 }
569
570 public static CdmPreference getPreferenceFromDB(PrefKey key){
571 ICdmRepository controller;
572 CdmPreference pref = null;
573
574 try{
575 if(CdmStore.isActive()){
576 controller = CdmStore.getCurrentApplicationConfiguration();
577 pref = controller.getPreferenceService().find(key);
578 }
579 }catch(Exception e){
580 e.printStackTrace();
581 }
582
583 return pref;
584
585 }
586
587 public static void setPreferenceToDB(CdmPreference preference){
588 ICdmRepository controller;
589 try{
590 if(CdmStore.isActive()){
591 controller = CdmStore.getCurrentApplicationConfiguration();
592 if (preference.getValue() == null && preference.isAllowOverride()){
593 controller.getPreferenceService().remove(preference.getKey());
594 }else{
595 controller.getPreferenceService().set(preference);
596 }
597 CdmPreferenceCache.instance().put(preference);
598 }
599 }catch(Exception e){
600 e.printStackTrace();
601 }
602
603 }
604
605 public static String getPreferredDefaultLangugae(){
606 String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
607 if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
608 return preferredLanguage;
609 }
610 return null;
611 }
612
613 public static boolean isShowMediaPreview(){
614 boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
615 return isShowMediaPreview;
616 }
617
618 /**
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
621 *
622 * @param clazz
623 * a {@link java.lang.Class} object.
624 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
625 */
626 public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
627 String className = clazz.getName();
628 if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
629 IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
630
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);
637 try {
638 matchStrategy.setMatchMode(fieldName, matchMode);
639 } catch (MatchException e) {
640 MessagingUtils.error(PreferencesUtil.class, e);
641 throw new RuntimeException(e);
642 }
643 }
644
645 return matchStrategy;
646 }
647 return getDefaultMatchStrategy(clazz);
648 }
649
650 /**
651 * Stores a matchStrategy into the preference store.
652 *
653 * @param matchStrategy
654 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
655 * object.
656 */
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);
660
661 List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
662
663 for (FieldMatcher fieldMatcher : fieldMatchers) {
664 String fieldName = fieldMatcher.getPropertyName();
665 setStringValue(
666 getMatchStrategyFieldName(className, fieldName),
667 fieldMatcher.getMatchMode().name());
668 }
669 }
670
671 /**
672 * Helper method to create the preference property for a match field.
673 *
674 * @param className
675 * @param fieldName
676 * @return
677 */
678 private static String getMatchStrategyFieldName(String className,
679 String fieldName) {
680 return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
681 }
682
683 /**
684 * Returns the default match strategy for a given class.
685 *
686 * @param clazz
687 * a {@link java.lang.Class} object.
688 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
689 */
690 public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
691 return DefaultMatchStrategy.NewInstance(clazz);
692 }
693
694 public static String getDateFormatPattern() {
695 // TODO make this configurable in properties
696 String pattern = "Y-M-d H:m";
697 return pattern;
698 }
699
700 public static <T extends TermBase> void addTermToPreferredTerms(T term) {
701
702 // VocabularyEnum vocabulary =
703 // VocabularyEnum.getVocabularyEnum(term.getClass());
704 //
705 // getPreferenceStore().setValue(getPreferenceKey(term),
706 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
707 //
708 // firePreferencesChanged(term.getClass());
709 }
710
711 /**
712 * Construct a unique key using the CdmBase object's uuid
713 *
714 * @param cdmBase
715 * @return
716 */
717 private static String getPreferenceKey(ICdmBase cdmBase) {
718 cdmBase = HibernateProxyHelper.deproxy(cdmBase);
719
720 String key = cdmBase.getClass().getName().concat(".")
721 .concat(cdmBase.getUuid().toString());
722 if (key.contains("javassist")) {
723 MessagingUtils.info("proxy");
724 }
725 return key;
726 }
727
728 /**
729 * Construct a unique key using the CdmBase object's uuid
730 *
731 * @param cdmBase
732 * @return
733 */
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.");
741 }
742 return key;
743 }
744
745
746
747 /**
748 * Construct a unique key using the CdmBase object's uuid
749 *
750 * @param cdmBase
751 * @return
752 */
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.");
760 }
761 return key;
762 }
763
764 /**
765 * Retrieves search preferences from the preference store
766 *
767 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
768 */
769 public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
770 IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
771
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)));
781
782 return configurator;
783 }
784
785 /**
786 * create new preferences, setting all search options to true
787 *
788 * @return a
789 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
790 * object.
791 */
792 public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
793 IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
794
795 configurator.setDoTaxa(true);
796 configurator.setDoSynonyms(true);
797 configurator.setDoNamesWithoutTaxa(true);
798 configurator.setDoTaxaByCommonNames(true);
799
800 configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
801 "name", "name.$", "relationsFromThisTaxon.$"));
802
803 configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
804 "name", "name.$", "synonyms.relatedTo.*"));
805
806 // DEFAULT VALUES
807 // match mode is a simple like, actually all other match modes are kind
808 // of bogus
809 configurator
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) ;
816 return configurator;
817 }
818
819 /**
820 * Store search preferences
821 *
822 * @param configurator
823 * a
824 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
825 * object.
826 */
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());
837 }
838
839 public static void firePreferencesChanged(Class clazz) {
840 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
841 null, clazz);
842 }
843
844 public static String createPreferenceString(String property){
845 return prefKey(property);
846
847 }
848 public static String createOverridePreferenceString(String property){
849 return prefOverrideKey(property);
850
851 }
852
853 /**
854 * Set default values for preferences
855 */
856 public static void setDefaults() {
857 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
858 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
859 true);
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);
872
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());
877
878
879 //Name Details
880 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
881
882 //Navigator preferences
883 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
884
885 //getPreferenceStore().setDefault(createPreferenceString(Prefe), true);
886
887 getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false);
888
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()));
906
907 }
908
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);
913 }
914
915
916
917 }
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){
924 return ;
925 }
926 preference = controller.getPreferenceService().find(key);
927 if (preference == null){
928 return;
929 }
930 // setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
931
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);
935
936 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
937 getPreferenceKey(preferredCode));
938
939 }
940
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();
947 }
948 }else{
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
951 }
952 }
953
954 public static String getMapServiceAccessPoint() {
955 return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
956 }
957
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);
961 return false;
962 }
963
964 public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
965 String uuidString = getStringValue(
966 FEATURE_TREE_DEFAULT_TEXT);
967 if (StringUtils.isBlank(uuidString)) {
968 return null;
969 }
970 FeatureTree tree = CdmStore.getService(
971 IFeatureTreeService.class).load(UUID.fromString(uuidString));
972 if (tree.getId() == 0) {
973 return null;
974 }
975 return tree;
976 }
977
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));
983 }
984
985 public static void setSortRanksHierarchichally(boolean selection) {
986 setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
987 }
988
989 public static boolean getSortRanksHierarchichally() {
990 return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
991 }
992
993 public static boolean isMultilanguageTextEditingCapability() {
994 return getBooleanValue(
995 MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
996 }
997
998 public static Language getGlobalLanguage() {
999
1000
1001 String languageUuidString = getStringValue(
1002 GLOBAL_LANGUAGE_UUID);
1003
1004 if(!CdmStore.isActive()) {
1005 MessagingUtils.noDataSourceWarningDialog(languageUuidString);
1006 return null;
1007 }
1008
1009 if (CdmUtils.isBlank(languageUuidString)) {
1010 return Language.getDefaultLanguage();
1011 }
1012
1013 UUID languageUuid = UUID.fromString(languageUuidString);
1014 return (Language) CdmStore.getService(ITermService.class).load(
1015 languageUuid);
1016 }
1017
1018 public static void setGlobalLanguage(Language language) {
1019 if(language != null) {
1020 setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
1021 CdmStore.setDefaultLanguage(language);
1022 }
1023
1024 }
1025
1026 public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
1027 List<MarkerType> markerTypes = CdmStore.getTermManager()
1028 .getPreferredTerms(MarkerType.class);
1029
1030 Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
1031
1032 for (MarkerType markerType : markerTypes) {
1033 String name = getMarkerTypeEditingPreferenceKey(markerType);
1034 Boolean value = getBooleanValue(name);
1035
1036 result.put(markerType, value);
1037 }
1038
1039 return result;
1040 }
1041
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));
1048 }
1049
1050 }
1051
1052 private static String getMarkerTypeEditingPreferenceKey(
1053 MarkerType markerType) {
1054 markerType = HibernateProxyHelper.deproxy(markerType);
1055 return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
1056 }
1057
1058 public static void setEditMarkerTypePreference(MarkerType markerType,
1059 boolean edit) {
1060 setBooleanValue(
1061 getMarkerTypeEditingPreferenceKey(markerType), edit);
1062 }
1063
1064 public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
1065 DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
1066 .NewInstance();
1067 configurator.setMoveDerivedUnitMediaToGallery(true);
1068 configurator.setMoveFieldObjectMediaToGallery(true);
1069 return configurator;
1070 }
1071
1072 /**
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>
1075 *
1076 * @param setLanguage 0 is for german and 1 for english.
1077 * @throws IOException
1078 */
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
1082 if(file == null){
1083 throw new IOException();
1084 }
1085 Properties properties = load(file.getAbsolutePath()+"/config.ini");
1086 switch(setLanguage){
1087 case 0:
1088 properties.setProperty("osgi.nl", "de");
1089 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
1090 break;
1091 case 1:
1092 properties.setProperty("osgi.nl", "en");
1093 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
1094 break;
1095 default:
1096 break;
1097 }
1098 save(file+"/config.ini", properties);
1099 }
1100
1101 /**
1102 * This method loads a property from a given file and returns it.
1103 *
1104 * @param filename
1105 * @return
1106 * @throws IOException
1107 */
1108 private Properties load(String filename) throws IOException {
1109 FileInputStream in = new FileInputStream(filename);
1110 Properties prop = new Properties();
1111 prop.load(in);
1112 in.close();
1113 return prop;
1114 }
1115
1116 /**
1117 * This method saves a property to the specified file.
1118 *
1119 * @param filename
1120 * @param properties
1121 * @throws IOException
1122 */
1123 private void save(String filename, Properties properties) throws IOException{
1124 FileOutputStream fos = new FileOutputStream(filename);
1125 properties.store(fos, "");
1126 fos.close();
1127 }
1128
1129 /**
1130 * Saves a list of P2 Metadata Repositories as string with specified delimiters
1131 *
1132 * @param p2Repos
1133 */
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()) {
1139 sb.append("-");
1140 } else {
1141 sb.append(p2Repo.getName());
1142 }
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()));
1147 }
1148 getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
1149 }
1150
1151
1152 /**
1153 * Retrieves a list of previously saved P2 repositories
1154 *
1155 * @return
1156 */
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);
1162
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();
1168 URI uri = null;
1169 try {
1170 uri = new URI(p2ReposStrST.nextToken());
1171 } catch (URISyntaxException e) {
1172 continue;
1173 }
1174 boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
1175 MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
1176 mre.setNickname(nickname);
1177 mre.setEnabled(enabled);
1178 p2Repos.add(mre);
1179 }
1180 }
1181 }
1182
1183 return p2Repos;
1184 }
1185
1186 /**
1187 * enables/disables nested composite. <br>
1188 *
1189 * @param ctrl - Composite to be en-/disabeld
1190 * @param enabled - boolean
1191 */
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);
1197 }
1198 } else {
1199 ctrl.setEnabled(enabled);
1200 }
1201 }
1202
1203 public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
1204 setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
1205
1206 }
1207
1208 public static NavigatorOrderEnum getSortNodes() {
1209 return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1210
1211 }
1212
1213 public static boolean isNodesSortedNaturally() {
1214 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1215 return value.equals(NavigatorOrderEnum.NaturalOrder);
1216
1217 }
1218
1219 public static boolean isNodesSortedByName() {
1220 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1221 return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
1222
1223 }
1224
1225 public static boolean isNodesSortedByNameAndRank() {
1226 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1227 return value.equals(NavigatorOrderEnum.RankAndNameOrder);
1228
1229 }
1230
1231 public static boolean isStoreNavigatorState() {
1232 return getBooleanValue(RESTORE_NAVIGATOR_STATE);
1233
1234 }
1235
1236 public static void setStoreNavigatorState(boolean selection) {
1237 setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
1238
1239 }
1240
1241 public static boolean isShowUpWidgetIsDisposedMessages() {
1242 return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1243 }
1244 public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1245 setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1246 }
1247
1248 public static boolean isShowIdInVocabularyInChecklistEditor() {
1249 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1250 if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
1251 return true;
1252 }else{
1253 return false;
1254 }
1255 }
1256 public static boolean isShowSymbol1InChecklistEditor() {
1257 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1258 if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
1259 return true;
1260 }else{
1261 return false;
1262 }
1263 }
1264 public static boolean isShowSymbol2InChecklistEditor() {
1265 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1266 if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
1267 return true;
1268 }else{
1269 return false;
1270 }
1271 }
1272 public static void setAreaDisplayInChecklistEditor(String selection) {
1273 setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
1274 }
1275
1276 public static void setOwnDescriptionForChecklistEditor(boolean selection) {
1277 setBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
1278 }
1279
1280 public static boolean isOwnDescriptionForChecklistEditor() {
1281 return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
1282 }
1283
1284 public static String displayAreaInChecklistEditor() {
1285 String result = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1286 if (StringUtils.isBlank(result)){
1287 return ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()).getKey();
1288 }
1289 return result;
1290 }
1291
1292 public static String displayStatusInChecklistEditor() {
1293 String result = getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
1294 if (StringUtils.isBlank(result)){
1295 return((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey();
1296 }
1297 return result;
1298 }
1299 public static void setDisplayStatusInChecklistEditor(String selection) {
1300 setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
1301
1302 }
1303
1304 public static boolean isShowRankInChecklistEditor() {
1305 return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
1306 }
1307 public static void setShowRankInChecklistEditor(boolean selection) {
1308 setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
1309 }
1310
1311 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1312 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1313 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1314 CdmPreference preference = null;
1315 String value;
1316 if (!local) {
1317 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
1318 preference = cache.findBestMatching(key);
1319 if (preference == null){
1320 return null;
1321 }
1322
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....
1328 }else{
1329 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
1330 }
1331 if (value!= null){
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]));
1338 }
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"));
1355 }
1356 return config;
1357 }
1358
1359 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
1360 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1361
1362 String value;
1363
1364 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
1365 if (value != null){
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]));
1372 }
1373
1374 config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1375
1376 config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1377
1378 config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1379 config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1380
1381 config.setLSIDActivated(getValue(sectionMap, "lsid"));
1382
1383 config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1384
1385 config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1386
1387 config.setRankActivated(getValue(sectionMap, "rank"));
1388
1389 config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1390
1391 config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1392
1393 config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1394
1395 config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1396
1397 config.setProtologueActivated(getValue(sectionMap,"protologue"));
1398
1399 config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1400
1401 config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1402
1403 config.setHybridActivated(getValue(sectionMap,"hybrid"));
1404 }
1405 return config;
1406 }
1407
1408 public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1409 CdmPreference preference = null;
1410
1411 if (!local) {
1412 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView, config.toString());
1413
1414 setPreferenceToDB(preference);
1415 }
1416 else{
1417 setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
1418 }
1419
1420
1421 }
1422
1423 private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1424 if (sectionMap.containsKey(string)){
1425 return sectionMap.get(string);
1426 }else{
1427 return true;
1428 }
1429
1430 }
1431
1432 public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1433
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){
1440 return null;
1441 }
1442 preference = controller.getPreferenceService().find(key);
1443 if (preference == null){
1444 return config;
1445 } else{
1446 String configString = preference.getValue();
1447 if(configString!=null){
1448 String[] configArray = configString.split(";");
1449
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];
1456 }
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));
1489 }else{
1490 logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1491 }
1492 }
1493 }
1494 }
1495 return config;
1496 }
1497
1498 public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1499 Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1500
1501 config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1502
1503 config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1504
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)));
1521 try{
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);
1525 }
1526 return config;
1527
1528 }
1529
1530 public static void updateAbcdImportConfigurationPreference() {
1531 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1532
1533 CdmPreference pref = cache.findBestMatching(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig));
1534
1535 if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
1536 resetToDBPreferenceAbcdCOnfigurator();
1537
1538 }
1539 }
1540
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());
1545
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());
1549
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());
1563 }
1564 }
1565
1566 public static boolean isSortTaxaByRankAndName() {
1567
1568 return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1569 }
1570
1571 public static String getSortNamedAreasInDistributionEditor() {
1572
1573 return getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey());
1574 }
1575
1576 public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
1577 setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
1578
1579 }
1580
1581 public static void setLastSelectedReference(
1582 List<String> lastSelectedReferences) {
1583
1584 setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1585 }
1586
1587 public static List<String> getLastSelectedReferences() {
1588
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(", "));
1594 }
1595 return result;
1596 }
1597
1598 public static void setPreferredNamedAreasForDistributionEditor(
1599 String saveCheckedElements, String saveGrayedElements, boolean local) {
1600 if (local){
1601 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
1602
1603 }
1604 else{
1605 CdmPreference preference = null;
1606
1607 if (saveCheckedElements == null){
1608 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1609
1610 if (preference == null){
1611 return ;
1612 } else{
1613 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1614 saveCheckedElements);
1615 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1616 setPreferenceToDB(preference);
1617
1618 }
1619 } else{
1620 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1621 setPreferenceToDB(preference);
1622 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1623 saveCheckedElements);
1624
1625 }
1626 }
1627
1628 }
1629
1630 public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1631 boolean local, boolean isOverride) {
1632 if (local){
1633 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
1634 setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
1635 }
1636 else{
1637 ICdmRepository controller;
1638 CdmPreference preference = null;
1639
1640 if (saveCheckedElements == null){
1641 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1642
1643 if (preference == null){
1644 return ;
1645 } else{
1646 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1647 saveCheckedElements);
1648 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1649 preference.setAllowOverride(isOverride);
1650 setPreferenceToDB(preference);
1651 }
1652 } else{
1653 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1654 preference.setAllowOverride(isOverride);
1655 setPreferenceToDB(preference);
1656 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1657 saveCheckedElements);
1658
1659 }
1660 }
1661 }
1662
1663 public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1664 if (local){
1665
1666 String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
1667 return pref;
1668 }
1669 else{
1670 CdmPreference preference = null;
1671 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1672 if (preference == null){
1673 return null;
1674 } else{
1675 return preference.getValue();
1676 }
1677
1678 }
1679 }
1680
1681 public static List<UUID> createUUIDListFromStringPref(String prefKey) {
1682 String prefValue = PreferencesUtil.getStringValue(prefKey);
1683 if (prefValue == null){
1684 return null;
1685 }
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));
1691 }
1692 }
1693 return uuidList;
1694 }
1695
1696 public static boolean getFilterCommonNameReferences(){
1697 Boolean result = getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1698 if (result == null){
1699 return false;
1700 }
1701 return result;
1702 }
1703
1704 public static void updateDBPreferences() {
1705
1706
1707 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1708 cache.getAllTaxEditorDBPreferences();
1709
1710 //ABCD Configurator
1711
1712 updateAbcdImportConfigurationPreference();
1713
1714 //Name Details
1715 NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1716 // if (config != null ){
1717 // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1718 // setPreferredNameDetailsConfiguration(config, false);
1719 // }
1720 // }
1721
1722 }
1723
1724 public static void setPreferencesToDB(List<CdmPreference> preferences) {
1725
1726 ICdmRepository controller;
1727 //try{
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());
1733
1734 }else{
1735 controller.getPreferenceService().set(preference);
1736
1737 }
1738
1739 }
1740 CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
1741
1742 }
1743 /*}catch(Exception e){
1744 e.printStackTrace();
1745 }*/
1746 }
1747
1748 /**
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
1752 */
1753 public static boolean contains(String prefKey){
1754 return getPreferenceStore().contains(prefKey(prefKey));
1755 }
1756
1757
1758
1759 }