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