Project

General

Profile

Download (70.7 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.ICdmBase;
48
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
49
import eu.etaxonomy.cdm.model.common.ISimpleTerm;
50
import eu.etaxonomy.cdm.model.common.Language;
51
import eu.etaxonomy.cdm.model.common.MarkerType;
52
import eu.etaxonomy.cdm.model.common.TermBase;
53
import eu.etaxonomy.cdm.model.description.FeatureTree;
54
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
55
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
56
import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
57
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
58
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
59
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
60
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
61
import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
62
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
63
import eu.etaxonomy.cdm.strategy.match.MatchException;
64
import eu.etaxonomy.cdm.strategy.match.MatchMode;
65
import eu.etaxonomy.taxeditor.model.AbstractUtility;
66
import eu.etaxonomy.taxeditor.model.MessagingUtils;
67
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
68
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
69
import eu.etaxonomy.taxeditor.store.CdmStore;
70
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
71
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
72

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

    
84
	/**
85
	 *
86
	 */
87
	public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
88

    
89
	public static final String P2_REPOSITORIES_DELIM = ",";
90
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
91

    
92
	private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
93

    
94

    
95

    
96

    
97

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

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

    
113
	public static String prefOverrideKey(String name) {
114
        return name + "_OVERRIDE_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
115
    }
116

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

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

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

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

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

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

    
183
    /**
184
     * <p>
185
     * getStringValue
186
     * </p>
187
     *
188
     *
189
     **/
190
    public static String getStringValue(String name, boolean local) {
191

    
192
        String prefValue = getDBPreferenceValue(name);
193
        if (prefValue == null || local){
194
            String dbSpecific = prefKey(name);
195
            if (getPreferenceStore().contains(dbSpecific)){
196
                prefValue = getPreferenceStore().getString(dbSpecific);
197
            }else{
198
                prefValue = getPreferenceStore().
199
                        getString(name);
200
            }
201
        }
202
        return prefValue;
203

    
204
    }
205

    
206
    public static String getStringValue(String name){
207
        return getStringValue(name, false);
208
    }
209

    
210
    private static String getDBPreferenceValue(String name) {
211
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
212
        if (cache.get(name) != null){
213
            CdmPreference pref = cache.get(name);
214
            if (!pref.isAllowOverride() || !getBooleanValue(prefOverrideKey(name))){
215
                return pref.getValue();
216
            }
217
        }
218
        return null;
219
    }
220

    
221
    /**
222
     * <p>
223
     * setIntValue
224
     * </p>
225
     *
226
     *
227
     **/
228
    public static int getIntValue(String name) {
229
        String prefValue = getDBPreferenceValue(name);
230
        Integer result = null;
231
        try{
232
            result = Integer.parseInt(prefValue);
233
        }catch(NumberFormatException e){
234
            logger.debug("Preference value of " + name + " is not a number");
235
        }
236
        if (result == null){
237
            String dbSpecific = prefKey(name);
238
            if (getPreferenceStore().contains(dbSpecific)){
239
                result = getPreferenceStore().getInt(dbSpecific);
240
            }else{
241
                result =  getPreferenceStore().
242
                        getInt(name);
243
            }
244
        }
245
        return result;
246

    
247

    
248
    }
249

    
250
    /**
251
     * <p>
252
     * setBooleanValue
253
     * </p>
254
     *
255
     *
256
     **/
257
    public static boolean getBooleanValue(String name) {
258
        if (CdmStore.isActive()){
259
            String prefValue = getDBPreferenceValue(name);
260
            if (prefValue == null){
261
                String dbSpecific = prefKey(name);
262
                if (getPreferenceStore().contains(dbSpecific)){
263
                    return getPreferenceStore().getBoolean(dbSpecific);
264
                }else{
265
                    return getPreferenceStore().
266
                            getBoolean(name);
267
                }
268
            }else{
269
                return Boolean.valueOf(prefValue);
270
            }
271

    
272
        }else{
273
            return getPreferenceStore().getBoolean(name);
274
        }
275

    
276
    }
277

    
278
    /**
279
     * <p>
280
     * setBooleanValue
281
     * </p>
282
     *
283
     *
284
     **/
285
    public static double getDoubleValue(String name) {
286
        String prefValue = getDBPreferenceValue(name);
287
        Double result = null;
288
        try{
289
            result = Double.parseDouble(prefValue);
290
        }catch(NumberFormatException e){
291
            logger.debug("Preference value of " + name + " is not a number");
292
        }
293
        if (result == null){
294
            String dbSpecific = prefKey(name);
295
            if (getPreferenceStore().contains(dbSpecific)){
296
                result = getPreferenceStore().getDouble(dbSpecific);
297
            }else{
298
                result =  getPreferenceStore().
299
                        getDouble(name);
300
            }
301
        }
302
        return result;
303

    
304
    }
305

    
306
    /**
307
     * <p>
308
     * getFloatValue
309
     * </p>
310
     *
311
     *
312
     **/
313
    public static float getFloatValue(String name) {
314
        String prefValue = getDBPreferenceValue(name);
315
        Float result = null;
316
        try{
317
            result = Float.parseFloat(prefValue);
318
        }catch(NumberFormatException e){
319
            logger.debug("Preference value of " + name + " is not a number");
320
        }
321
        if (result == null){
322
            String dbSpecific = prefKey(name);
323
            if (getPreferenceStore().contains(dbSpecific)){
324
                result = getPreferenceStore().getFloat(dbSpecific);
325
            }else{
326
                result =  getPreferenceStore().
327
                        getFloat(name);
328
            }
329
        }
330
        return result;
331

    
332
    }
333

    
334
    /**
335
     * <p>
336
     * getLongValue
337
     * </p>
338
     *
339
     *
340
     **/
341
    public static long getLongValue(String name) {
342
        String prefValue = getDBPreferenceValue(name);
343
        Long result = null;
344
        try{
345
            result = Long.parseLong(prefValue);
346
        }catch(NumberFormatException e){
347
            logger.debug("Preference value of " + name + " is not a number");
348
        }
349
        if (result == null){
350
            String dbSpecific = prefKey(name);
351
            if (getPreferenceStore().contains(dbSpecific)){
352
                result = getPreferenceStore().getLong(dbSpecific);
353
            }else{
354
                result =  getPreferenceStore().
355
                        getLong(name);
356
            }
357
        }
358
        return result;
359
    }
360

    
361

    
362
	/**
363
	 * <p>
364
	 * setPreferredNomenclaturalCode
365
	 * </p>
366
	 *
367
	 * @param preferredCode
368
	 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
369
	 *            object.
370
	 */
371
	public static CdmPreference setPreferredNomenclaturalCode(
372
			String preferenceValue, boolean local) {
373
	    if (local){
374
	        setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
375
	                preferenceValue);
376
	    }
377
	    else{
378
    		ICdmRepository controller;
379
    		controller = CdmStore.getCurrentApplicationConfiguration();
380
    		if (controller == null){
381
                return null;
382
            }
383
    		PrefKey key = null;
384
    		try{
385
    		    key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
386
    		}catch (Exception e){
387
    		    System.out.println(e.getStackTrace());
388
    		}
389
    		CdmPreference preference = null;
390

    
391
    		if (preferenceValue == null){
392
    			preference = controller.getPreferenceService().find(key);
393
    			if (preference == null){
394
    				return null;
395
    			} else{
396
    			    setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
397
    				        preference.getValue());
398

    
399
    				return preference;
400
    			}
401
    		} else{
402
    			preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
403
    			controller.getPreferenceService().set(preference);
404

    
405
    		}
406
	    }
407
        return null;
408

    
409

    
410

    
411
	}
412

    
413
	/**
414
     * <p>
415
     * setPreferredNomenclaturalCode
416
     * </p>
417
     *
418
     * @param preferredCode
419
     *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
420
     *            object.
421
     */
422
    public static void setPreferredNomenclaturalCode(
423
        CdmPreference preference) {
424

    
425
        ICdmRepository controller;
426
        controller = CdmStore.getCurrentApplicationConfiguration();
427
        if (controller == null){
428
            return;
429
        }
430
        PrefKey key = null;
431
        try{
432
            key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
433
        }catch (Exception e){
434
            System.out.println(e.getStackTrace());
435
        }
436

    
437
        controller.getPreferenceService().set(preference);
438

    
439
    }
440

    
441

    
442
	public static NomenclaturalCode getPreferredNomenclaturalCode(){
443
	    if (getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey()))) {
444
            return getPreferredNomenclaturalCode(true);
445
        } else{
446
            return getPreferredNomenclaturalCode(false);
447
        }
448
	}
449

    
450
	/**
451
	 * <p>
452
	 * getPreferredNomenclaturalCode
453
	 * </p>
454
	 *
455
	 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
456
	 */
457
	public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
458

    
459
		CdmPreference pref = null;
460
		if (!useLocal){
461
		    pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
462
		}
463

    
464
	    String preferredCode;
465
	    if(pref == null){
466
	    	preferredCode = getStringValue(
467
					PREFERRED_NOMENCLATURAL_CODE_KEY, true);
468

    
469
	    }else{
470
	    	preferredCode = pref.getValue();
471
	    }
472

    
473
	    return getPreferredNomenclaturalCode(preferredCode);
474

    
475
	}
476

    
477
	/**
478
     * <p>
479
     * getPreferredNomenclaturalCode
480
     * </p>
481
     *
482
     * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
483
     */
484
    public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
485

    
486
        for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
487
            if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
488
                return code;
489
            }
490
        }
491
        return null;
492
    }
493

    
494
	public static boolean isShowTaxonAssociations(){
495
        boolean result = getBooleanValue(EditorPreferencePredicate.ShowTaxonAssociations.getKey());
496
        return result;
497
    }
498

    
499
	public static boolean isShowLifeForm(){
500
	    boolean result =  getBooleanValue(EditorPreferencePredicate.ShowLifeForm.getKey());
501
	    return result;
502
    }
503

    
504
	public static boolean isDeterminationOnlyForFieldUnits(){
505
	    boolean result =  getBooleanValue(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
506
        return result;
507
    }
508

    
509
	public static boolean isCollectingAreaInGeneralSection(){
510
	    boolean result =  getBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
511
        return result;
512
	}
513

    
514
	public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
515
        ICdmRepository controller;
516
        CdmPreference pref = null;
517

    
518
        try{
519
            if(CdmStore.isActive()){
520
                controller = CdmStore.getCurrentApplicationConfiguration();
521
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
522
                pref = controller.getPreferenceService().find(key);
523
            }
524
        }catch(Exception e){
525
            e.printStackTrace();
526
        }
527

    
528
        return pref;
529

    
530
    }
531

    
532
    public static void setPreferenceToDB(CdmPreference preference){
533
        ICdmRepository controller;
534
        try{
535
            if(CdmStore.isActive()){
536
                controller = CdmStore.getCurrentApplicationConfiguration();
537
                controller.getPreferenceService().set(preference);
538
            }
539
        }catch(Exception e){
540
            e.printStackTrace();
541
        }
542

    
543
    }
544

    
545

    
546

    
547
	public static String getPreferredDefaultLangugae(){
548
	    String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
549
	    if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
550
	        return preferredLanguage;
551
	    }
552
	    return null;
553
	}
554

    
555
	public static boolean isShowMediaPreview(){
556
        boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
557
        return isShowMediaPreview;
558
    }
559

    
560
	/**
561
	 * Get the match strategy for the given class that was stored in preferences
562
	 * or the default strategy if it was not stored in preferences
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 getMatchStrategy(Class<?> clazz) {
569
		String className = clazz.getName();
570
		if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
571
			IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
572

    
573
			//TODO CacheMatchers (or multiple field matchers in future) are missing here
574
			for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
575
				String fieldName = fieldMatcher.getPropertyName();
576
				String matchModeName = getStringValue(
577
						getMatchStrategyFieldName(className, fieldName));
578
				MatchMode matchMode = MatchMode.valueOf(matchModeName);
579
				try {
580
					matchStrategy.setMatchMode(fieldName, matchMode);
581
				} catch (MatchException e) {
582
					MessagingUtils.error(PreferencesUtil.class, e);
583
					throw new RuntimeException(e);
584
				}
585
			}
586

    
587
			return matchStrategy;
588
		}
589
		return getDefaultMatchStrategy(clazz);
590
	}
591

    
592
	/**
593
	 * Stores a matchStrategy into the preference store.
594
	 *
595
	 * @param matchStrategy
596
	 *            a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
597
	 *            object.
598
	 */
599
	public static void setMatchStrategy(IMatchStrategy matchStrategy) {
600
		String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
601
		setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
602

    
603
		List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
604

    
605
		for (FieldMatcher fieldMatcher : fieldMatchers) {
606
			String fieldName = fieldMatcher.getPropertyName();
607
			setStringValue(
608
					getMatchStrategyFieldName(className, fieldName),
609
					fieldMatcher.getMatchMode().name());
610
		}
611
	}
612

    
613
	/**
614
	 * Helper method to create the preference property for a match field.
615
	 *
616
	 * @param className
617
	 * @param fieldName
618
	 * @return
619
	 */
620
	private static String getMatchStrategyFieldName(String className,
621
			String fieldName) {
622
		return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
623
	}
624

    
625
	/**
626
	 * Returns the default match strategy for a given class.
627
	 *
628
	 * @param clazz
629
	 *            a {@link java.lang.Class} object.
630
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
631
	 */
632
	public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
633
		return DefaultMatchStrategy.NewInstance(clazz);
634
	}
635

    
636
	/**
637
	 * <p>
638
	 * getDateFormatPattern
639
	 * </p>
640
	 *
641
	 * @return a {@link java.lang.String} object.
642
	 */
643
	public static String getDateFormatPattern() {
644
		// TODO make this configurable in properties
645
		String pattern = "Y-M-d H:m";
646
		return pattern;
647
	}
648

    
649
	/**
650
	 * <p>
651
	 * addTermToPreferredTerms
652
	 * </p>
653
	 *
654
	 * @param term
655
	 *            a T object.
656
	 * @param <T>
657
	 *            a T object.
658
	 */
659
	public static <T extends TermBase> void addTermToPreferredTerms(T term) {
660

    
661
		// VocabularyEnum vocabulary =
662
		// VocabularyEnum.getVocabularyEnum(term.getClass());
663
		//
664
		// getPreferenceStore().setValue(getPreferenceKey(term),
665
		// VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
666
		//
667
		// firePreferencesChanged(term.getClass());
668
	}
669

    
670
	/**
671
	 * Construct a unique key using the CdmBase object's uuid
672
	 *
673
	 * @param cdmBase
674
	 * @return
675
	 */
676
	private static String getPreferenceKey(ICdmBase cdmBase) {
677
		cdmBase = HibernateProxyHelper.deproxy(cdmBase);
678

    
679
		String key = cdmBase.getClass().getName().concat(".")
680
				.concat(cdmBase.getUuid().toString());
681
		if (key.contains("javassist")) {
682
			MessagingUtils.info("proxy");
683
		}
684
		return key;
685
	}
686

    
687
	/**
688
	 * Construct a unique key using the CdmBase object's uuid
689
	 *
690
	 * @param cdmBase
691
	 * @return
692
	 */
693
	public static String getPreferenceKey(ISimpleTerm simpleTerm) {
694
		simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
695
		String key = simpleTerm.getClass().getName().concat(".")
696
				.concat(simpleTerm.getUuid().toString());
697
		if (key.contains("javassist")) {
698
			MessagingUtils.warn(PreferencesUtil.class,
699
					"Trying to persist a preference based on a proxy class.");
700
		}
701
		return key;
702
	}
703

    
704

    
705

    
706
	/**
707
	 * Construct a unique key using the CdmBase object's uuid
708
	 *
709
	 * @param cdmBase
710
	 * @return
711
	 */
712
	public static String getPreferenceKey(IDefinedTerm definedTerm) {
713
		definedTerm = HibernateProxyHelper.deproxy(definedTerm);
714
		String key = definedTerm.getClass().getName().concat(".")
715
				.concat(definedTerm.getUuid().toString());
716
		if (key.contains("javassist")) {
717
			MessagingUtils.warn(PreferencesUtil.class,
718
					"Trying to persist a preference based on a proxy class.");
719
		}
720
		return key;
721
	}
722

    
723
	/**
724
	 * Retrieves search preferences from the preference store
725
	 *
726
	 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
727
	 */
728
	public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
729
		IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
730

    
731
		configurator.setDoTaxa(getBooleanValue(
732
				TAXON_SERVICE_CONFIGURATOR_TAXA));
733
		configurator.setDoSynonyms(getBooleanValue(
734
				TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
735
		configurator.setDoNamesWithoutTaxa(getBooleanValue(
736
				TAXON_SERVICE_CONFIGURATOR_NAMES));
737
		configurator.setDoTaxaByCommonNames(getBooleanValue(
738
				TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
739
		//configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
740

    
741
		return configurator;
742
	}
743

    
744
	/**
745
	 * create new preferences, setting all search options to true
746
	 *
747
	 * @return a
748
	 *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
749
	 *         object.
750
	 */
751
	public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
752
		IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
753

    
754
		configurator.setDoTaxa(true);
755
		configurator.setDoSynonyms(true);
756
		configurator.setDoNamesWithoutTaxa(true);
757
		configurator.setDoTaxaByCommonNames(true);
758

    
759
		configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
760
				"name", "name.$", "relationsFromThisTaxon.$"));
761

    
762
		configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
763
				"name", "name.$", "synonyms.relatedTo.*"));
764

    
765
		// DEFAULT VALUES
766
		// match mode is a simple like, actually all other match modes are kind
767
		// of bogus
768
		configurator
769
				.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
770
		// we set page number and size here as this should always be unlimited
771
		configurator.setPageNumber(0);
772
		// TODO currently limit results to 10000
773
		configurator.setPageSize(10000);
774
		setSearchConfigurator(configurator) ;
775
		return configurator;
776
	}
777

    
778
	/**
779
	 * Store search preferences
780
	 *
781
	 * @param configurator
782
	 *            a
783
	 *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
784
	 *            object.
785
	 */
786
	public static void setSearchConfigurator(
787
			IFindTaxaAndNamesConfigurator configurator) {
788
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
789
				configurator.isDoTaxa());
790
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
791
				configurator.isDoSynonyms());
792
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
793
				configurator.isDoNamesWithoutTaxa());
794
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
795
				configurator.isDoTaxaByCommonNames());
796
	}
797

    
798
	/**
799
	 * <p>
800
	 * firePreferencesChanged
801
	 * </p>
802
	 *
803
	 * @param clazz
804
	 *            a {@link java.lang.Class} object.
805
	 */
806
	public static void firePreferencesChanged(Class clazz) {
807
		getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
808
				null, clazz);
809
	}
810

    
811
	public static String createPreferenceString(String property){
812
	   return prefKey(property);
813

    
814
	}
815
	public static String createOverridePreferenceString(String property){
816
	       return prefOverrideKey(property);
817

    
818
	    }
819

    
820
	/**
821
	 * Set default values for preferences
822
	 */
823
	public static void setDefaults() {
824
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
825
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
826
				true);
827
		getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
828
				"http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
829
		//FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
830
		getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
831
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT),
832
				"http://www.biodiversitylibrary.org/openurl");
833
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000");
834
		getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000");
835
		//Distribution Editor:
836
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(EditorPreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
837
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
838
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfStatus.getKey()), EditorPreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
839

    
840

    
841
		//Name Details
842
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS), true);
843
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE), true);
844
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP), true);
845
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_HYBRID), true);
846
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_LSID), true);
847
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP), true);
848
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAMECACHE), true);
849
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE), true);
850
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE), true);
851
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS), true);
852
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE), true);
853
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_RANK), true);
854
		getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION), true);
855
		//Navigator preferences
856
		getPreferenceStore().setDefault(createPreferenceString(SORT_NODES), NavigatorOrderEnum.RankAndNameOrder.getKey());
857

    
858
		getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
859
		//override db preferences
860
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.AbcdImportConfig.getKey())), false);
861
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.ShowSpecimen.getKey())), false);
862
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.NameDetailsView.getKey())), false);
863
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.DistributionEditorActivated.getKey())), false);
864

    
865
		getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
866
		getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN), true);
867
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
868
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
869
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
870
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(EditorPreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
871
		getPreferenceStore().setDefault(createPreferenceString(DISABLE_SEC), false);
872
		getPreferenceStore().setDefault(createPreferenceString(SHOW_SEC_DETAILS), true);
873
	}
874

    
875
	/**
876
	 * <p>
877
	 * checkNomenclaturalCode
878
	 * </p>
879
	 */
880
	public static void checkNomenclaturalCode() {
881
		// First time Editor is opened, no nomenclatural code has been set
882
		if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
883
			PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
884
		}
885

    
886

    
887

    
888
	}
889
	public static void setNomenclaturalCodePreferences(){
890
	    ICdmRepository controller;
891
        controller = CdmStore.getCurrentApplicationConfiguration();
892
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
893
        CdmPreference preference = null;
894
        if (controller == null){
895
            return ;
896
        }
897
        preference = controller.getPreferenceService().find(key);
898
        if (preference == null){
899
            return;
900
        }
901
//        setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
902

    
903
        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
904
        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
905
        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
906

    
907
        setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
908
                getPreferenceKey(preferredCode));
909

    
910
	}
911

    
912
	public static void checkDefaultLanguage(){
913
	    if(PreferencesUtil.getPreferredDefaultLangugae() == null){
914
	       Shell shell = AbstractUtility.getShell();
915
	       int open = new DefaultLanguageDialog(shell).open();
916
	       if(open == Window.OK){
917
	           PlatformUI.getWorkbench().restart();
918
	       }
919
	    }else{
920
	        //TODO:In case of a reinstall, the config.ini will be overwritten
921
	        //     here you create config.ini with the stored key from preferences
922
	    }
923
	}
924

    
925
	/**
926
	 * <p>
927
	 * getMapServiceAccessPoint
928
	 * </p>
929
	 *
930
	 * @return a {@link java.lang.String} object.
931
	 */
932
	public static String getMapServiceAccessPoint() {
933
		return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
934
	}
935

    
936
	/**
937
	 * <p>
938
	 * shouldConnectAtStartUp
939
	 * </p>
940
	 *
941
	 * @return a boolean.
942
	 */
943
	public static boolean shouldConnectAtStartUp() {
944
		//FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
945
		//return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
946
		return false;
947
	}
948

    
949
	/**
950
	 * <p>
951
	 * getDefaultFeatureTreeForTextualDescription
952
	 * </p>
953
	 *
954
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
955
	 */
956
	public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
957
		String uuidString = getStringValue(
958
				FEATURE_TREE_DEFAULT_TEXT);
959
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
960
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
961
	}
962

    
963
	/**
964
	 * <p>
965
	 * getDefaultFeatureTreeForStructuredDescription
966
	 * </p>
967
	 *
968
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
969
	 */
970
	public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
971
		String uuidString = getStringValue(
972
				FEATURE_TREE_DEFAULT_STRUCTURE);
973
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
974
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
975
	}
976

    
977
	/**
978
	 * <p>
979
	 * setSortRanksHierarchichally
980
	 * </p>
981
	 *
982
	 * @param selection
983
	 *            a boolean.
984
	 */
985
	public static void setSortRanksHierarchichally(boolean selection) {
986
		setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
987
	}
988

    
989
	/**
990
	 * <p>
991
	 * getSortRanksHierarchichally
992
	 * </p>
993
	 *
994
	 * @return a boolean.
995
	 */
996
	public static boolean getSortRanksHierarchichally() {
997
		return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
998
	}
999

    
1000
	public static boolean isMultilanguageTextEditingCapability() {
1001
		return getBooleanValue(
1002
				MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
1003
	}
1004

    
1005
	public static Language getGlobalLanguage() {
1006

    
1007

    
1008
		String languageUuidString = getStringValue(
1009
				GLOBAL_LANGUAGE_UUID);
1010

    
1011
		if(!CdmStore.isActive()) {
1012
            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
1013
            return null;
1014
        }
1015

    
1016
		if (CdmUtils.isBlank(languageUuidString)) {
1017
			return Language.getDefaultLanguage();
1018
		}
1019

    
1020
		UUID languageUuid = UUID.fromString(languageUuidString);
1021
		return (Language) CdmStore.getService(ITermService.class).load(
1022
				languageUuid);
1023
	}
1024

    
1025
	public static void setGlobalLanguage(Language language) {
1026
	    if(language != null) {
1027
	        setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
1028
	        CdmStore.setDefaultLanguage(language);
1029
	    }
1030

    
1031
	}
1032

    
1033
	/**
1034
	 * @return
1035
	 */
1036
	public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
1037
		List<MarkerType> markerTypes = CdmStore.getTermManager()
1038
				.getPreferredTerms(MarkerType.class);
1039

    
1040
		Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
1041

    
1042
		for (MarkerType markerType : markerTypes) {
1043
			String name = getMarkerTypeEditingPreferenceKey(markerType);
1044
			Boolean value = getBooleanValue(name);
1045

    
1046
			result.put(markerType, value);
1047
		}
1048

    
1049
		return result;
1050
	}
1051

    
1052
	/**
1053
	 * @param markerTypeEditingMap
1054
	 */
1055
	public static void setEditMarkerTypePreferences(
1056
			Map<MarkerType, Boolean> markerTypeEditingMap) {
1057
		for (MarkerType markerType : markerTypeEditingMap.keySet()) {
1058
			String name = getMarkerTypeEditingPreferenceKey(markerType);
1059
			setBooleanValue(name,
1060
					markerTypeEditingMap.get(markerType));
1061
		}
1062

    
1063
	}
1064

    
1065
	private static String getMarkerTypeEditingPreferenceKey(
1066
			MarkerType markerType) {
1067
		markerType = HibernateProxyHelper.deproxy(markerType);
1068
		return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
1069
	}
1070

    
1071
	/**
1072
	 * <p>
1073
	 * setEditMarkerTypePreference
1074
	 * </p>
1075
	 *
1076
	 * @param input
1077
	 *            a {@link org.eclipse.ui.IEditorInput} object.
1078
	 * @param markerType
1079
	 *            a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
1080
	 * @param edit
1081
	 *            a boolean.
1082
	 */
1083
	public static void setEditMarkerTypePreference(MarkerType markerType,
1084
			boolean edit) {
1085
		setBooleanValue(
1086
				getMarkerTypeEditingPreferenceKey(markerType), edit);
1087
	}
1088

    
1089
	/**
1090
	 * @return
1091
	 */
1092
	public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
1093
		DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
1094
				.NewInstance();
1095
		configurator.setMoveDerivedUnitMediaToGallery(true);
1096
		configurator.setMoveFieldObjectMediaToGallery(true);
1097
		return configurator;
1098
	}
1099

    
1100
	/**
1101
	 * This method will write language properties to the config.ini located in the configuration folder
1102
	 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
1103
	 *
1104
	 * @param setLanguage 0 is for german and 1 for english.
1105
	 * @throws IOException
1106
	 */
1107
    public void writePropertyToConfigFile(int setLanguage) throws IOException {
1108
        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
1109
        //give warning to user if the directory has no write access
1110
        if(file == null){
1111
            throw new IOException();
1112
        }
1113
        Properties properties = load(file.getAbsolutePath()+"/config.ini");
1114
        switch(setLanguage){
1115
        case 0:
1116
            properties.setProperty("osgi.nl", "de");
1117
            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
1118
            break;
1119
        case 1:
1120
            properties.setProperty("osgi.nl", "en");
1121
            setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
1122
            break;
1123
        default:
1124
            break;
1125
        }
1126
        save(file+"/config.ini", properties);
1127
    }
1128

    
1129
    /**
1130
     * This method loads a property from a given file and returns it.
1131
     *
1132
     * @param filename
1133
     * @return
1134
     * @throws IOException
1135
     */
1136
    private Properties load(String filename) throws IOException {
1137
        FileInputStream in = new FileInputStream(filename);
1138
        Properties prop = new Properties();
1139
        prop.load(in);
1140
        in.close();
1141
        return prop;
1142
    }
1143

    
1144
    /**
1145
     * This method saves a property to the specified file.
1146
     *
1147
     * @param filename
1148
     * @param properties
1149
     * @throws IOException
1150
     */
1151
    private void save(String filename, Properties properties) throws IOException{
1152
        FileOutputStream fos =  new FileOutputStream(filename);
1153
        properties.store(fos, "");
1154
        fos.close();
1155
    }
1156

    
1157
    /**
1158
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
1159
     *
1160
     * @param p2Repos
1161
     */
1162
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
1163
        StringBuilder sb = new StringBuilder();
1164
        for(MetadataRepositoryElement p2Repo : p2Repos) {
1165
            sb.append(P2_REPOSITORIES_DELIM);
1166
            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
1167
                sb.append("-");
1168
            } else {
1169
                sb.append(p2Repo.getName());
1170
            }
1171
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
1172
            sb.append(p2Repo.getLocation().toString());
1173
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
1174
            sb.append(String.valueOf(p2Repo.isEnabled()));
1175
        }
1176
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
1177
    }
1178

    
1179

    
1180
    /**
1181
     * Retrieves a list of previously saved P2 repositories
1182
     *
1183
     * @return
1184
     */
1185
    public static List<MetadataRepositoryElement> getP2Repositories() {
1186
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
1187
        String p2ReposPref =  getStringValue(P2_REPOSITORY_LIST);
1188
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
1189
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
1190

    
1191
            while(p2ReposPrefST.hasMoreTokens()) {
1192
                String p2RepoStr = p2ReposPrefST.nextToken();
1193
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
1194
                if(p2ReposStrST.countTokens()==3) {
1195
                    String nickname = p2ReposStrST.nextToken();
1196
                    URI uri = null;
1197
                    try {
1198
                        uri = new URI(p2ReposStrST.nextToken());
1199
                    } catch (URISyntaxException e) {
1200
                        continue;
1201
                    }
1202
                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
1203
                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
1204
                    mre.setNickname(nickname);
1205
                    mre.setEnabled(enabled);
1206
                    p2Repos.add(mre);
1207
                }
1208
            }
1209
        }
1210

    
1211
        return p2Repos;
1212
    }
1213

    
1214
    /**
1215
     * enables/disables nested composite. <br>
1216
     *
1217
     * @param ctrl - Composite to be en-/disabeld
1218
     * @param enabled - boolean
1219
     */
1220
    public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
1221
        if (ctrl instanceof Composite) {
1222
            Composite comp = (Composite) ctrl;
1223
            for (Control c : comp.getChildren()) {
1224
                recursiveSetEnabled(c, enabled);
1225
            }
1226
        } else {
1227
            ctrl.setEnabled(enabled);
1228
        }
1229
    }
1230

    
1231

    
1232

    
1233

    
1234
    /**
1235
     * @param orderActivated
1236
     */
1237
    public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
1238
        setStringValue(SORT_NODES, nodesOrder.key);
1239

    
1240
    }
1241

    
1242
    /**
1243
     * @param orderActivated
1244
     */
1245
    public static NavigatorOrderEnum getSortNodes() {
1246
        return NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1247

    
1248
    }
1249

    
1250
    /**
1251
     * @param orderActivated
1252
     */
1253
    public static boolean isNodesSortedNaturally() {
1254
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1255
        return value.equals(NavigatorOrderEnum.NaturalOrder);
1256

    
1257
    }
1258

    
1259
    /**
1260
     * @param orderActivated
1261
     */
1262
    public static boolean isNodesSortedByName() {
1263
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1264
        return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
1265

    
1266
    }
1267

    
1268
    /**
1269
     * @param orderActivated
1270
     */
1271
    public static boolean isNodesSortedByNameAndRank() {
1272
        NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
1273
        return value.equals(NavigatorOrderEnum.RankAndNameOrder);
1274

    
1275
    }
1276
	/**
1277
	 * <p>
1278
	 * setStoreNavigatorState
1279
	 * </p>
1280
	 *
1281
	 * @param selection
1282
	 *            a boolean.
1283
	 */
1284
	public static boolean isStoreNavigatorState() {
1285
		return getBooleanValue(RESTORE_NAVIGATOR_STATE);
1286

    
1287
	}
1288

    
1289
	/**
1290
	 * <p>
1291
	 * setStoreNavigatorState
1292
	 * </p>
1293
	 *
1294
	 * @param selection
1295
	 *            a boolean.
1296
	 */
1297
	public static void setStoreNavigatorState(boolean selection) {
1298
		setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
1299

    
1300
	}
1301

    
1302
    /**
1303
     * @return
1304
     */
1305
    public static boolean isShowUpWidgetIsDisposedMessages() {
1306
       return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1307
    }
1308
    public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1309
        setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1310
    }
1311

    
1312
    /**
1313
     * @return
1314
     */
1315
    public static boolean isShowIdInVocabularyInChecklistEditor() {
1316
        String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1317
        if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
1318
            return true;
1319
        }else{
1320
            return false;
1321
        }
1322
    }
1323
    public static boolean isShowSymbol1InChecklistEditor() {
1324
        String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1325
        if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
1326
            return true;
1327
        }else{
1328
            return false;
1329
        }
1330
     }
1331
    public static boolean isShowSymbol2InChecklistEditor() {
1332
        String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1333
        if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
1334
            return true;
1335
        }else{
1336
            return false;
1337
        }
1338
     }
1339
    public static void setAreaDisplayInChecklistEditor(String selection) {
1340
        setStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
1341
    }
1342

    
1343
    public static void setOwnDescriptionForChecklistEditor(boolean selection) {
1344
        setBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
1345
    }
1346

    
1347
    public static boolean isOwnDescriptionForChecklistEditor() {
1348
        return getBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
1349
    }
1350

    
1351
    /**
1352
     * @return
1353
     */
1354
    public static String displayStatusInChecklistEditor() {
1355
       return getStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey());
1356
    }
1357
    public static void setDisplayStatusInChecklistEditor(String selection) {
1358
        setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), selection);
1359
    }
1360

    
1361
    /**
1362
     * @return
1363
     */
1364
    public static boolean isShowRankInChecklistEditor() {
1365
        return getBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey());
1366
    }
1367
    public static void setShowRankInChecklistEditor(boolean selection) {
1368
       setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
1369
    }
1370

    
1371
    /**
1372
     * @param object
1373
     * @param b
1374
     * @return
1375
     */
1376
    public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1377
        NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1378
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
1379
        CdmPreference preference = null;
1380

    
1381
        if (!local) {
1382
            preference = cache.get(EditorPreferencePredicate.NameDetailsView.getKey());
1383
            if (preference == null){
1384
                return null;
1385
            }
1386

    
1387
            setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1388

    
1389
            //the preference value is build like this:
1390
            //<section1>:true;<section2>:false....
1391

    
1392
            String value = preference.getValue();
1393
            String [] sections = value.split(";");
1394
            Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1395
            String[] sectionValues;
1396
            for (String sectionValue: sections){
1397
                sectionValues = sectionValue.split(":");
1398
                sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1399
            }
1400
            config.setAllowOverride(preference.isAllowOverride());
1401
            config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1402

    
1403
    //        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
1404
    //                (getValue(sectionMap, "taxon")));
1405
            config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1406

    
1407
            config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecEnabled"));
1408
            config.setSecEnabled(getValue(sectionMap, "taxon.SecDetails"));
1409

    
1410
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
1411
    //                (getValue(sectionMap, "lsid")));
1412
            config.setLSIDActivated(getValue(sectionMap, "lsid"));
1413

    
1414
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1415
    //                (getValue(sectionMap, "nc")));
1416
            config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1417

    
1418
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1419
    //                (getValue(sectionMap, "ap")));
1420
            config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1421

    
1422
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
1423
    //                (getValue(sectionMap, "rank")));
1424
            config.setRankActivated(getValue(sectionMap, "rank"));
1425

    
1426

    
1427
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1428
    //                (getValue(sectionMap, "atomisedEpithets")));
1429
            config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1430

    
1431
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1432
    //                (getValue(sectionMap,"author")));
1433
            config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1434

    
1435
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1436
    //                (getValue(sectionMap, "nomRef")));
1437
            config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1438

    
1439
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1440
    //                (getValue(sectionMap, "nomStat")));
1441
            config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1442

    
1443

    
1444
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1445
    //                (getValue(sectionMap,"protologue")));
1446
            config.setProtologueActivated(getValue(sectionMap,"protologue"));
1447

    
1448
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1449
    //                (getValue(sectionMap,"typeDes")));
1450
            config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1451

    
1452
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1453
    //                (getValue(sectionMap,"nameRelation")));
1454
            config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1455

    
1456
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
1457
    //                (getValue(sectionMap, "hybrid")));
1458
            config.setHybridActivated(getValue(sectionMap,"hybrid"));
1459
        }else{
1460
            config.setSimpleDetailsViewActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION));
1461
            config.setTaxonSectionActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON));
1462
            config.setSecDetailsActivated(getBooleanValue(SHOW_SEC_DETAILS));
1463
            config.setSecEnabled(getBooleanValue(DISABLE_SEC));
1464
            config.setLSIDActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID));
1465
            config.setNomenclaturalCodeActived(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1466
            config.setAppendedPhraseActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1467
            config.setRankActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK));
1468
            config.setAtomisedEpithetsActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1469
            config.setAuthorshipSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1470
            config.setNomenclaturalReferenceSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1471
            config.setNomenclaturalStatusSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1472
            config.setProtologueActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1473
            config.setTypeDesignationSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1474
            config.setNameRelationsSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1475
            config.setHybridActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID));
1476
        }
1477
        return config;
1478
    }
1479

    
1480
    /**
1481
     * @param object
1482
     * @param b
1483
     * @return
1484
     */
1485
    public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1486
        CdmPreference preference = null;
1487

    
1488
        if (!local) {
1489
            preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), EditorPreferencePredicate.NameDetailsView, config.toString());
1490

    
1491
            setPreferenceToDB(preference);
1492
        }
1493
        //also add to local preferences
1494
        setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION, config.isSimpleDetailsViewActivated());
1495
        setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1496
        setBooleanValue(SHOW_SEC_DETAILS, config.isSecDetailsActivated());
1497
        setBooleanValue(DISABLE_SEC, config.isSecEnabled());
1498
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1499
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, config.isNomenclaturalCodeActived());
1500
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, config.isAppendedPhraseActivated());
1501
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1502
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, config.isAtomisedEpithetsActivated());
1503
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, config.isAuthorshipSectionActivated());
1504
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, config.isNomenclaturalReferenceSectionActivated());
1505
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, config.isNomenclaturalStatusSectionActivated());
1506
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, config.isProtologueActivated());
1507
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, config.isTypeDesignationSectionActivated());
1508
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, config.isNameRelationsSectionActivated());
1509
        setBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID, config.isHybridActivated());
1510

    
1511
    }
1512

    
1513
    private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1514
		if (sectionMap.containsKey(string)){
1515
			return sectionMap.get(string);
1516
		}else{
1517
			return true;
1518
		}
1519

    
1520
	}
1521

    
1522

    
1523

    
1524
    /**
1525
     * <p>
1526
     * setAbcdConfigurator
1527
     * </p>
1528
     *
1529
     * @param preferredConfiguration
1530
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1531
     *            object.
1532
     */
1533
    public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1534

    
1535
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1536
        ICdmRepository controller;
1537
        controller = CdmStore.getCurrentApplicationConfiguration();
1538
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AbcdImportConfig);
1539
        CdmPreference preference = null;
1540
        if (controller == null){
1541
            return null;
1542
        }
1543
        preference = controller.getPreferenceService().find(key);
1544
        if (preference == null){
1545
            return config;
1546
         } else{
1547
             String configString = preference.getValue();
1548
             String[] configArray = configString.split(";");
1549

    
1550
             for (String configItem: configArray){
1551
                 String[] keyValue = configItem.split(":");
1552
                 String keyString = keyValue[0];
1553
                 String valueString = null;
1554
                 if (keyValue.length>1){
1555
                      valueString = keyValue[1];
1556
                 }
1557
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1558
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1559
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1560
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1561
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1562
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1563
                 }else if (keyString.equals("ignoreAuthorship")){
1564
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1565
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1566
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1567
                 }else if (keyString.equals("reuseExistingMetaData")){
1568
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1569
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1570
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1571
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1572
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1573
                 }else if (keyString.equals("deduplicateReferences")){
1574
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1575
                 }else if (keyString.equals("deduplicateClassifications")){
1576
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1577
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1578
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1579
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1580
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1581
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1582
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1583
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1584
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1585
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1586
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1587
                 }else if (keyString.equals("nomenclaturalCode")){
1588
                         config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1589
                 }else{
1590
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1591
                 }
1592

    
1593
             }
1594
        }
1595
        return config;
1596
    }
1597

    
1598
    public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1599
       Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1600

    
1601
        config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1602

    
1603
        config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1604

    
1605
        config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1606
        config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1607
        config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1608
        config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
1609
        config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1610
        config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1611
        config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1612
        config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1613
        config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1614
        config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1615
        config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1616
        config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1617
        config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1618
        config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1619
        config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1620
        config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1621

    
1622
        return config;
1623

    
1624
    }
1625

    
1626

    
1627
    public static void updateAbcdImportConfigurationPreference() {
1628
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
1629
        CdmPreference pref = cache.get(EditorPreferencePredicate.AbcdImportConfig.getKey());
1630

    
1631
        if (!getBooleanValue(prefOverrideKey(EditorPreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
1632
            resetToDBPreferenceAbcdCOnfigurator();
1633

    
1634
        }
1635
    }
1636

    
1637
    public static void resetToDBPreferenceAbcdCOnfigurator(){
1638
        Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
1639
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1640
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1641

    
1642
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1643
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1644
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1645

    
1646
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1647
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1648
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1649
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1650
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1651
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1652
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1653
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1654
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1655
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1656
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1657
        if (config.getNomenclaturalCode() != null){
1658
            setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1659
        }
1660
    }
1661

    
1662

    
1663
    /**
1664
    *
1665
    */
1666
   public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
1667
       NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1668
       if (local){
1669
          config.setSimpleDetailsViewActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
1670
          config.setAppendedPhraseActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1671
          config.setAtomisedEpithetsActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1672
          config.setAuthorshipSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1673
          config.setLSIDActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
1674
          config.setNameApprobiationActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
1675
          config.setNameCacheActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
1676
          config.setNameRelationsSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1677
          config.setNomenclaturalCodeActived(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1678
          config.setNomenclaturalStatusSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1679
          config.setNomenclaturalReferenceSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1680
          config.setProtologueActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1681
          config.setRankActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
1682
          config.setTaxonSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
1683
          config.setTypeDesignationSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1684
          config.setHybridActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
1685
       }else{
1686

    
1687
       }
1688

    
1689
      return config;
1690
   }
1691

    
1692

    
1693
   public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
1694
       setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
1695
               config.isSimpleDetailsViewActivated());
1696
       setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1697
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1698
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1699
               config.isNomenclaturalCodeActived());
1700
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
1701
               config.isNameCacheActivated());
1702
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1703
               config.isAppendedPhraseActivated());
1704
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1705
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1706
               config.isAtomisedEpithetsActivated());
1707
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
1708
               config.isAuthorCacheActivated());
1709
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1710
               config.isAuthorshipSectionActivated());
1711
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1712
               config.isNomenclaturalReferenceSectionActivated());
1713
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1714
               config.isNomenclaturalStatusSectionActivated());
1715
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1716
               config.isProtologueActivated());
1717
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1718
               config.isTypeDesignationSectionActivated());
1719
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1720
               config.isNameRelationsSectionActivated());
1721
       setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
1722
               config.isHybridActivated());
1723

    
1724
   }
1725

    
1726
/**
1727
 * @return
1728
 */
1729
public static boolean isSortTaxaByRankAndName() {
1730

    
1731
    return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1732
}
1733

    
1734
/**
1735
 * @return
1736
 */
1737
public static boolean isSortNamedAreaByOrderInVocabulary() {
1738

    
1739
    return getBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey());
1740
}
1741

    
1742
public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
1743
    setBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey(), isSortByVocabularyOrder);
1744

    
1745
}
1746

    
1747
/**
1748
 * <p>
1749
 * setPreferredNamedAreasForDistributionEditor
1750
 * </p>
1751
 *
1752
 * @param saveCheckedElements
1753
 * @param saveGrayedElements
1754
 */
1755
public static void setLastSelectedReference(
1756
        List<String> lastSelectedReferences) {
1757

    
1758
        setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1759
    }
1760

    
1761
/**
1762
 * <p>
1763
 * setPreferredNamedAreasForDistributionEditor
1764
 * </p>
1765
 *
1766
 * @param saveCheckedElements
1767
 * @param saveGrayedElements
1768
 */
1769
public static List<String> getLastSelectedReferences() {
1770

    
1771
        //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1772
        String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
1773
        List<String> result = new ArrayList<>();
1774
        if (!StringUtils.isBlank(lastSelected)){
1775
            Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1776
        }
1777
        return result;
1778
    }
1779

    
1780

    
1781
/**
1782
 * <p>
1783
 * setPreferredNamedAreasForDistributionEditor
1784
 * </p>
1785
 *
1786
 * @param saveCheckedElements
1787
 * @param saveGrayedElements
1788
 */
1789
public static void setPreferredNamedAreasForDistributionEditor(
1790
        String saveCheckedElements, String saveGrayedElements, boolean local) {
1791
    if (local){
1792
        setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
1793

    
1794
    }
1795
    else{
1796
        CdmPreference preference = null;
1797

    
1798
        if (saveCheckedElements == null){
1799
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1800

    
1801
            if (preference == null){
1802
                return ;
1803
            } else{
1804
                setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1805
                        saveCheckedElements);
1806
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1807
                setPreferenceToDB(preference);
1808

    
1809
            }
1810
        } else{
1811
           preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1812
           setPreferenceToDB(preference);
1813
           setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1814
                    saveCheckedElements);
1815

    
1816
        }
1817
    }
1818

    
1819
}
1820

    
1821
/**
1822
 * @param saveCheckedElements
1823
 * @param saveCheckedElements2
1824
 * @param b
1825
 */
1826
public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1827
        boolean local, boolean isOverride) {
1828
    if (local){
1829
      setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
1830
      setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
1831
    }
1832
    else{
1833
        ICdmRepository controller;
1834
        CdmPreference preference = null;
1835

    
1836
        if (saveCheckedElements == null){
1837
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1838

    
1839
            if (preference == null){
1840
                return ;
1841
            } else{
1842
                setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1843
                        saveCheckedElements);
1844
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1845
                preference.setAllowOverride(isOverride);
1846
                setPreferenceToDB(preference);
1847
            }
1848
        } else{
1849
            preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1850
            preference.setAllowOverride(isOverride);
1851
            setPreferenceToDB(preference);
1852
            setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1853
                    saveCheckedElements);
1854

    
1855
        }
1856
    }
1857
}
1858

    
1859

    
1860

    
1861

    
1862
/**
1863
 * @param saveCheckedElements
1864
 * @param saveCheckedElements2
1865
 * @param b
1866
 */
1867
public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1868
    if (local){
1869

    
1870
        String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
1871
        return pref;
1872
    }
1873
    else{
1874
        CdmPreference preference = null;
1875
        preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1876
        if (preference == null){
1877
            return null;
1878
        } else{
1879
            return preference.getValue();
1880
        }
1881

    
1882
    }
1883

    
1884

    
1885

    
1886
}
1887

    
1888
public static boolean getFilterCommonNameReferences(){
1889
    return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1890
}
1891

    
1892
/**
1893
 *
1894
 */
1895
public static void updateDBPreferences() {
1896
    CdmPreference preference = null;
1897
    CdmPreferenceCache cache = CdmPreferenceCache.instance();
1898
    cache.getAllTaxEditorDBPreferences();
1899

    
1900
    //ABCD Configurator
1901

    
1902
    updateAbcdImportConfigurationPreference();
1903

    
1904
    //Name Details
1905
    NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1906
    if (config != null ){
1907
        if (!getBooleanValue(OVERRIDE_NAME_DETAILS) ||  !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1908
            setPreferredNameDetailsConfiguration(config, false);
1909
        }
1910
    }
1911

    
1912

    
1913

    
1914

    
1915

    
1916

    
1917

    
1918

    
1919
}
1920

    
1921

    
1922

    
1923

    
1924

    
1925

    
1926

    
1927

    
1928
}
(22-22/31)