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