Project

General

Profile

Download (74.3 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

    
10
package eu.etaxonomy.taxeditor.preference;
11

    
12
import java.io.File;
13
import java.io.FileInputStream;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.net.URI;
17
import java.net.URISyntaxException;
18
import java.util.ArrayList;
19
import java.util.Arrays;
20
import java.util.Collections;
21
import java.util.HashMap;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Properties;
25
import java.util.StringTokenizer;
26
import java.util.UUID;
27

    
28
import org.apache.commons.lang.StringUtils;
29
import org.apache.log4j.Logger;
30
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
31
import org.eclipse.jface.preference.IPreferenceStore;
32
import org.eclipse.jface.window.Window;
33
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Control;
35
import org.eclipse.swt.widgets.Shell;
36
import org.eclipse.ui.PlatformUI;
37

    
38
import eu.etaxonomy.cdm.api.application.ICdmRepository;
39
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
40
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
41
import eu.etaxonomy.cdm.api.service.ITermService;
42
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
43
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
44
import eu.etaxonomy.cdm.common.CdmUtils;
45
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
47
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
48
import eu.etaxonomy.cdm.model.common.ICdmBase;
49
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
50
import eu.etaxonomy.cdm.model.common.ISimpleTerm;
51
import eu.etaxonomy.cdm.model.common.Language;
52
import eu.etaxonomy.cdm.model.common.MarkerType;
53
import eu.etaxonomy.cdm.model.common.TermBase;
54
import eu.etaxonomy.cdm.model.common.TermType;
55
import eu.etaxonomy.cdm.model.description.FeatureTree;
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.name.NomenclaturalCode;
62
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
63
import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
64
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
65
import eu.etaxonomy.cdm.strategy.match.MatchException;
66
import eu.etaxonomy.cdm.strategy.match.MatchMode;
67
import eu.etaxonomy.taxeditor.model.AbstractUtility;
68
import eu.etaxonomy.taxeditor.model.MessagingUtils;
69
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
70
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
71
import eu.etaxonomy.taxeditor.store.CdmStore;
72
import eu.etaxonomy.taxeditor.store.TermStore;
73
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
74
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
75

    
76
/**
77
 * <p>
78
 * PreferencesUtil class.
79
 * </p>
80
 *
81
 * @author p.ciardelli
82
 * @author n.hoffmann
83
 * @created 05.12.2008
84
 */
85
public class PreferencesUtil implements IPreferenceKeys {
86

    
87
	/**
88
	 *
89
	 */
90
	public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
91

    
92
	public static final String P2_REPOSITORIES_DELIM = ",";
93
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
94

    
95
	private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
96

    
97

    
98

    
99
	/**
100
	 * <p>
101
	 * getPreferenceStore
102
	 * </p>
103
	 *
104
	 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
105
	 */
106
	public static IPreferenceStore getPreferenceStore() {
107
		return TaxeditorStorePlugin.getDefault().getPreferenceStore();
108
	}
109

    
110
	private static String prefKey(String name) {
111
	    return name + "_"+  ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
112
	}
113

    
114
	/**
115
     * <p>
116
     * setStringValue
117
     * </p>
118
     *
119
     *
120
     **/
121
    public static void setStringValue(String name, String value) {
122
        getPreferenceStore().setValue(prefKey(name), value);
123
    }
124

    
125
    /**
126
     * <p>
127
     * setIntValue
128
     * </p>
129
     *
130
     *
131
     **/
132
    public static void setIntValue(String name, int value) {
133
        getPreferenceStore().setValue(prefKey(name), value);
134
    }
135

    
136
    /**
137
     * <p>
138
     * setBooleanValue
139
     * </p>
140
     *
141
     *
142
     **/
143
    public static void setBooleanValue(String name, boolean value) {
144
        getPreferenceStore().setValue(prefKey(name), value);
145
    }
146

    
147
    /**
148
     * <p>
149
     * setBooleanValue
150
     * </p>
151
     *
152
     *
153
     **/
154
    public static void setDoubleValue(String name, double value) {
155
        getPreferenceStore().setValue(prefKey(name), value);
156
    }
157

    
158
    /**
159
     * <p>
160
     * setFloatValue
161
     * </p>
162
     *
163
     *
164
     **/
165
    public static void setFloatValue(String name, float value) {
166
        getPreferenceStore().setValue(name + ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(), value);
167
    }
168

    
169
    /**
170
     * <p>
171
     * setFloatValue
172
     * </p>
173
     *
174
     *
175
     **/
176
    public static void setLongValue(String name, long value) {
177
        getPreferenceStore().setValue(prefKey(name), value);
178
    }
179

    
180
    /**
181
     * <p>
182
     * setStringValue
183
     * </p>
184
     *
185
     *
186
     **/
187
    public static String getStringValue(String name) {
188

    
189
        String dbSpecific = prefKey(name);
190
        if (getPreferenceStore().contains(dbSpecific)){
191
            return getPreferenceStore().getString(dbSpecific);
192
        }else{
193
            return getPreferenceStore().
194
                    getString(name);
195
        }
196

    
197
    }
198

    
199
    /**
200
     * <p>
201
     * setIntValue
202
     * </p>
203
     *
204
     *
205
     **/
206
    public static int getIntValue(String name) {
207
        String dbSpecific = prefKey(name);
208
        if (getPreferenceStore().contains(dbSpecific)){
209
            return getPreferenceStore().getInt(dbSpecific);
210
        }else{
211
            return getPreferenceStore().
212
                    getInt(name);
213
        }
214

    
215
    }
216

    
217
    /**
218
     * <p>
219
     * setBooleanValue
220
     * </p>
221
     *
222
     *
223
     **/
224
    public static boolean getBooleanValue(String name) {
225
        if (CdmStore.isActive()){
226
            String dbSpecific = prefKey(name);
227
            if (getPreferenceStore().contains(dbSpecific)){
228
                return getPreferenceStore().getBoolean(dbSpecific);
229
            }else{
230
                return getPreferenceStore().
231
                        getBoolean(name);
232
            }
233

    
234
        }else{
235

    
236
            return getPreferenceStore().getBoolean(name);
237
        }
238

    
239
    }
240

    
241
    /**
242
     * <p>
243
     * setBooleanValue
244
     * </p>
245
     *
246
     *
247
     **/
248
    public static double getDoubleValue(String name) {
249
        String dbSpecific = prefKey(name);
250
        if (getPreferenceStore().contains(dbSpecific)){
251
            return getPreferenceStore().getDouble(dbSpecific);
252
        }else{
253
            return getPreferenceStore().
254
                    getDouble(name);
255
        }
256

    
257
    }
258

    
259
    /**
260
     * <p>
261
     * getFloatValue
262
     * </p>
263
     *
264
     *
265
     **/
266
    public static float getFloatValue(String name) {
267
        String dbSpecific = prefKey(name);
268
        if (getPreferenceStore().contains(dbSpecific)){
269
            return getPreferenceStore().getFloat(dbSpecific);
270
        }else{
271
            return getPreferenceStore().
272
                    getFloat(name);
273
        }
274

    
275
    }
276

    
277
    /**
278
     * <p>
279
     * getLongValue
280
     * </p>
281
     *
282
     *
283
     **/
284
    public static long getLongValue(String name) {
285
        String dbSpecific = prefKey(name);
286
        if (getPreferenceStore().contains(dbSpecific)){
287
            return getPreferenceStore().getLong(dbSpecific);
288
        }else{
289
            return getPreferenceStore().
290
                    getLong(name);
291
        }
292
    }
293

    
294

    
295
	/**
296
	 * <p>
297
	 * setPreferredNomenclaturalCode
298
	 * </p>
299
	 *
300
	 * @param preferredCode
301
	 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
302
	 *            object.
303
	 */
304
	public static CdmPreference setPreferredNomenclaturalCode(
305
			String preferenceKey, boolean local) {
306
	    if (local){
307
	        setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
308
	                preferenceKey);
309
	    }
310
	    else{
311
    		ICdmRepository controller;
312
    		controller = CdmStore.getCurrentApplicationConfiguration();
313
    		if (controller == null){
314
                return null;
315
            }
316
    		PrefKey key = null;
317
    		try{
318
    		    key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
319
    		}catch (Exception e){
320
    		    System.out.println(e.getStackTrace());
321
    		}
322
    		CdmPreference preference = null;
323

    
324
    		if (preferenceKey == null){
325
    			preference = controller.getPreferenceService().find(key);
326
    			if (preference == null){
327
    				return null;
328
    			} else{
329
    			    setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
330
    				        preference.getValue());
331
    			    setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
332
    				return preference;
333
    			}
334
    		} else{
335
    			preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceKey);
336
    			controller.getPreferenceService().set(preference);
337

    
338
    		}
339
	    }
340
        return null;
341

    
342

    
343

    
344
	}
345

    
346
	public static NomenclaturalCode getPreferredNomenclaturalCode(){
347
	    if (getBooleanValue(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
348
            return getPreferredNomenclaturalCode(true);
349
        } else{
350
            return getPreferredNomenclaturalCode(false);
351
        }
352
	}
353

    
354
	/**
355
	 * <p>
356
	 * getPreferredNomenclaturalCode
357
	 * </p>
358
	 *
359
	 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
360
	 */
361
	public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
362

    
363
		CdmPreference pref = null;
364
		if (!useLocal){
365
		    pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
366
		}
367

    
368
	    String preferredCode;
369
	    if(pref == null){
370
	    	preferredCode = getStringValue(
371
					PREFERRED_NOMENCLATURAL_CODE_KEY);
372

    
373
	    }else{
374
	    	preferredCode = pref.getValue();
375
	    }
376

    
377
	    return getPreferredNomenclaturalCode(preferredCode);
378

    
379
	}
380

    
381
	/**
382
     * <p>
383
     * getPreferredNomenclaturalCode
384
     * </p>
385
     *
386
     * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
387
     */
388
    public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
389

    
390
        for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
391
            if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
392
                return code;
393
            }
394
        }
395
        return null;
396
    }
397

    
398
	public static boolean isShowTaxonAssociations(){
399
        if (getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) && getBooleanValue(SHOW_TAXON_ASSOCIATIONS_ALLOW_OVERRIDE)) {
400
            return getBooleanValue(SHOW_TAXON_ASSOCIATIONS);
401
        } else{
402
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
403

    
404
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
405
        }
406
    }
407

    
408
	public static boolean isShowLifeForm(){
409
        if (getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) && getBooleanValue(SHOW_LIFE_FORM_ALLOW_OVERRIDE)) {
410
            return getBooleanValue(SHOW_LIFE_FORM);
411
        } else{
412
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
413

    
414
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
415
        }
416
    }
417

    
418
	public static boolean isDeterminationOnlyForFieldUnits(){
419
        if (getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) && getBooleanValue(DETERMINATIONS_ONLY_FOR_FIELDUNITS_ALLOW_OVERRIDE)) {
420
            return getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS);
421
        } else{
422
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
423

    
424
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
425
        }
426
    }
427

    
428
	public static boolean isCollectingAreaInGeneralSection(){
429
        if (getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) && getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_ALLOW_OVERRIDE)) {
430
            return getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
431
        } else{
432
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
433

    
434
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
435
        }
436
    }
437

    
438
	public static boolean isShowSimpleDetailsView(){
439
        if (getBooleanValue(OVERRIDE_NAME_DETAILS) && getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)) {
440
            return getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION);
441
        } else{
442
            CdmPreference pref = getPreferenceFromDB(EditorPreferencePredicate.NameDetailsView);
443

    
444
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
445
        }
446
    }
447

    
448

    
449

    
450
    public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
451
        ICdmRepository controller;
452
        CdmPreference pref = null;
453

    
454
        try{
455
            if(CdmStore.isActive()){
456
                controller = CdmStore.getCurrentApplicationConfiguration();
457
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
458
                pref = controller.getPreferenceService().find(key);
459
            }
460
        }catch(Exception e){
461
            e.printStackTrace();
462
        }
463

    
464
        return pref;
465

    
466
    }
467

    
468
    public static void setPreferenceToDB(CdmPreference preference){
469
        ICdmRepository controller;
470
        try{
471
            if(CdmStore.isActive()){
472
                controller = CdmStore.getCurrentApplicationConfiguration();
473
                controller.getPreferenceService().set(preference);
474
            }
475
        }catch(Exception e){
476
            e.printStackTrace();
477
        }
478

    
479
    }
480

    
481

    
482

    
483
	public static String getPreferredDefaultLangugae(){
484
	    String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
485
	    if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
486
	        return preferredLanguage;
487
	    }
488
	    return null;
489
	}
490

    
491
	public static boolean isShowMediaPreview(){
492
        boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
493
        return isShowMediaPreview;
494
    }
495

    
496
	/**
497
	 * Get the match strategy for the given class that was stored in preferences
498
	 * or the default strategy if it was not stored in preferences
499
	 *
500
	 * @param clazz
501
	 *            a {@link java.lang.Class} object.
502
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
503
	 */
504
	public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
505
		String className = clazz.getName();
506
		if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
507
			IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
508

    
509
			//TODO CacheMatchers (or multiple field matchers in future) are missing here
510
			for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
511
				String fieldName = fieldMatcher.getPropertyName();
512
				String matchModeName = getStringValue(
513
						getMatchStrategyFieldName(className, fieldName));
514
				MatchMode matchMode = MatchMode.valueOf(matchModeName);
515
				try {
516
					matchStrategy.setMatchMode(fieldName, matchMode);
517
				} catch (MatchException e) {
518
					MessagingUtils.error(PreferencesUtil.class, e);
519
					throw new RuntimeException(e);
520
				}
521
			}
522

    
523
			return matchStrategy;
524
		}
525
		return getDefaultMatchStrategy(clazz);
526
	}
527

    
528
	/**
529
	 * Stores a matchStrategy into the preference store.
530
	 *
531
	 * @param matchStrategy
532
	 *            a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
533
	 *            object.
534
	 */
535
	public static void setMatchStrategy(IMatchStrategy matchStrategy) {
536
		String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
537
		setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
538

    
539
		List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
540

    
541
		for (FieldMatcher fieldMatcher : fieldMatchers) {
542
			String fieldName = fieldMatcher.getPropertyName();
543
			setStringValue(
544
					getMatchStrategyFieldName(className, fieldName),
545
					fieldMatcher.getMatchMode().name());
546
		}
547
	}
548

    
549
	/**
550
	 * Helper method to create the preference property for a match field.
551
	 *
552
	 * @param className
553
	 * @param fieldName
554
	 * @return
555
	 */
556
	private static String getMatchStrategyFieldName(String className,
557
			String fieldName) {
558
		return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
559
	}
560

    
561
	/**
562
	 * Returns the default match strategy for a given class.
563
	 *
564
	 * @param clazz
565
	 *            a {@link java.lang.Class} object.
566
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
567
	 */
568
	public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
569
		return DefaultMatchStrategy.NewInstance(clazz);
570
	}
571

    
572
	/**
573
	 * <p>
574
	 * getDateFormatPattern
575
	 * </p>
576
	 *
577
	 * @return a {@link java.lang.String} object.
578
	 */
579
	public static String getDateFormatPattern() {
580
		// TODO make this configurable in properties
581
		String pattern = "Y-M-d H:m";
582
		return pattern;
583
	}
584

    
585
	/**
586
	 * <p>
587
	 * addTermToPreferredTerms
588
	 * </p>
589
	 *
590
	 * @param term
591
	 *            a T object.
592
	 * @param <T>
593
	 *            a T object.
594
	 */
595
	public static <T extends TermBase> void addTermToPreferredTerms(T term) {
596

    
597
		// VocabularyEnum vocabulary =
598
		// VocabularyEnum.getVocabularyEnum(term.getClass());
599
		//
600
		// getPreferenceStore().setValue(getPreferenceKey(term),
601
		// VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
602
		//
603
		// firePreferencesChanged(term.getClass());
604
	}
605

    
606
	/**
607
	 * Construct a unique key using the CdmBase object's uuid
608
	 *
609
	 * @param cdmBase
610
	 * @return
611
	 */
612
	private static String getPreferenceKey(ICdmBase cdmBase) {
613
		cdmBase = HibernateProxyHelper.deproxy(cdmBase);
614

    
615
		String key = cdmBase.getClass().getName().concat(".")
616
				.concat(cdmBase.getUuid().toString());
617
		if (key.contains("javassist")) {
618
			MessagingUtils.info("proxy");
619
		}
620
		return key;
621
	}
622

    
623
	/**
624
	 * Construct a unique key using the CdmBase object's uuid
625
	 *
626
	 * @param cdmBase
627
	 * @return
628
	 */
629
	public static String getPreferenceKey(ISimpleTerm simpleTerm) {
630
		simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
631
		String key = simpleTerm.getClass().getName().concat(".")
632
				.concat(simpleTerm.getUuid().toString());
633
		if (key.contains("javassist")) {
634
			MessagingUtils.warn(PreferencesUtil.class,
635
					"Trying to persist a preference based on a proxy class.");
636
		}
637
		return key;
638
	}
639

    
640

    
641

    
642
	/**
643
	 * Construct a unique key using the CdmBase object's uuid
644
	 *
645
	 * @param cdmBase
646
	 * @return
647
	 */
648
	public static String getPreferenceKey(IDefinedTerm definedTerm) {
649
		definedTerm = HibernateProxyHelper.deproxy(definedTerm);
650
		String key = definedTerm.getClass().getName().concat(".")
651
				.concat(definedTerm.getUuid().toString());
652
		if (key.contains("javassist")) {
653
			MessagingUtils.warn(PreferencesUtil.class,
654
					"Trying to persist a preference based on a proxy class.");
655
		}
656
		return key;
657
	}
658

    
659
	/**
660
	 * Retrieves search preferences from the preference store
661
	 *
662
	 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
663
	 */
664
	public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
665
		IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
666

    
667
		configurator.setDoTaxa(getBooleanValue(
668
				TAXON_SERVICE_CONFIGURATOR_TAXA));
669
		configurator.setDoSynonyms(getBooleanValue(
670
				TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
671
		configurator.setDoNamesWithoutTaxa(getBooleanValue(
672
				TAXON_SERVICE_CONFIGURATOR_NAMES));
673
		configurator.setDoTaxaByCommonNames(getBooleanValue(
674
				TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
675
		//configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
676

    
677
		return configurator;
678
	}
679

    
680
	/**
681
	 * create new preferences, setting all search options to true
682
	 *
683
	 * @return a
684
	 *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
685
	 *         object.
686
	 */
687
	public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
688
		IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
689

    
690
		configurator.setDoTaxa(true);
691
		configurator.setDoSynonyms(true);
692
		configurator.setDoNamesWithoutTaxa(true);
693
		configurator.setDoTaxaByCommonNames(true);
694

    
695
		configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
696
				"name", "name.$", "relationsFromThisTaxon.$"));
697

    
698
		configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
699
				"name", "name.$", "synonyms.relatedTo.*"));
700

    
701
		// DEFAULT VALUES
702
		// match mode is a simple like, actually all other match modes are kind
703
		// of bogus
704
		configurator
705
				.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
706
		// we set page number and size here as this should always be unlimited
707
		configurator.setPageNumber(0);
708
		// TODO currently limit results to 10000
709
		configurator.setPageSize(10000);
710
		setSearchConfigurator(configurator) ;
711
		return configurator;
712
	}
713

    
714
	/**
715
	 * Store search preferences
716
	 *
717
	 * @param configurator
718
	 *            a
719
	 *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
720
	 *            object.
721
	 */
722
	public static void setSearchConfigurator(
723
			IFindTaxaAndNamesConfigurator configurator) {
724
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
725
				configurator.isDoTaxa());
726
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
727
				configurator.isDoSynonyms());
728
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
729
				configurator.isDoNamesWithoutTaxa());
730
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
731
				configurator.isDoTaxaByCommonNames());
732
	}
733

    
734
	/**
735
	 * <p>
736
	 * firePreferencesChanged
737
	 * </p>
738
	 *
739
	 * @param clazz
740
	 *            a {@link java.lang.Class} object.
741
	 */
742
	public static void firePreferencesChanged(Class clazz) {
743
		getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
744
				null, clazz);
745
	}
746

    
747
	public static String createPreferenceString(String property){
748
	   return prefKey(property);
749

    
750
	}
751

    
752
	/**
753
	 * Set default values for preferences
754
	 */
755
	public static void setDefaults() {
756
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
757
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
758
				true);
759
		getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
760
				"http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
761
		//FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
762
		getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
763
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT),
764
				"http://www.biodiversitylibrary.org/openurl");
765
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000");
766
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000");
767
		//Distribution Editor:
768
		getPreferenceStore().setDefault(createPreferenceString(DISTRIBUTION_AREA_PREFRENCES_ACTIVE), true);
769
		getPreferenceStore().setDefault(createPreferenceString(CHECKLIST_AREA_DISPLAY), CHECKLIST_AREA_DISPLAY_TITLE);
770
		getPreferenceStore().setDefault(createPreferenceString(CHECKLIST_STATUS_DISPLAY), false);
771

    
772

    
773
		//Name Details
774
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS), true);
775
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE), true);
776
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP), true);
777
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_HYBRID), true);
778
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_LSID), true);
779
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP), true);
780
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAMECACHE), true);
781
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE), true);
782
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE), true);
783
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS), true);
784
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE), true);
785
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_RANK), true);
786
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION), true);
787
		//Navigator preferences
788
		getPreferenceStore().setDefault(createPreferenceString(SORT_NODES), NavigatorOrderEnum.RankAndNameOrder.getKey());
789

    
790
		getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
791
		//override db preferences
792
		getPreferenceStore().setDefault(createPreferenceString(ABCD_IMPORT_OVERRIDE), false);
793
		getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN_OVERRIDE), false);
794
		getPreferenceStore().setDefault(createPreferenceString(OVERRIDE_NAME_DETAILS), false);
795
		getPreferenceStore().setDefault(createPreferenceString(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE), false);
796

    
797
		getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
798
		getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN), true);
799
		getPreferenceStore().setDefault(createPreferenceString(SHOW_TAXONNODE_WIZARD), true);
800
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAMESPACE_IN_SOURCE), true);
801
		getPreferenceStore().setDefault(createPreferenceString(SHOW_ID_IN_SOURCE), true);
802
		getPreferenceStore().setDefault(createPreferenceString(DISABLE_MULTI_CLASSIFICATION), false);
803
		getPreferenceStore().setDefault(createPreferenceString(DISABLE_SEC), false);
804
		getPreferenceStore().setDefault(createPreferenceString(SHOW_SEC_DETAILS), true);
805
	}
806

    
807
	/**
808
	 * <p>
809
	 * checkNomenclaturalCode
810
	 * </p>
811
	 */
812
	public static void checkNomenclaturalCode() {
813
		// First time Editor is opened, no nomenclatural code has been set
814
		if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
815
			PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
816
		}
817

    
818

    
819

    
820
	}
821
	public static void setNomenclaturalCodePreferences(){
822
	    ICdmRepository controller;
823
        controller = CdmStore.getCurrentApplicationConfiguration();
824
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
825
        CdmPreference preference = null;
826
        if (controller == null){
827
            return ;
828
        }
829
        preference = controller.getPreferenceService().find(key);
830
        if (preference == null){
831
            return;
832
        }
833
        setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
834

    
835
        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
836
        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
837
        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
838

    
839
        setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
840
                getPreferenceKey(preferredCode));
841

    
842
	}
843

    
844
	public static void checkDefaultLanguage(){
845
	    if(PreferencesUtil.getPreferredDefaultLangugae() == null){
846
	       Shell shell = AbstractUtility.getShell();
847
	       int open = new DefaultLanguageDialog(shell).open();
848
	       if(open == Window.OK){
849
	           PlatformUI.getWorkbench().restart();
850
	       }
851
	    }else{
852
	        //TODO:In case of a reinstall, the config.ini will be overwritten
853
	        //     here you create config.ini with the stored key from preferences
854
	    }
855
	}
856

    
857
	/**
858
	 * <p>
859
	 * getMapServiceAccessPoint
860
	 * </p>
861
	 *
862
	 * @return a {@link java.lang.String} object.
863
	 */
864
	public static String getMapServiceAccessPoint() {
865
		return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
866
	}
867

    
868
	/**
869
	 * <p>
870
	 * shouldConnectAtStartUp
871
	 * </p>
872
	 *
873
	 * @return a boolean.
874
	 */
875
	public static boolean shouldConnectAtStartUp() {
876
		//FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
877
		//return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
878
		return false;
879
	}
880

    
881
	/**
882
	 * <p>
883
	 * getDefaultFeatureTreeForTextualDescription
884
	 * </p>
885
	 *
886
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
887
	 */
888
	public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
889
		String uuidString = getStringValue(
890
				FEATURE_TREE_DEFAULT_TEXT);
891
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
892
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
893
	}
894

    
895
	/**
896
	 * <p>
897
	 * getDefaultFeatureTreeForStructuredDescription
898
	 * </p>
899
	 *
900
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
901
	 */
902
	public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
903
		String uuidString = getStringValue(
904
				FEATURE_TREE_DEFAULT_STRUCTURE);
905
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
906
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
907
	}
908

    
909
	/**
910
	 * <p>
911
	 * setSortRanksHierarchichally
912
	 * </p>
913
	 *
914
	 * @param selection
915
	 *            a boolean.
916
	 */
917
	public static void setSortRanksHierarchichally(boolean selection) {
918
		setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
919
	}
920

    
921
	/**
922
	 * <p>
923
	 * getSortRanksHierarchichally
924
	 * </p>
925
	 *
926
	 * @return a boolean.
927
	 */
928
	public static boolean getSortRanksHierarchichally() {
929
		return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
930
	}
931

    
932
	public static boolean isMultilanguageTextEditingCapability() {
933
		return getBooleanValue(
934
				MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
935
	}
936

    
937
	public static Language getGlobalLanguage() {
938

    
939

    
940
		String languageUuidString = getStringValue(
941
				GLOBAL_LANGUAGE_UUID);
942

    
943
		if(!CdmStore.isActive()) {
944
            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
945
            return null;
946
        }
947

    
948
		if (CdmUtils.isBlank(languageUuidString)) {
949
			return Language.getDefaultLanguage();
950
		}
951

    
952
		UUID languageUuid = UUID.fromString(languageUuidString);
953
		return (Language) CdmStore.getService(ITermService.class).load(
954
				languageUuid);
955
	}
956

    
957
	public static void setGlobalLanguage(Language language) {
958
	    if(language != null) {
959
	        setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
960
	        CdmStore.setDefaultLanguage(language);
961
	    }
962

    
963
	}
964

    
965
	/**
966
	 * @return
967
	 */
968
	public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
969
		List<MarkerType> markerTypes = CdmStore.getTermManager()
970
				.getPreferredTerms(MarkerType.class);
971

    
972
		Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
973

    
974
		for (MarkerType markerType : markerTypes) {
975
			String name = getMarkerTypeEditingPreferenceKey(markerType);
976
			Boolean value = getBooleanValue(name);
977

    
978
			result.put(markerType, value);
979
		}
980

    
981
		return result;
982
	}
983

    
984
	/**
985
	 * @param markerTypeEditingMap
986
	 */
987
	public static void setEditMarkerTypePreferences(
988
			Map<MarkerType, Boolean> markerTypeEditingMap) {
989
		for (MarkerType markerType : markerTypeEditingMap.keySet()) {
990
			String name = getMarkerTypeEditingPreferenceKey(markerType);
991
			setBooleanValue(name,
992
					markerTypeEditingMap.get(markerType));
993
		}
994

    
995
	}
996

    
997
	private static String getMarkerTypeEditingPreferenceKey(
998
			MarkerType markerType) {
999
		markerType = HibernateProxyHelper.deproxy(markerType);
1000
		return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
1001
	}
1002

    
1003
	/**
1004
	 * <p>
1005
	 * setEditMarkerTypePreference
1006
	 * </p>
1007
	 *
1008
	 * @param input
1009
	 *            a {@link org.eclipse.ui.IEditorInput} object.
1010
	 * @param markerType
1011
	 *            a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
1012
	 * @param edit
1013
	 *            a boolean.
1014
	 */
1015
	public static void setEditMarkerTypePreference(MarkerType markerType,
1016
			boolean edit) {
1017
		setBooleanValue(
1018
				getMarkerTypeEditingPreferenceKey(markerType), edit);
1019
	}
1020

    
1021
	/**
1022
	 * @return
1023
	 */
1024
	public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
1025
		DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
1026
				.NewInstance();
1027
		configurator.setMoveDerivedUnitMediaToGallery(true);
1028
		configurator.setMoveFieldObjectMediaToGallery(true);
1029
		return configurator;
1030
	}
1031

    
1032
	/**
1033
	 * This method will write language properties to the config.ini located in the configuration folder
1034
	 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
1035
	 *
1036
	 * @param setLanguage 0 is for german and 1 for english.
1037
	 * @throws IOException
1038
	 */
1039
    public void writePropertyToConfigFile(int setLanguage) throws IOException {
1040
        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
1041
        //give warning to user if the directory has no write access
1042
        if(file == null){
1043
            throw new IOException();
1044
        }
1045
        Properties properties = load(file.getAbsolutePath()+"/config.ini");
1046
        switch(setLanguage){
1047
        case 0:
1048
            properties.setProperty("osgi.nl", "de");
1049
            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
1050
            break;
1051
        case 1:
1052
            properties.setProperty("osgi.nl", "en");
1053
            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
1054
            break;
1055
        default:
1056
            break;
1057
        }
1058
        save(file+"/config.ini", properties);
1059
    }
1060

    
1061
    /**
1062
     * This method loads a property from a given file and returns it.
1063
     *
1064
     * @param filename
1065
     * @return
1066
     * @throws IOException
1067
     */
1068
    private Properties load(String filename) throws IOException {
1069
        FileInputStream in = new FileInputStream(filename);
1070
        Properties prop = new Properties();
1071
        prop.load(in);
1072
        in.close();
1073
        return prop;
1074
    }
1075

    
1076
    /**
1077
     * This method saves a property to the specified file.
1078
     *
1079
     * @param filename
1080
     * @param properties
1081
     * @throws IOException
1082
     */
1083
    private void save(String filename, Properties properties) throws IOException{
1084
        FileOutputStream fos =  new FileOutputStream(filename);
1085
        properties.store(fos, "");
1086
        fos.close();
1087
    }
1088

    
1089
    /**
1090
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
1091
     *
1092
     * @param p2Repos
1093
     */
1094
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
1095
        StringBuilder sb = new StringBuilder();
1096
        for(MetadataRepositoryElement p2Repo : p2Repos) {
1097
            sb.append(P2_REPOSITORIES_DELIM);
1098
            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
1099
                sb.append("-");
1100
            } else {
1101
                sb.append(p2Repo.getName());
1102
            }
1103
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
1104
            sb.append(p2Repo.getLocation().toString());
1105
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
1106
            sb.append(String.valueOf(p2Repo.isEnabled()));
1107
        }
1108
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
1109
    }
1110

    
1111

    
1112
    /**
1113
     * Retrieves a list of previously saved P2 repositories
1114
     *
1115
     * @return
1116
     */
1117
    public static List<MetadataRepositoryElement> getP2Repositories() {
1118
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
1119
        String p2ReposPref =  getStringValue(P2_REPOSITORY_LIST);
1120
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
1121
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
1122

    
1123
            while(p2ReposPrefST.hasMoreTokens()) {
1124
                String p2RepoStr = p2ReposPrefST.nextToken();
1125
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
1126
                if(p2ReposStrST.countTokens()==3) {
1127
                    String nickname = p2ReposStrST.nextToken();
1128
                    URI uri = null;
1129
                    try {
1130
                        uri = new URI(p2ReposStrST.nextToken());
1131
                    } catch (URISyntaxException e) {
1132
                        continue;
1133
                    }
1134
                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
1135
                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
1136
                    mre.setNickname(nickname);
1137
                    mre.setEnabled(enabled);
1138
                    p2Repos.add(mre);
1139
                }
1140
            }
1141
        }
1142

    
1143
        return p2Repos;
1144
    }
1145

    
1146
    /**
1147
     * enables/disables nested composite. <br>
1148
     *
1149
     * @param ctrl - Composite to be en-/disabeld
1150
     * @param enabled - boolean
1151
     */
1152
    public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
1153
        if (ctrl instanceof Composite) {
1154
            Composite comp = (Composite) ctrl;
1155
            for (Control c : comp.getChildren()) {
1156
                recursiveSetEnabled(c, enabled);
1157
            }
1158
        } else {
1159
            ctrl.setEnabled(enabled);
1160
        }
1161
    }
1162

    
1163

    
1164

    
1165

    
1166
    /**
1167
     * @param orderActivated
1168
     */
1169
    public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
1170
        setStringValue(SORT_NODES, nodesOrder.key);
1171

    
1172
    }
1173

    
1174
    /**
1175
     * @param orderActivated
1176
     */
1177
    public static NavigatorOrderEnum getSortNodes() {
1178
        return NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1179

    
1180
    }
1181

    
1182
    /**
1183
     * @param orderActivated
1184
     */
1185
    public static boolean isNodesSortedNaturally() {
1186
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1187
        return value.equals(NavigatorOrderEnum.NaturalOrder);
1188

    
1189
    }
1190

    
1191
    /**
1192
     * @param orderActivated
1193
     */
1194
    public static boolean isNodesSortedByName() {
1195
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1196
        return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
1197

    
1198
    }
1199

    
1200
    /**
1201
     * @param orderActivated
1202
     */
1203
    public static boolean isNodesSortedByNameAndRank() {
1204
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1205
        return value.equals(NavigatorOrderEnum.RankAndNameOrder);
1206

    
1207
    }
1208
	/**
1209
	 * <p>
1210
	 * setStoreNavigatorState
1211
	 * </p>
1212
	 *
1213
	 * @param selection
1214
	 *            a boolean.
1215
	 */
1216
	public static boolean isStoreNavigatorState() {
1217
		return getBooleanValue(RESTORE_NAVIGATOR_STATE);
1218

    
1219
	}
1220

    
1221
	/**
1222
	 * <p>
1223
	 * setStoreNavigatorState
1224
	 * </p>
1225
	 *
1226
	 * @param selection
1227
	 *            a boolean.
1228
	 */
1229
	public static void setStoreNavigatorState(boolean selection) {
1230
		setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
1231

    
1232
	}
1233

    
1234
    /**
1235
     * @return
1236
     */
1237
    public static boolean isShowUpWidgetIsDisposedMessages() {
1238
       return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1239
    }
1240
    public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1241
        setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1242
    }
1243

    
1244
    /**
1245
     * @return
1246
     */
1247
    public static boolean isShowIdInVocabularyInChecklistEditor() {
1248
        String area_display = getStringValue(IPreferenceKeys.CHECKLIST_AREA_DISPLAY);
1249
        if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
1250
            return true;
1251
        }else{
1252
            return false;
1253
        }
1254
    }
1255
    public static boolean isShowSymbol1InChecklistEditor() {
1256
        String area_display = getStringValue(IPreferenceKeys.CHECKLIST_AREA_DISPLAY);
1257
        if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
1258
            return true;
1259
        }else{
1260
            return false;
1261
        }
1262
     }
1263
    public static boolean isShowSymbol2InChecklistEditor() {
1264
        String area_display = getStringValue(IPreferenceKeys.CHECKLIST_AREA_DISPLAY);
1265
        if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
1266
            return true;
1267
        }else{
1268
            return false;
1269
        }
1270
     }
1271
    public static void setAreaDisplayInChecklistEditor(String selection) {
1272
        setStringValue(CHECKLIST_AREA_DISPLAY, selection);
1273
    }
1274

    
1275
    /**
1276
     * @return
1277
     */
1278
    public static String displayStatusInChecklistEditor() {
1279
       return getStringValue(IPreferenceKeys.CHECKLIST_STATUS_DISPLAY);
1280
    }
1281
    public static void setDisplayStatusInChecklistEditor(String selection) {
1282
        setStringValue(CHECKLIST_STATUS_DISPLAY, selection);
1283
    }
1284

    
1285
    /**
1286
     * @return
1287
     */
1288
    public static boolean isShowRankInChecklistEditor() {
1289
        return getBooleanValue(IPreferenceKeys.CHECKLIST_SHOW_RANK);
1290
    }
1291
    public static void setShowRankInChecklistEditor(boolean selection) {
1292
       setBooleanValue(CHECKLIST_SHOW_RANK, selection);
1293
    }
1294

    
1295
    /**
1296
     * @param object
1297
     * @param b
1298
     * @return
1299
     */
1300
    public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1301
        NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1302

    
1303
        CdmPreference preference = null;
1304

    
1305
        if (!local) {
1306
            preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
1307
            if (preference == null){
1308
                return null;
1309
            }
1310

    
1311
            setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1312

    
1313
            //the preference value is build like this:
1314
            //<section1>:true;<section2>:false....
1315

    
1316
            String value = preference.getValue();
1317
            String [] sections = value.split(";");
1318
            Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1319
            String[] sectionValues;
1320
            for (String sectionValue: sections){
1321
                sectionValues = sectionValue.split(":");
1322
                sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1323
            }
1324
            config.setAllowOverride(preference.isAllowOverride());
1325
            config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1326

    
1327
    //        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
1328
    //                (getValue(sectionMap, "taxon")));
1329
            config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1330

    
1331
            config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecEnabled"));
1332
            config.setSecEnabled(getValue(sectionMap, "taxon.SecDetails"));
1333

    
1334
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
1335
    //                (getValue(sectionMap, "lsid")));
1336
            config.setLSIDActivated(getValue(sectionMap, "lsid"));
1337

    
1338
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1339
    //                (getValue(sectionMap, "nc")));
1340
            config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1341

    
1342
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1343
    //                (getValue(sectionMap, "ap")));
1344
            config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1345

    
1346
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
1347
    //                (getValue(sectionMap, "rank")));
1348
            config.setRankActivated(getValue(sectionMap, "rank"));
1349

    
1350

    
1351
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1352
    //                (getValue(sectionMap, "atomisedEpithets")));
1353
            config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1354

    
1355
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1356
    //                (getValue(sectionMap,"author")));
1357
            config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1358

    
1359
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1360
    //                (getValue(sectionMap, "nomRef")));
1361
            config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1362

    
1363
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1364
    //                (getValue(sectionMap, "nomStat")));
1365
            config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1366

    
1367

    
1368
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1369
    //                (getValue(sectionMap,"protologue")));
1370
            config.setProtologueActivated(getValue(sectionMap,"protologue"));
1371

    
1372
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1373
    //                (getValue(sectionMap,"typeDes")));
1374
            config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1375

    
1376
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1377
    //                (getValue(sectionMap,"nameRelation")));
1378
            config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1379

    
1380
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
1381
    //                (getValue(sectionMap, "hybrid")));
1382
            config.setHybridActivated(getValue(sectionMap,"hybrid"));
1383
        }else{
1384
            config.setSimpleDetailsViewActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION));
1385
            config.setTaxonSectionActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON));
1386
            config.setSecDetailsActivated(getBooleanValue(SHOW_SEC_DETAILS));
1387
            config.setSecEnabled(getBooleanValue(DISABLE_SEC));
1388
            config.setLSIDActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID));
1389
            config.setNomenclaturalCodeActived(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1390
            config.setAppendedPhraseActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1391
            config.setRankActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK));
1392
            config.setAtomisedEpithetsActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1393
            config.setAuthorshipSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1394
            config.setNomenclaturalReferenceSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1395
            config.setNomenclaturalStatusSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1396
            config.setProtologueActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1397
            config.setTypeDesignationSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1398
            config.setNameRelationsSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1399
            config.setHybridActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID));
1400
        }
1401
        return config;
1402
    }
1403

    
1404
    /**
1405
     * @param object
1406
     * @param b
1407
     * @return
1408
     */
1409
    public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1410
        CdmPreference preference = null;
1411

    
1412
        if (!local) {
1413
            preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NameDetailsView, config.toString());
1414

    
1415
            setPreferenceToDB(preference);
1416
        }
1417
        //also add to local preferences
1418
        setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION, config.isSimpleDetailsViewActivated());
1419
        setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1420
        setBooleanValue(SHOW_SEC_DETAILS, config.isSecDetailsActivated());
1421
        setBooleanValue(DISABLE_SEC, config.isSecEnabled());
1422
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1423
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, config.isNomenclaturalCodeActived());
1424
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, config.isAppendedPhraseActivated());
1425
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1426
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, config.isAtomisedEpithetsActivated());
1427
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, config.isAuthorshipSectionActivated());
1428
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, config.isNomenclaturalReferenceSectionActivated());
1429
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, config.isNomenclaturalStatusSectionActivated());
1430
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, config.isProtologueActivated());
1431
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, config.isTypeDesignationSectionActivated());
1432
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, config.isNameRelationsSectionActivated());
1433
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID, config.isHybridActivated());
1434

    
1435
    }
1436

    
1437
    private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1438
		if (sectionMap.containsKey(string)){
1439
			return sectionMap.get(string);
1440
		}else{
1441
			return true;
1442
		}
1443

    
1444
	}
1445

    
1446

    
1447

    
1448
    /**
1449
     * <p>
1450
     * setAbcdConfigurator
1451
     * </p>
1452
     *
1453
     * @param preferredConfiguration
1454
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1455
     *            object.
1456
     */
1457
    public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1458

    
1459
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1460
        ICdmRepository controller;
1461
        controller = CdmStore.getCurrentApplicationConfiguration();
1462
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
1463
        CdmPreference preference = null;
1464
        if (controller == null){
1465
            return null;
1466
        }
1467
        preference = controller.getPreferenceService().find(key);
1468
        if (preference == null){
1469
            return config;
1470
         } else{
1471
             String configString = preference.getValue();
1472
             String[] configArray = configString.split(";");
1473

    
1474
             for (String configItem: configArray){
1475
                 String[] keyValue = configItem.split(":");
1476
                 String keyString = keyValue[0];
1477
                 String valueString = null;
1478
                 if (keyValue.length>1){
1479
                      valueString = keyValue[1];
1480
                 }
1481
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1482
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1483
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1484
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1485
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1486
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1487
                 }else if (keyString.equals("ignoreAuthorship")){
1488
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1489
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1490
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1491
                 }else if (keyString.equals("reuseExistingMetaData")){
1492
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1493
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1494
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1495
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1496
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1497
                 }else if (keyString.equals("deduplicateReferences")){
1498
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1499
                 }else if (keyString.equals("deduplicateClassifications")){
1500
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1501
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1502
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1503
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1504
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1505
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1506
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1507
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1508
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1509
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1510
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1511
                 }else if (keyString.equals("nomenclaturalCode")){
1512
                         config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1513
                 }else{
1514
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1515
                 }
1516

    
1517
             }
1518
        }
1519
        return config;
1520
    }
1521

    
1522
    public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1523
       Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1524

    
1525
        config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1526

    
1527
        config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1528

    
1529
        config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1530
        config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1531
        config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1532
        config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
1533
        config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1534
        config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1535
        config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1536
        config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1537
        config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1538
        config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1539
        config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1540
        config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1541
        config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1542
        config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1543
        config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1544
        config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1545

    
1546
        return config;
1547

    
1548
    }
1549

    
1550

    
1551
    public static void updateAbcdImportConfigurationPreference() {
1552

    
1553
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1554
        ICdmRepository controller;
1555
        controller = CdmStore.getCurrentApplicationConfiguration();
1556
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
1557
        CdmPreference preference = null;
1558
        if (controller == null){
1559
            return ;
1560
        }
1561
        preference = controller.getPreferenceService().find(key);
1562
        boolean allowOverride = true;
1563
        if (preference != null && !preference.isAllowOverride()){
1564
            allowOverride = false;
1565
        }
1566
        if (!getBooleanValue(IPreferenceKeys.ABCD_IMPORT_OVERRIDE) || !allowOverride){
1567
            resetToDBPreferenceAbcdCOnfigurator();
1568

    
1569
        }
1570
    }
1571

    
1572
    public static void resetToDBPreferenceAbcdCOnfigurator(){
1573
        Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
1574
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1575
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1576

    
1577
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1578
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1579
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1580

    
1581
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1582
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1583
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1584
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1585
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1586
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1587
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1588
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1589
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1590
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1591
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1592
        if (config.getNomenclaturalCode() != null){
1593
            setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1594
        }
1595
    }
1596

    
1597

    
1598
    /**
1599
    *
1600
    */
1601
   public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
1602
       NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1603
       if (local){
1604
          config.setSimpleDetailsViewActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
1605
          config.setAppendedPhraseActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1606
          config.setAtomisedEpithetsActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1607
          config.setAuthorshipSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1608
          config.setLSIDActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
1609
          config.setNameApprobiationActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
1610
          config.setNameCacheActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
1611
          config.setNameRelationsSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1612
          config.setNomenclaturalCodeActived(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1613
          config.setNomenclaturalStatusSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1614
          config.setNomenclaturalReferenceSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1615
          config.setProtologueActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1616
          config.setRankActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
1617
          config.setTaxonSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
1618
          config.setTypeDesignationSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1619
          config.setHybridActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
1620
       }else{
1621

    
1622
       }
1623

    
1624
      return config;
1625
   }
1626

    
1627

    
1628
   public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
1629
       setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
1630
               config.isSimpleDetailsViewActivated());
1631
       setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1632
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1633
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1634
               config.isNomenclaturalCodeActived());
1635
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
1636
               config.isNameCacheActivated());
1637
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1638
               config.isAppendedPhraseActivated());
1639
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1640
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1641
               config.isAtomisedEpithetsActivated());
1642
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
1643
               config.isAuthorCacheActivated());
1644
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1645
               config.isAuthorshipSectionActivated());
1646
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1647
               config.isNomenclaturalReferenceSectionActivated());
1648
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1649
               config.isNomenclaturalStatusSectionActivated());
1650
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1651
               config.isProtologueActivated());
1652
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1653
               config.isTypeDesignationSectionActivated());
1654
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1655
               config.isNameRelationsSectionActivated());
1656
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
1657
               config.isHybridActivated());
1658

    
1659
   }
1660

    
1661
/**
1662
 * @return
1663
 */
1664
public static boolean isSortTaxaByRankAndName() {
1665

    
1666
    return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1667
}
1668

    
1669
/**
1670
 * @return
1671
 */
1672
public static boolean isSortNamedAreaByOrderInVocabulary() {
1673

    
1674
    return getBooleanValue(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER);
1675
}
1676

    
1677
public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
1678
    setBooleanValue(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER, isSortByVocabularyOrder);
1679

    
1680
}
1681

    
1682
/**
1683
 * <p>
1684
 * setPreferredNamedAreasForDistributionEditor
1685
 * </p>
1686
 *
1687
 * @param saveCheckedElements
1688
 * @param saveGrayedElements
1689
 */
1690
public static void setLastSelectedReference(
1691
        List<String> lastSelectedReferences) {
1692

    
1693
        setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1694
    }
1695

    
1696
/**
1697
 * <p>
1698
 * setPreferredNamedAreasForDistributionEditor
1699
 * </p>
1700
 *
1701
 * @param saveCheckedElements
1702
 * @param saveGrayedElements
1703
 */
1704
public static List<String> getLastSelectedReferences() {
1705

    
1706
        //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1707
        String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
1708
        List<String> result = new ArrayList<>();
1709
        if (!StringUtils.isBlank(lastSelected)){
1710
            Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1711
        }
1712
        return result;
1713
    }
1714

    
1715

    
1716
/**
1717
 * <p>
1718
 * setPreferredNamedAreasForDistributionEditor
1719
 * </p>
1720
 *
1721
 * @param saveCheckedElements
1722
 * @param saveGrayedElements
1723
 */
1724
public static void setPreferredNamedAreasForDistributionEditor(
1725
        String saveCheckedElements, String saveGrayedElements, boolean local) {
1726
    if (local){
1727
        setStringValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
1728

    
1729
    }
1730
    else{
1731
        CdmPreference preference = null;
1732

    
1733
        if (saveCheckedElements == null){
1734
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1735

    
1736
            if (preference == null){
1737
                return ;
1738
            } else{
1739
                setStringValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1740
                        saveCheckedElements);
1741
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1742
                setPreferenceToDB(preference);
1743

    
1744
            }
1745
        } else{
1746
           preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1747
           setPreferenceToDB(preference);
1748
           setStringValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1749
                    saveCheckedElements);
1750

    
1751
        }
1752
    }
1753

    
1754
}
1755

    
1756
/**
1757
 * @param saveCheckedElements
1758
 * @param saveCheckedElements2
1759
 * @param b
1760
 */
1761
public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1762
        boolean local) {
1763
    if (local){
1764
      setStringValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES, saveCheckedElements);
1765
    }
1766
    else{
1767
        ICdmRepository controller;
1768
        CdmPreference preference = null;
1769

    
1770
        if (saveCheckedElements == null){
1771
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1772

    
1773
            if (preference == null){
1774
                return ;
1775
            } else{
1776
                setStringValue(DISTRIBUTION_VOCABULARIES,
1777
                        saveCheckedElements);
1778
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1779
                setPreferenceToDB(preference);
1780
            }
1781
        } else{
1782
            preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1783
            setPreferenceToDB(preference);
1784
            setStringValue(DISTRIBUTION_VOCABULARIES,
1785
                    saveCheckedElements);
1786

    
1787
        }
1788
    }
1789
}
1790

    
1791

    
1792

    
1793

    
1794
/**
1795
 * @param saveCheckedElements
1796
 * @param saveCheckedElements2
1797
 * @param b
1798
 */
1799
public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1800
    if (local){
1801

    
1802
        String pref = getStringValue(DISTRIBUTION_VOCABULARIES);
1803
        return pref;
1804
    }
1805
    else{
1806
        CdmPreference preference = null;
1807
        preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1808
        if (preference == null){
1809
            return null;
1810
        } else{
1811
            return preference.getValue();
1812
        }
1813

    
1814
    }
1815

    
1816

    
1817

    
1818
}
1819

    
1820
public static boolean getFilterCommonNameReferences(){
1821
    return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1822
}
1823

    
1824
/**
1825
 *
1826
 */
1827
public static void updateDBPreferences() {
1828
    CdmPreference preference = null;
1829
    IPreferenceStore prefStore = getPreferenceStore();
1830

    
1831
    //ABCD Configurator
1832

    
1833
    updateAbcdImportConfigurationPreference();
1834

    
1835
    preference = getPreferenceFromDB(PreferencePredicate.ShowImportExportMenu);
1836
    if (preference != null){
1837
        if(!getBooleanValue(SHOW_IO_MENU) ||  !preference.isAllowOverride()){
1838
           setBooleanValue(SHOW_IO_MENU, Boolean.valueOf(preference.getValue()));
1839
        }
1840
    }else{
1841
        setBooleanValue(SHOW_IO_MENU, true);
1842
    }
1843

    
1844
    preference = getPreferenceFromDB(PreferencePredicate.ShowMediaView);
1845
    if (preference != null){
1846
        if(!getBooleanValue(SHOW_MEDIA) ||  !preference.isAllowOverride()){
1847
            setBooleanValue(SHOW_MEDIA, Boolean.valueOf(preference.getValue()));
1848
        }
1849
    }else{
1850
        setBooleanValue(SHOW_MEDIA, true);
1851
    }
1852

    
1853
    preference = getPreferenceFromDB(PreferencePredicate.ShowChecklistPerspective);
1854
    if (preference != null){
1855
        if(!getBooleanValue(SHOW_CHECKLIST_PERSPECTIVE) ||  !preference.isAllowOverride()){
1856
            setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, Boolean.valueOf(preference.getValue()));
1857
        }
1858
    }else{
1859
        setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, false);
1860
    }
1861

    
1862
    //Specimen Details
1863
    preference = getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
1864
    if (preference != null){
1865
        if(!getBooleanValue(SHOW_SPECIMEN) ||  !preference.isAllowOverride()){
1866
            setBooleanValue(SHOW_SPECIMEN, Boolean.valueOf(preference.getValue()));
1867
        }
1868
    }else{
1869
        setBooleanValue(SHOW_SPECIMEN, true);
1870
    }
1871

    
1872
    preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
1873
    if (preference != null){
1874
        if(!getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) ||  !preference.isAllowOverride()){
1875
            setBooleanValue(SHOW_TAXON_ASSOCIATIONS, Boolean.valueOf(preference.getValue()));
1876
        }
1877
    }
1878
    preference = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
1879
    if (preference != null){
1880
        if(!getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) ||  !preference.isAllowOverride()){
1881
            setBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, Boolean.valueOf(preference.getValue()));
1882
        }
1883
    }
1884
    preference = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
1885
    if (preference != null){
1886
        if(!getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) ||  !preference.isAllowOverride()){
1887
            setBooleanValue(SHOW_LIFE_FORM, Boolean.valueOf(preference.getValue()));
1888
        }
1889
    }
1890
    preference = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
1891
    if (preference != null){
1892
        if(!getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) ||  !preference.isAllowOverride()){
1893
            setBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS, Boolean.valueOf(preference.getValue()));
1894
        }
1895
    }
1896

    
1897

    
1898
    //Name Details
1899
    NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1900
    if (config != null ){
1901
        if (!getBooleanValue(OVERRIDE_NAME_DETAILS) ||  !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1902
            setPreferredNameDetailsConfiguration(config, false);
1903
        }
1904
    }
1905

    
1906
    //Distribution Editor
1907
    preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1908
    if (preference != null){
1909
        if (!getBooleanValue(DISTRIBUTION_VOCABULARIES_OVERRIDE) ||  !preference.isAllowOverride()){
1910
            setStringValue(DISTRIBUTION_VOCABULARIES, preference.getValue());
1911
            setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
1912
        }
1913
    }else{
1914
        setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE,true);
1915
        setStringValue(DISTRIBUTION_VOCABULARIES, "");
1916
    }
1917

    
1918
    preference = getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
1919
    if (preference != null){
1920
        if (!getBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) || !preference.isAllowOverride()){
1921
            setBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE, Boolean.valueOf(preference.getValue()));
1922
        }
1923
    }
1924

    
1925
    preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
1926
    if (preference != null){
1927
        if (!getBooleanValue(DISTRIBUTION_STATUS_OVERRIDE) || !preference.isAllowOverride()){
1928
            //get terms for the uuids... and add them to the termManager as preferred terms
1929
            ITermService termService = CdmStore.getService(ITermService.class);
1930
            String[] uuidArray = preference.getValue().split(";");
1931
            List<UUID> uuidList = new ArrayList();
1932
            for (String uuidString:uuidArray){
1933
                try {
1934
                    uuidList.add(UUID.fromString(uuidString));
1935
                } catch (Exception e) {
1936
                    logger.warn("Preference loading failed", e);
1937
                }
1938
            }
1939

    
1940
            List<DefinedTermBase> definedTermBases = termService.load(uuidList, null);
1941
            CdmStore.getTermManager().setPreferredTerms(definedTermBases, TermStore.getTerms(TermType.PresenceAbsenceTerm, null));
1942
        }
1943
    }
1944

    
1945
    preference = getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
1946
    if (preference != null){
1947
        if (!getBooleanValue(COMMON_NAME_AREA_VOCABULARIES) ||  !preference.isAllowOverride()){
1948
            setStringValue(COMMON_NAME_AREA_VOCABULARIES, preference.getValue());
1949
            setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
1950
        }
1951
    }else{
1952
        setStringValue(COMMON_NAME_AREA_VOCABULARIES, "");
1953
        setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, true);
1954
    }
1955

    
1956
    preference = getPreferenceFromDB(PreferencePredicate.CommonNameReferencesWithMarker);
1957
    if (preference != null){
1958
        if (!getBooleanValue(FILTER_COMMON_NAME_REFERENCES) ||  !preference.isAllowOverride()){
1959
            setBooleanValue(FILTER_COMMON_NAME_REFERENCES, Boolean.valueOf(preference.getValue()));
1960
        }
1961
    }else{
1962
        setBooleanValue(FILTER_COMMON_NAME_REFERENCES, false);
1963
    }
1964

    
1965

    
1966
    preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonNodeWizard);
1967
    if (preference != null){
1968
        if (!getBooleanValue(SHOW_TAXONNODE_WIZARD) ||  !preference.isAllowOverride()){
1969
            setBooleanValue(SHOW_TAXONNODE_WIZARD, Boolean.valueOf(preference.getValue()));
1970
        }
1971
    }else{
1972
        setBooleanValue(SHOW_TAXONNODE_WIZARD, true);
1973
    }
1974

    
1975
    preference = getPreferenceFromDB(PreferencePredicate.ShowIdInSource);
1976
    if (preference != null){
1977
        if (!getBooleanValue(SHOW_ID_IN_SOURCE) ||  !preference.isAllowOverride()){
1978
            setBooleanValue(SHOW_ID_IN_SOURCE, Boolean.valueOf(preference.getValue()));
1979
        }
1980
    }else{
1981
        setBooleanValue(SHOW_ID_IN_SOURCE, true);
1982
    }
1983

    
1984
    preference = getPreferenceFromDB(PreferencePredicate.ShowNamespaceInSource);
1985
    if (preference != null){
1986
        if (!getBooleanValue(SHOW_NAMESPACE_IN_SOURCE) ||  !preference.isAllowOverride()){
1987
            setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, Boolean.valueOf(preference.getValue()));
1988
        }
1989
    }else{
1990
        setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, true);
1991
    }
1992

    
1993
    preference = getPreferenceFromDB(PreferencePredicate.DisableMultiClassification);
1994
    if (preference != null){
1995
        if (!getBooleanValue(DISABLE_MULTI_CLASSIFICATION) ||  !preference.isAllowOverride()){
1996
            setBooleanValue(DISABLE_MULTI_CLASSIFICATION, Boolean.valueOf(preference.getValue()));
1997
        }
1998
    }else{
1999
        setBooleanValue(DISABLE_MULTI_CLASSIFICATION, false);
2000
    }
2001

    
2002
}
2003

    
2004

    
2005

    
2006

    
2007

    
2008

    
2009

    
2010

    
2011
}
(21-21/29)