fix search configuration
[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.equinox.internal.p2.ui.model.MetadataRepositoryElement;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.jface.window.Window;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Shell;
36 import org.eclipse.ui.PlatformUI;
37
38 import eu.etaxonomy.cdm.api.application.ICdmRepository;
39 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
40 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
41 import eu.etaxonomy.cdm.api.service.ITermService;
42 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
43 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
44 import eu.etaxonomy.cdm.common.CdmUtils;
45 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
47 import eu.etaxonomy.cdm.model.common.ICdmBase;
48 import eu.etaxonomy.cdm.model.common.Language;
49 import eu.etaxonomy.cdm.model.common.MarkerType;
50 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
51 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
52 import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
53 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
54 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
55 import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
56 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
57 import eu.etaxonomy.cdm.model.term.FeatureTree;
58 import eu.etaxonomy.cdm.model.term.IDefinedTerm;
59 import eu.etaxonomy.cdm.model.term.ISimpleTerm;
60 import eu.etaxonomy.cdm.model.term.TermBase;
61 import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
62 import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
63 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
64 import eu.etaxonomy.cdm.strategy.match.MatchException;
65 import eu.etaxonomy.cdm.strategy.match.MatchMode;
66 import eu.etaxonomy.taxeditor.model.AbstractUtility;
67 import eu.etaxonomy.taxeditor.model.MessagingUtils;
68 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
69 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
70 import eu.etaxonomy.taxeditor.store.CdmStore;
71 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
72 import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
73
74 /**
75 * <p>
76 * PreferencesUtil class.
77 * </p>
78 *
79 * @author p.ciardelli
80 * @author n.hoffmann
81 * @created 05.12.2008
82 */
83 public class PreferencesUtil implements IPreferenceKeys {
84
85 /**
86 *
87 */
88 public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
89
90 public static final String P2_REPOSITORIES_DELIM = ",";
91 public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
92
93 private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
94
95
96
97
98
99 /**
100 * <p>
101 * getPreferenceStore
102 * </p>
103 *
104 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
105 */
106 public static IPreferenceStore getPreferenceStore() {
107 return TaxeditorStorePlugin.getDefault().getPreferenceStore();
108 }
109
110 static String prefKey(String name) {
111 return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
112 }
113
114 public static String prefOverrideKey(String name) {
115 return name + "_OVERRIDE_";
116 }
117
118 /**
119 * <p>
120 * setStringValue
121 * </p>
122 *
123 *
124 **/
125 public static void setStringValue(String name, String value) {
126 if (value != null){
127 getPreferenceStore().setValue(prefKey(name), value);
128 }else{
129 getPreferenceStore().setToDefault(name);
130 }
131 }
132
133 /**
134 * <p>
135 * setIntValue
136 * </p>
137 *
138 *
139 **/
140 public static void setIntValue(String name, int value) {
141 getPreferenceStore().setValue(prefKey(name), value);
142 }
143
144 /**
145 * <p>
146 * setBooleanValue
147 * </p>
148 *
149 *
150 **/
151 public static void setBooleanValue(String name, boolean value) {
152 getPreferenceStore().setValue(prefKey(name), value);
153 }
154
155 /**
156 * <p>
157 * setBooleanValue
158 * </p>
159 *
160 *
161 **/
162 public static void setDoubleValue(String name, double value) {
163 getPreferenceStore().setValue(prefKey(name), value);
164 }
165
166 /**
167 * <p>
168 * setFloatValue
169 * </p>
170 *
171 *
172 **/
173 public static void setFloatValue(String name, float value) {
174 getPreferenceStore().setValue(prefKey(name), value);
175 }
176
177 /**
178 * <p>
179 * setFloatValue
180 * </p>
181 *
182 *
183 **/
184 public static void setLongValue(String name, long value) {
185 getPreferenceStore().setValue(prefKey(name), value);
186 }
187
188 /**
189 * <p>
190 * getStringValue
191 * </p>
192 *
193 *
194 **/
195 public static String getStringValue(String name, boolean local) {
196
197 CdmPreference pref = getDBPreferenceValue(name);
198 String prefValue = null;
199 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
200 boolean override = true;
201 if (getPreferenceStore().contains(overrideKey)){
202 override = getPreferenceStore().getBoolean(overrideKey);
203 }
204 if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
205 String dbSpecific = prefKey(name);
206 if (getPreferenceStore().contains(dbSpecific)){
207 prefValue = getPreferenceStore().getString(dbSpecific);
208 }else{
209 prefValue = getPreferenceStore().
210 getString(name);
211 }
212 }else if (pref != null){
213 prefValue = pref.getValue();
214 }
215 return prefValue;
216
217 }
218
219 public static String getStringValue(String name){
220 return getStringValue(name, false);
221 }
222
223 private static CdmPreference getDBPreferenceValue(String name) {
224 CdmPreferenceCache cache = CdmPreferenceCache.instance();
225 CdmPreference pref = null;
226 //
227 pref = cache.get(name);
228 if (pref == null ){
229 //get default value for Predicate
230 IPreferencePredicate pred = PreferencePredicate.getByKey(name);
231 if (pred != null){
232 if (pred.getDefaultValue() != null){
233 pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString());
234 }else{
235 pref = CdmPreference.NewTaxEditorInstance(pred, null);
236 }
237 pref.setAllowOverride(true);
238 }
239 }
240 return pref;
241 }
242
243 /**
244 * <p>
245 * setIntValue
246 * </p>
247 *
248 *
249 **/
250 public static int getIntValue(String name) {
251 CdmPreference pref= getDBPreferenceValue(name);
252 String prefValue = null;
253 if (pref != null){
254 prefValue = pref.getValue();
255 }
256 Integer result = null;
257 try{
258 result = Integer.parseInt(prefValue);
259 }catch(NumberFormatException e){
260 logger.debug("Preference value of " + name + " is not a number");
261 }
262 if (result == null){
263 String dbSpecific = prefKey(name);
264 if (getPreferenceStore().contains(dbSpecific)){
265 result = getPreferenceStore().getInt(dbSpecific);
266 }else{
267 result = getPreferenceStore().
268 getInt(name);
269 }
270 }
271 return result;
272
273
274 }
275
276 public static boolean getBooleanValue(String name) {
277 return getBooleanValue(name, false);
278 }
279
280 /**
281 * <p>
282 * getBooleanValue
283 * </p>
284 *
285 *
286 **/
287 public static boolean getBooleanValue(String name, boolean local) {
288 if (CdmStore.isActive()){
289 CdmPreference pref = getDBPreferenceValue(name);
290 String prefValue = null;
291 if (pref == null || local){
292 String dbSpecific = prefKey(name);
293 if (getPreferenceStore().contains(dbSpecific)){
294 return getPreferenceStore().getBoolean(dbSpecific);
295 }else{
296 return getPreferenceStore().
297 getBoolean(name);
298 }
299 }else{
300 return Boolean.valueOf(pref.getValue());
301 }
302
303 }else{
304 return getPreferenceStore().getBoolean(name);
305 }
306
307 }
308
309 /**
310 * <p>
311 * setBooleanValue
312 * </p>
313 *
314 *
315 **/
316 public static double getDoubleValue(String name) {
317 CdmPreference pref = getDBPreferenceValue(name);
318 String prefValue = null;
319 if (pref != null){
320 prefValue = pref.getValue();
321 }
322 Double result = null;
323 try{
324 result = Double.parseDouble(prefValue);
325 }catch(NumberFormatException e){
326 logger.debug("Preference value of " + name + " is not a number");
327 }
328 if (result == null){
329 String dbSpecific = prefKey(name);
330 if (getPreferenceStore().contains(dbSpecific)){
331 result = getPreferenceStore().getDouble(dbSpecific);
332 }else{
333 result = getPreferenceStore().
334 getDouble(name);
335 }
336 }
337 return result;
338
339 }
340
341 /**
342 * <p>
343 * getFloatValue
344 * </p>
345 *
346 *
347 **/
348 public static float getFloatValue(String name) {
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 if (result == null){
361 String dbSpecific = prefKey(name);
362 if (getPreferenceStore().contains(dbSpecific)){
363 result = getPreferenceStore().getFloat(dbSpecific);
364 }else{
365 result = getPreferenceStore().
366 getFloat(name);
367 }
368 }
369 return result;
370
371 }
372
373 /**
374 * <p>
375 * getLongValue
376 * </p>
377 *
378 *
379 **/
380 public static long getLongValue(String name) {
381 CdmPreference pref = getDBPreferenceValue(name);
382 String prefValue = null;
383 if (pref != null){
384 prefValue = pref.getValue();
385 }
386 Long result = null;
387 try{
388 result = Long.parseLong(prefValue);
389 }catch(NumberFormatException e){
390 logger.debug("Preference value of " + name + " is not a number");
391 }
392 if (result == null){
393 String dbSpecific = prefKey(name);
394 if (getPreferenceStore().contains(dbSpecific)){
395 result = getPreferenceStore().getLong(dbSpecific);
396 }else{
397 result = getPreferenceStore().
398 getLong(name);
399 }
400 }
401 return result;
402 }
403
404
405 /**
406 * <p>
407 * setPreferredNomenclaturalCode
408 * </p>
409 *
410 * @param preferredCode
411 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
412 * object.
413 */
414 public static CdmPreference setPreferredNomenclaturalCode(
415 String preferenceValue, boolean local) {
416 if (local){
417 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
418 preferenceValue);
419 }
420 else{
421 ICdmRepository controller;
422 controller = CdmStore.getCurrentApplicationConfiguration();
423 if (controller == null){
424 return null;
425 }
426 PrefKey key = null;
427 try{
428 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
429 }catch (Exception e){
430 System.out.println(e.getStackTrace());
431 }
432 CdmPreference preference = null;
433
434 if (preferenceValue == null){
435 preference = controller.getPreferenceService().find(key);
436 if (preference == null){
437 return null;
438 } else{
439 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
440 preference.getValue());
441
442 return preference;
443 }
444 } else{
445 preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
446 controller.getPreferenceService().set(preference);
447
448 }
449 }
450 return null;
451
452
453
454 }
455
456 /**
457 * <p>
458 * setPreferredNomenclaturalCode
459 * </p>
460 *
461 * @param preferredCode
462 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
463 * object.
464 */
465 public static void setPreferredNomenclaturalCode(
466 CdmPreference preference) {
467
468 ICdmRepository controller;
469 controller = CdmStore.getCurrentApplicationConfiguration();
470 if (controller == null){
471 return;
472 }
473 PrefKey key = null;
474 try{
475 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
476 }catch (Exception e){
477 System.out.println(e.getStackTrace());
478 }
479
480 controller.getPreferenceService().set(preference);
481
482 }
483
484
485
486
487 /**
488 * <p>
489 * getPreferredNomenclaturalCode
490 * </p>
491 *
492 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
493 */
494 public static NomenclaturalCode getPreferredNomenclaturalCode() {
495
496 CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
497
498
499 String preferredCode;
500 if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
501 preferredCode = getStringValue(
502 PreferencePredicate.NomenclaturalCode.getKey(), true);
503
504 }else{
505 preferredCode = pref.getValue();
506 }
507 if (StringUtils.isBlank(preferredCode)){
508 preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
509 }
510
511 return getPreferredNomenclaturalCode(preferredCode);
512
513 }
514
515 /**
516 * <p>
517 * getPreferredNomenclaturalCode
518 * </p>
519 *
520 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
521 */
522 public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
523
524 for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
525 if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
526 return code;
527 }
528 }
529 return null;
530 }
531
532 public static boolean isShowTaxonAssociations(){
533 boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
534 return result;
535 }
536
537 public static boolean isShowLifeForm(){
538 boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
539 return result;
540 }
541
542 public static boolean isDeterminationOnlyForFieldUnits(){
543 boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
544 return result;
545 }
546
547 public static boolean isCollectingAreaInGeneralSection(){
548 boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
549 return result;
550 }
551
552 public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
553 ICdmRepository controller;
554 CdmPreference pref = null;
555
556 try{
557 if(CdmStore.isActive()){
558 controller = CdmStore.getCurrentApplicationConfiguration();
559 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
560 pref = controller.getPreferenceService().find(key);
561 }
562 }catch(Exception e){
563 e.printStackTrace();
564 }
565
566 return pref;
567
568 }
569
570 public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
571 ICdmRepository controller;
572 List<CdmPreference> prefs = null;
573
574 try{
575 if(CdmStore.isActive()){
576 controller = CdmStore.getCurrentApplicationConfiguration();
577 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
578 prefs = controller.getPreferenceService().list(predicate);
579 }
580 }catch(Exception e){
581 e.printStackTrace();
582 }
583
584 return prefs;
585
586 }
587
588 public static CdmPreference getPreferenceFromDB(PrefKey key){
589 ICdmRepository controller;
590 CdmPreference pref = null;
591
592 try{
593 if(CdmStore.isActive()){
594 controller = CdmStore.getCurrentApplicationConfiguration();
595 pref = controller.getPreferenceService().find(key);
596 }
597 }catch(Exception e){
598 e.printStackTrace();
599 }
600
601 return pref;
602
603 }
604
605
606
607 public static void setPreferenceToDB(CdmPreference preference){
608 ICdmRepository controller;
609 try{
610 if(CdmStore.isActive()){
611 controller = CdmStore.getCurrentApplicationConfiguration();
612 controller.getPreferenceService().set(preference);
613 CdmPreferenceCache.instance().put(preference);
614 }
615 }catch(Exception e){
616 e.printStackTrace();
617 }
618
619 }
620
621
622
623 public static String getPreferredDefaultLangugae(){
624 String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
625 if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
626 return preferredLanguage;
627 }
628 return null;
629 }
630
631 public static boolean isShowMediaPreview(){
632 boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
633 return isShowMediaPreview;
634 }
635
636 /**
637 * Get the match strategy for the given class that was stored in preferences
638 * or the default strategy if it was not stored in preferences
639 *
640 * @param clazz
641 * a {@link java.lang.Class} object.
642 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
643 */
644 public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
645 String className = clazz.getName();
646 if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
647 IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
648
649 //TODO CacheMatchers (or multiple field matchers in future) are missing here
650 for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
651 String fieldName = fieldMatcher.getPropertyName();
652 String matchModeName = getStringValue(
653 getMatchStrategyFieldName(className, fieldName));
654 MatchMode matchMode = MatchMode.valueOf(matchModeName);
655 try {
656 matchStrategy.setMatchMode(fieldName, matchMode);
657 } catch (MatchException e) {
658 MessagingUtils.error(PreferencesUtil.class, e);
659 throw new RuntimeException(e);
660 }
661 }
662
663 return matchStrategy;
664 }
665 return getDefaultMatchStrategy(clazz);
666 }
667
668 /**
669 * Stores a matchStrategy into the preference store.
670 *
671 * @param matchStrategy
672 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
673 * object.
674 */
675 public static void setMatchStrategy(IMatchStrategy matchStrategy) {
676 String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
677 setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
678
679 List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
680
681 for (FieldMatcher fieldMatcher : fieldMatchers) {
682 String fieldName = fieldMatcher.getPropertyName();
683 setStringValue(
684 getMatchStrategyFieldName(className, fieldName),
685 fieldMatcher.getMatchMode().name());
686 }
687 }
688
689 /**
690 * Helper method to create the preference property for a match field.
691 *
692 * @param className
693 * @param fieldName
694 * @return
695 */
696 private static String getMatchStrategyFieldName(String className,
697 String fieldName) {
698 return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
699 }
700
701 /**
702 * Returns the default match strategy for a given class.
703 *
704 * @param clazz
705 * a {@link java.lang.Class} object.
706 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
707 */
708 public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
709 return DefaultMatchStrategy.NewInstance(clazz);
710 }
711
712 /**
713 * <p>
714 * getDateFormatPattern
715 * </p>
716 *
717 * @return a {@link java.lang.String} object.
718 */
719 public static String getDateFormatPattern() {
720 // TODO make this configurable in properties
721 String pattern = "Y-M-d H:m";
722 return pattern;
723 }
724
725 /**
726 * <p>
727 * addTermToPreferredTerms
728 * </p>
729 *
730 * @param term
731 * a T object.
732 * @param <T>
733 * a T object.
734 */
735 public static <T extends TermBase> void addTermToPreferredTerms(T term) {
736
737 // VocabularyEnum vocabulary =
738 // VocabularyEnum.getVocabularyEnum(term.getClass());
739 //
740 // getPreferenceStore().setValue(getPreferenceKey(term),
741 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
742 //
743 // firePreferencesChanged(term.getClass());
744 }
745
746 /**
747 * Construct a unique key using the CdmBase object's uuid
748 *
749 * @param cdmBase
750 * @return
751 */
752 private static String getPreferenceKey(ICdmBase cdmBase) {
753 cdmBase = HibernateProxyHelper.deproxy(cdmBase);
754
755 String key = cdmBase.getClass().getName().concat(".")
756 .concat(cdmBase.getUuid().toString());
757 if (key.contains("javassist")) {
758 MessagingUtils.info("proxy");
759 }
760 return key;
761 }
762
763 /**
764 * Construct a unique key using the CdmBase object's uuid
765 *
766 * @param cdmBase
767 * @return
768 */
769 public static String getPreferenceKey(ISimpleTerm simpleTerm) {
770 simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
771 String key = simpleTerm.getClass().getName().concat(".")
772 .concat(simpleTerm.getUuid().toString());
773 if (key.contains("javassist")) {
774 MessagingUtils.warn(PreferencesUtil.class,
775 "Trying to persist a preference based on a proxy class.");
776 }
777 return key;
778 }
779
780
781
782 /**
783 * Construct a unique key using the CdmBase object's uuid
784 *
785 * @param cdmBase
786 * @return
787 */
788 public static String getPreferenceKey(IDefinedTerm definedTerm) {
789 definedTerm = HibernateProxyHelper.deproxy(definedTerm);
790 String key = definedTerm.getClass().getName().concat(".")
791 .concat(definedTerm.getUuid().toString());
792 if (key.contains("javassist")) {
793 MessagingUtils.warn(PreferencesUtil.class,
794 "Trying to persist a preference based on a proxy class.");
795 }
796 return key;
797 }
798
799 /**
800 * Retrieves search preferences from the preference store
801 *
802 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
803 */
804 public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
805 IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
806
807 configurator.setDoTaxa(getBooleanValue(
808 TAXON_SERVICE_CONFIGURATOR_TAXA));
809 configurator.setDoSynonyms(getBooleanValue(
810 TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
811 configurator.setDoNamesWithoutTaxa(getBooleanValue(
812 TAXON_SERVICE_CONFIGURATOR_NAMES));
813 configurator.setDoTaxaByCommonNames(getBooleanValue(
814 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
815 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
816
817 return configurator;
818 }
819
820 /**
821 * create new preferences, setting all search options to true
822 *
823 * @return a
824 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
825 * object.
826 */
827 public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
828 IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
829
830 configurator.setDoTaxa(true);
831 configurator.setDoSynonyms(true);
832 configurator.setDoNamesWithoutTaxa(true);
833 configurator.setDoTaxaByCommonNames(true);
834
835 configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
836 "name", "name.$", "relationsFromThisTaxon.$"));
837
838 configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
839 "name", "name.$", "synonyms.relatedTo.*"));
840
841 // DEFAULT VALUES
842 // match mode is a simple like, actually all other match modes are kind
843 // of bogus
844 configurator
845 .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
846 // we set page number and size here as this should always be unlimited
847 configurator.setPageNumber(0);
848 // TODO currently limit results to 10000
849 configurator.setPageSize(10000);
850 //setSearchConfigurator(configurator) ;
851 return configurator;
852 }
853
854 /**
855 * Store search preferences
856 *
857 * @param configurator
858 * a
859 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
860 * object.
861 */
862 public static void setSearchConfigurator(
863 IFindTaxaAndNamesConfigurator configurator) {
864 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
865 configurator.isDoTaxa());
866 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
867 configurator.isDoSynonyms());
868 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
869 configurator.isDoNamesWithoutTaxa());
870 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
871 configurator.isDoTaxaByCommonNames());
872 }
873
874 /**
875 * <p>
876 * firePreferencesChanged
877 * </p>
878 *
879 * @param clazz
880 * a {@link java.lang.Class} object.
881 */
882 public static void firePreferencesChanged(Class clazz) {
883 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
884 null, clazz);
885 }
886
887 public static String createPreferenceString(String property){
888 return prefKey(property);
889
890 }
891 public static String createOverridePreferenceString(String property){
892 return prefOverrideKey(property);
893
894 }
895
896 /**
897 * Set default values for preferences
898 */
899 public static void setDefaults() {
900 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
901 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
902 true);
903 getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
904 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
905 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
906 getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
907 getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT),
908 "http://www.biodiversitylibrary.org/openurl");
909 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000");
910 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000");
911 //Distribution Editor:
912 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
913 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
914 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
915
916
917 //Name Details
918 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
919
920 //Navigator preferences
921 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
922
923 //getPreferenceStore().setDefault(createPreferenceString(Prefe), true);
924
925 getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false);
926
927 getPreferenceStore().setDefault(createPreferenceString(SHOW_MEDIA_PREVIEW), false);
928 //override db preferences
929 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false);
930 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true);
931 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false);
932 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true);
933 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true);
934 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true);
935 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true);
936 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false);
937 getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
938 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
939 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
940 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
941 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
942 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString()));
943
944 }
945
946 /**
947 * <p>
948 * checkNomenclaturalCode
949 * </p>
950 */
951 public static void checkNomenclaturalCode() {
952 // First time Editor is opened, no nomenclatural code has been set
953 if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
954 PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
955 }
956
957
958
959 }
960 public static void setNomenclaturalCodePreferences(){
961 ICdmRepository controller;
962 controller = CdmStore.getCurrentApplicationConfiguration();
963 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
964 CdmPreference preference = null;
965 if (controller == null){
966 return ;
967 }
968 preference = controller.getPreferenceService().find(key);
969 if (preference == null){
970 return;
971 }
972 // setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
973
974 int index = StringUtils.lastIndexOf(preference.getValue(), ".");
975 UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
976 NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
977
978 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
979 getPreferenceKey(preferredCode));
980
981 }
982
983 public static void checkDefaultLanguage(){
984 if(PreferencesUtil.getPreferredDefaultLangugae() == null){
985 Shell shell = AbstractUtility.getShell();
986 int open = new DefaultLanguageDialog(shell).open();
987 if(open == Window.OK){
988 PlatformUI.getWorkbench().restart();
989 }
990 }else{
991 //TODO:In case of a reinstall, the config.ini will be overwritten
992 // here you create config.ini with the stored key from preferences
993 }
994 }
995
996 /**
997 * <p>
998 * getMapServiceAccessPoint
999 * </p>
1000 *
1001 * @return a {@link java.lang.String} object.
1002 */
1003 public static String getMapServiceAccessPoint() {
1004 return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
1005 }
1006
1007 /**
1008 * <p>
1009 * shouldConnectAtStartUp
1010 * </p>
1011 *
1012 * @return a boolean.
1013 */
1014 public static boolean shouldConnectAtStartUp() {
1015 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
1016 //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
1017 return false;
1018 }
1019
1020 /**
1021 * <p>
1022 * getDefaultFeatureTreeForTextualDescription
1023 * </p>
1024 *
1025 * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object.
1026 */
1027 public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
1028 String uuidString = getStringValue(
1029 FEATURE_TREE_DEFAULT_TEXT);
1030 if (StringUtils.isBlank(uuidString)) {
1031 return null;
1032 }
1033 FeatureTree tree = CdmStore.getService(
1034 IFeatureTreeService.class).load(UUID.fromString(uuidString));
1035 if (tree.getId() == 0) {
1036 return null;
1037 }
1038 return tree;
1039 }
1040
1041 /**
1042 * <p>
1043 * getDefaultFeatureTreeForStructuredDescription
1044 * </p>
1045 *
1046 * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object.
1047 */
1048 public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
1049 String uuidString = getStringValue(
1050 FEATURE_TREE_DEFAULT_STRUCTURE);
1051 return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
1052 IFeatureTreeService.class).load(UUID.fromString(uuidString));
1053 }
1054
1055 /**
1056 * <p>
1057 * setSortRanksHierarchichally
1058 * </p>
1059 *
1060 * @param selection
1061 * a boolean.
1062 */
1063 public static void setSortRanksHierarchichally(boolean selection) {
1064 setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
1065 }
1066
1067 /**
1068 * <p>
1069 * getSortRanksHierarchichally
1070 * </p>
1071 *
1072 * @return a boolean.
1073 */
1074 public static boolean getSortRanksHierarchichally() {
1075 return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
1076 }
1077
1078 public static boolean isMultilanguageTextEditingCapability() {
1079 return getBooleanValue(
1080 MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
1081 }
1082
1083 public static Language getGlobalLanguage() {
1084
1085
1086 String languageUuidString = getStringValue(
1087 GLOBAL_LANGUAGE_UUID);
1088
1089 if(!CdmStore.isActive()) {
1090 MessagingUtils.noDataSourceWarningDialog(languageUuidString);
1091 return null;
1092 }
1093
1094 if (CdmUtils.isBlank(languageUuidString)) {
1095 return Language.getDefaultLanguage();
1096 }
1097
1098 UUID languageUuid = UUID.fromString(languageUuidString);
1099 return (Language) CdmStore.getService(ITermService.class).load(
1100 languageUuid);
1101 }
1102
1103 public static void setGlobalLanguage(Language language) {
1104 if(language != null) {
1105 setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
1106 CdmStore.setDefaultLanguage(language);
1107 }
1108
1109 }
1110
1111 /**
1112 * @return
1113 */
1114 public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
1115 List<MarkerType> markerTypes = CdmStore.getTermManager()
1116 .getPreferredTerms(MarkerType.class);
1117
1118 Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
1119
1120 for (MarkerType markerType : markerTypes) {
1121 String name = getMarkerTypeEditingPreferenceKey(markerType);
1122 Boolean value = getBooleanValue(name);
1123
1124 result.put(markerType, value);
1125 }
1126
1127 return result;
1128 }
1129
1130 /**
1131 * @param markerTypeEditingMap
1132 */
1133 public static void setEditMarkerTypePreferences(
1134 Map<MarkerType, Boolean> markerTypeEditingMap) {
1135 for (MarkerType markerType : markerTypeEditingMap.keySet()) {
1136 String name = getMarkerTypeEditingPreferenceKey(markerType);
1137 setBooleanValue(name,
1138 markerTypeEditingMap.get(markerType));
1139 }
1140
1141 }
1142
1143 private static String getMarkerTypeEditingPreferenceKey(
1144 MarkerType markerType) {
1145 markerType = HibernateProxyHelper.deproxy(markerType);
1146 return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
1147 }
1148
1149 /**
1150 * <p>
1151 * setEditMarkerTypePreference
1152 * </p>
1153 *
1154 * @param input
1155 * a {@link org.eclipse.ui.IEditorInput} object.
1156 * @param markerType
1157 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
1158 * @param edit
1159 * a boolean.
1160 */
1161 public static void setEditMarkerTypePreference(MarkerType markerType,
1162 boolean edit) {
1163 setBooleanValue(
1164 getMarkerTypeEditingPreferenceKey(markerType), edit);
1165 }
1166
1167 /**
1168 * @return
1169 */
1170 public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
1171 DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
1172 .NewInstance();
1173 configurator.setMoveDerivedUnitMediaToGallery(true);
1174 configurator.setMoveFieldObjectMediaToGallery(true);
1175 return configurator;
1176 }
1177
1178 /**
1179 * This method will write language properties to the config.ini located in the configuration folder
1180 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
1181 *
1182 * @param setLanguage 0 is for german and 1 for english.
1183 * @throws IOException
1184 */
1185 public void writePropertyToConfigFile(int setLanguage) throws IOException {
1186 File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
1187 //give warning to user if the directory has no write access
1188 if(file == null){
1189 throw new IOException();
1190 }
1191 Properties properties = load(file.getAbsolutePath()+"/config.ini");
1192 switch(setLanguage){
1193 case 0:
1194 properties.setProperty("osgi.nl", "de");
1195 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
1196 break;
1197 case 1:
1198 properties.setProperty("osgi.nl", "en");
1199 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
1200 break;
1201 default:
1202 break;
1203 }
1204 save(file+"/config.ini", properties);
1205 }
1206
1207 /**
1208 * This method loads a property from a given file and returns it.
1209 *
1210 * @param filename
1211 * @return
1212 * @throws IOException
1213 */
1214 private Properties load(String filename) throws IOException {
1215 FileInputStream in = new FileInputStream(filename);
1216 Properties prop = new Properties();
1217 prop.load(in);
1218 in.close();
1219 return prop;
1220 }
1221
1222 /**
1223 * This method saves a property to the specified file.
1224 *
1225 * @param filename
1226 * @param properties
1227 * @throws IOException
1228 */
1229 private void save(String filename, Properties properties) throws IOException{
1230 FileOutputStream fos = new FileOutputStream(filename);
1231 properties.store(fos, "");
1232 fos.close();
1233 }
1234
1235 /**
1236 * Saves a list of P2 Metadata Repositories as string with specified delimiters
1237 *
1238 * @param p2Repos
1239 */
1240 public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
1241 StringBuilder sb = new StringBuilder();
1242 for(MetadataRepositoryElement p2Repo : p2Repos) {
1243 sb.append(P2_REPOSITORIES_DELIM);
1244 if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
1245 sb.append("-");
1246 } else {
1247 sb.append(p2Repo.getName());
1248 }
1249 sb.append(P2_REPOSITORY_FIELDS_DELIM);
1250 sb.append(p2Repo.getLocation().toString());
1251 sb.append(P2_REPOSITORY_FIELDS_DELIM);
1252 sb.append(String.valueOf(p2Repo.isEnabled()));
1253 }
1254 getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
1255 }
1256
1257
1258 /**
1259 * Retrieves a list of previously saved P2 repositories
1260 *
1261 * @return
1262 */
1263 public static List<MetadataRepositoryElement> getP2Repositories() {
1264 List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
1265 String p2ReposPref = getStringValue(P2_REPOSITORY_LIST);
1266 if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
1267 StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
1268
1269 while(p2ReposPrefST.hasMoreTokens()) {
1270 String p2RepoStr = p2ReposPrefST.nextToken();
1271 StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
1272 if(p2ReposStrST.countTokens()==3) {
1273 String nickname = p2ReposStrST.nextToken();
1274 URI uri = null;
1275 try {
1276 uri = new URI(p2ReposStrST.nextToken());
1277 } catch (URISyntaxException e) {
1278 continue;
1279 }
1280 boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
1281 MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
1282 mre.setNickname(nickname);
1283 mre.setEnabled(enabled);
1284 p2Repos.add(mre);
1285 }
1286 }
1287 }
1288
1289 return p2Repos;
1290 }
1291
1292 /**
1293 * enables/disables nested composite. <br>
1294 *
1295 * @param ctrl - Composite to be en-/disabeld
1296 * @param enabled - boolean
1297 */
1298 public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
1299 if (ctrl instanceof Composite) {
1300 Composite comp = (Composite) ctrl;
1301 for (Control c : comp.getChildren()) {
1302 recursiveSetEnabled(c, enabled);
1303 }
1304 } else {
1305 ctrl.setEnabled(enabled);
1306 }
1307 }
1308
1309
1310
1311
1312 /**
1313 * @param orderActivated
1314 */
1315 public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
1316 setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
1317
1318 }
1319
1320 /**
1321 * @param orderActivated
1322 */
1323 public static NavigatorOrderEnum getSortNodes() {
1324 return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1325
1326 }
1327
1328 /**
1329 * @param orderActivated
1330 */
1331 public static boolean isNodesSortedNaturally() {
1332 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1333 return value.equals(NavigatorOrderEnum.NaturalOrder);
1334
1335 }
1336
1337 /**
1338 * @param orderActivated
1339 */
1340 public static boolean isNodesSortedByName() {
1341 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1342 return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
1343
1344 }
1345
1346 /**
1347 * @param orderActivated
1348 */
1349 public static boolean isNodesSortedByNameAndRank() {
1350 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1351 return value.equals(NavigatorOrderEnum.RankAndNameOrder);
1352
1353 }
1354 /**
1355 * <p>
1356 * setStoreNavigatorState
1357 * </p>
1358 *
1359 * @param selection
1360 * a boolean.
1361 */
1362 public static boolean isStoreNavigatorState() {
1363 return getBooleanValue(RESTORE_NAVIGATOR_STATE);
1364
1365 }
1366
1367 /**
1368 * <p>
1369 * setStoreNavigatorState
1370 * </p>
1371 *
1372 * @param selection
1373 * a boolean.
1374 */
1375 public static void setStoreNavigatorState(boolean selection) {
1376 setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
1377
1378 }
1379
1380 /**
1381 * @return
1382 */
1383 public static boolean isShowUpWidgetIsDisposedMessages() {
1384 return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1385 }
1386 public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1387 setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1388 }
1389
1390 /**
1391 * @return
1392 */
1393 public static boolean isShowIdInVocabularyInChecklistEditor() {
1394 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1395 if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
1396 return true;
1397 }else{
1398 return false;
1399 }
1400 }
1401 public static boolean isShowSymbol1InChecklistEditor() {
1402 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1403 if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
1404 return true;
1405 }else{
1406 return false;
1407 }
1408 }
1409 public static boolean isShowSymbol2InChecklistEditor() {
1410 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1411 if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
1412 return true;
1413 }else{
1414 return false;
1415 }
1416 }
1417 public static void setAreaDisplayInChecklistEditor(String selection) {
1418 setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
1419 }
1420
1421 public static void setOwnDescriptionForChecklistEditor(boolean selection) {
1422 setBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
1423 }
1424
1425 public static boolean isOwnDescriptionForChecklistEditor() {
1426 return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
1427 }
1428
1429 /**
1430 * @return
1431 */
1432 public static String displayAreaInChecklistEditor() {
1433 String result = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1434 if (StringUtils.isBlank(result)){
1435 return ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()).getKey();
1436 }
1437 return result;
1438 }
1439
1440 /**
1441 * @return
1442 */
1443 public static String displayStatusInChecklistEditor() {
1444 String result = getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
1445 if (StringUtils.isBlank(result)){
1446 return((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey();
1447 }
1448 return result;
1449 }
1450 public static void setDisplayStatusInChecklistEditor(String selection) {
1451 setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
1452
1453 }
1454
1455 /**
1456 * @return
1457 */
1458 public static boolean isShowRankInChecklistEditor() {
1459 return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
1460 }
1461 public static void setShowRankInChecklistEditor(boolean selection) {
1462 setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
1463 }
1464
1465 /**
1466 * @param object
1467 * @param b
1468 * @return
1469 */
1470 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1471 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1472 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1473 CdmPreference preference = null;
1474 String value;
1475 if (!local) {
1476 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
1477 preference = cache.findBestMatching(key);
1478 if (preference == null){
1479 return null;
1480 }
1481
1482 // setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1483 value = preference.getValue();
1484 config.setAllowOverride(preference.isAllowOverride());
1485 //the preference value is build like this:
1486 //<section1>:true;<section2>:false....
1487 }else{
1488 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
1489 }
1490 String [] sections = value.split(";");
1491 Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1492 String[] sectionValues;
1493 for (String sectionValue: sections){
1494 sectionValues = sectionValue.split(":");
1495 sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1496 }
1497
1498 config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1499
1500 config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1501
1502 config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1503 config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1504
1505 config.setLSIDActivated(getValue(sectionMap, "lsid"));
1506
1507 config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1508
1509 config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1510
1511 config.setRankActivated(getValue(sectionMap, "rank"));
1512
1513 config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1514
1515 config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1516
1517 config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1518
1519 config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1520
1521 config.setProtologueActivated(getValue(sectionMap,"protologue"));
1522
1523 config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1524
1525 config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1526
1527 config.setHybridActivated(getValue(sectionMap,"hybrid"));
1528
1529 return config;
1530 }
1531
1532 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
1533 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1534
1535 String value;
1536
1537 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
1538 if (value != null){
1539 String [] sections = value.split(";");
1540 Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1541 String[] sectionValues;
1542 for (String sectionValue: sections){
1543 sectionValues = sectionValue.split(":");
1544 sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1545 }
1546
1547 config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1548
1549 config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1550
1551 config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1552 config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1553
1554 config.setLSIDActivated(getValue(sectionMap, "lsid"));
1555
1556 config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1557
1558 config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1559
1560 config.setRankActivated(getValue(sectionMap, "rank"));
1561
1562 config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1563
1564 config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1565
1566 config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1567
1568 config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1569
1570 config.setProtologueActivated(getValue(sectionMap,"protologue"));
1571
1572 config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1573
1574 config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1575
1576 config.setHybridActivated(getValue(sectionMap,"hybrid"));
1577 }
1578 return config;
1579 }
1580
1581
1582 /**
1583 * @param object
1584 * @param b
1585 * @return
1586 */
1587 public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1588 CdmPreference preference = null;
1589
1590 if (!local) {
1591 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView, config.toString());
1592
1593 setPreferenceToDB(preference);
1594 }
1595 else{
1596 setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
1597 }
1598
1599
1600 }
1601
1602 private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1603 if (sectionMap.containsKey(string)){
1604 return sectionMap.get(string);
1605 }else{
1606 return true;
1607 }
1608
1609 }
1610
1611
1612
1613 /**
1614 * <p>
1615 * setAbcdConfigurator
1616 * </p>
1617 *
1618 * @param preferredConfiguration
1619 * a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1620 * object.
1621 */
1622 public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1623
1624 Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1625 ICdmRepository controller;
1626 controller = CdmStore.getCurrentApplicationConfiguration();
1627 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
1628 CdmPreference preference = null;
1629 if (controller == null){
1630 return null;
1631 }
1632 preference = controller.getPreferenceService().find(key);
1633 if (preference == null){
1634 return config;
1635 } else{
1636 String configString = preference.getValue();
1637 String[] configArray = configString.split(";");
1638
1639 for (String configItem: configArray){
1640 String[] keyValue = configItem.split(":");
1641 String keyString = keyValue[0];
1642 String valueString = null;
1643 if (keyValue.length>1){
1644 valueString = keyValue[1];
1645 }
1646 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1647 config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1648 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1649 config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1650 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1651 config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1652 }else if (keyString.equals("ignoreAuthorship")){
1653 config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1654 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1655 config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1656 }else if (keyString.equals("reuseExistingMetaData")){
1657 config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1658 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1659 config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1660 }else if (keyString.equals("allowReuseOtherClassifications")){
1661 config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1662 }else if (keyString.equals("deduplicateReferences")){
1663 config.setDeduplicateReferences(Boolean.valueOf(valueString));
1664 }else if (keyString.equals("deduplicateClassifications")){
1665 config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1666 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1667 config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1668 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1669 config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1670 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1671 config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1672 }else if (keyString.equals("mapUnitIdToBarcode")){
1673 config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1674 }else if (keyString.equals("overwriteExistingSpecimens")){
1675 config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1676 }else if (keyString.equals("nomenclaturalCode")){
1677 config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1678 }else{
1679 logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1680 }
1681
1682 }
1683 }
1684 return config;
1685 }
1686
1687 public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1688 Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1689
1690 config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1691
1692 config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1693
1694 config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1695 config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1696 config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1697 config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
1698 config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1699 config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1700 config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1701 config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1702 config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1703 config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1704 config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1705 config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1706 config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1707 config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1708 config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1709 config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1710
1711 return config;
1712
1713 }
1714
1715
1716 public static void updateAbcdImportConfigurationPreference() {
1717 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1718
1719 CdmPreference pref = cache.findBestMatching(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig));
1720
1721 if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
1722 resetToDBPreferenceAbcdCOnfigurator();
1723
1724 }
1725 }
1726
1727 public static void resetToDBPreferenceAbcdCOnfigurator(){
1728 Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
1729 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1730 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1731
1732 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1733 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1734 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1735
1736 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1737 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1738 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1739 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1740 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1741 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1742 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1743 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1744 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1745 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1746 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1747 if (config.getNomenclaturalCode() != null){
1748 setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1749 }
1750 }
1751
1752
1753
1754
1755
1756
1757
1758 /**
1759 * @return
1760 */
1761 public static boolean isSortTaxaByRankAndName() {
1762
1763 return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1764 }
1765
1766 /**
1767 * @return
1768 */
1769 public static String getSortNamedAreasInDistributionEditor() {
1770
1771 return getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey());
1772 }
1773
1774 public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
1775 setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
1776
1777 }
1778
1779 /**
1780 * <p>
1781 * setPreferredNamedAreasForDistributionEditor
1782 * </p>
1783 *
1784 * @param saveCheckedElements
1785 * @param saveGrayedElements
1786 */
1787 public static void setLastSelectedReference(
1788 List<String> lastSelectedReferences) {
1789
1790 setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1791 }
1792
1793 /**
1794 * <p>
1795 * setPreferredNamedAreasForDistributionEditor
1796 * </p>
1797 *
1798 * @param saveCheckedElements
1799 * @param saveGrayedElements
1800 */
1801 public static List<String> getLastSelectedReferences() {
1802
1803 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1804 String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
1805 List<String> result = new ArrayList<>();
1806 if (!StringUtils.isBlank(lastSelected)){
1807 Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1808 }
1809 return result;
1810 }
1811
1812
1813 /**
1814 * <p>
1815 * setPreferredNamedAreasForDistributionEditor
1816 * </p>
1817 *
1818 * @param saveCheckedElements
1819 * @param saveGrayedElements
1820 */
1821 public static void setPreferredNamedAreasForDistributionEditor(
1822 String saveCheckedElements, String saveGrayedElements, boolean local) {
1823 if (local){
1824 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
1825
1826 }
1827 else{
1828 CdmPreference preference = null;
1829
1830 if (saveCheckedElements == null){
1831 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1832
1833 if (preference == null){
1834 return ;
1835 } else{
1836 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1837 saveCheckedElements);
1838 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1839 setPreferenceToDB(preference);
1840
1841 }
1842 } else{
1843 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1844 setPreferenceToDB(preference);
1845 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1846 saveCheckedElements);
1847
1848 }
1849 }
1850
1851 }
1852
1853 /**
1854 * @param saveCheckedElements
1855 * @param saveCheckedElements2
1856 * @param b
1857 */
1858 public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1859 boolean local, boolean isOverride) {
1860 if (local){
1861 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
1862 setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
1863 }
1864 else{
1865 ICdmRepository controller;
1866 CdmPreference preference = null;
1867
1868 if (saveCheckedElements == null){
1869 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1870
1871 if (preference == null){
1872 return ;
1873 } else{
1874 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1875 saveCheckedElements);
1876 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1877 preference.setAllowOverride(isOverride);
1878 setPreferenceToDB(preference);
1879 }
1880 } else{
1881 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1882 preference.setAllowOverride(isOverride);
1883 setPreferenceToDB(preference);
1884 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1885 saveCheckedElements);
1886
1887 }
1888 }
1889 }
1890
1891
1892 /**
1893 * @param saveCheckedElements
1894 * @param saveCheckedElements2
1895 * @param b
1896 */
1897 public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1898 if (local){
1899
1900 String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
1901 return pref;
1902 }
1903 else{
1904 CdmPreference preference = null;
1905 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1906 if (preference == null){
1907 return null;
1908 } else{
1909 return preference.getValue();
1910 }
1911
1912 }
1913 }
1914
1915 public static List<UUID> createUUIDListFromStringPref(String prefKey) {
1916 String prefValue = PreferencesUtil.getStringValue(prefKey);
1917 String[] stringArray = prefValue.split(";");
1918 List<UUID> uuidList = new ArrayList();
1919 for (String uuid: stringArray){
1920 if (!StringUtils.isBlank(uuid)){
1921 uuidList.add(UUID.fromString(uuid));
1922 }
1923 }
1924 return uuidList;
1925 }
1926
1927 public static boolean getFilterCommonNameReferences(){
1928 return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1929 }
1930
1931 /**
1932 *
1933 */
1934 public static void updateDBPreferences() {
1935 CdmPreference preference = null;
1936 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1937 cache.getAllTaxEditorDBPreferences();
1938
1939 //ABCD Configurator
1940
1941 updateAbcdImportConfigurationPreference();
1942
1943 //Name Details
1944 NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1945 // if (config != null ){
1946 // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1947 // setPreferredNameDetailsConfiguration(config, false);
1948 // }
1949 // }
1950
1951
1952
1953
1954
1955
1956
1957
1958 }
1959
1960 /**
1961 * @param string
1962 * @param saveCheckedElements
1963 */
1964 public static void setPreferencesToDB(List<CdmPreference> preferences) {
1965
1966 ICdmRepository controller;
1967 try{
1968 if(CdmStore.isActive()){
1969 controller = CdmStore.getCurrentApplicationConfiguration();
1970 for (CdmPreference preference: preferences){
1971
1972 controller.getPreferenceService().set(preference);
1973
1974 CdmPreferenceCache.instance().put(preference);
1975 }
1976 }
1977 }catch(Exception e){
1978 e.printStackTrace();
1979 }
1980 }
1981
1982
1983
1984
1985
1986
1987
1988
1989 }