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