Project

General

Profile

Download (61.1 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.metadata.TermDisplayEnum;
60
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
61
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
62
import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
63
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
64
import eu.etaxonomy.cdm.strategy.match.MatchException;
65
import eu.etaxonomy.cdm.strategy.match.MatchMode;
66
import eu.etaxonomy.taxeditor.model.AbstractUtility;
67
import eu.etaxonomy.taxeditor.model.MessagingUtils;
68
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
69
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
70
import eu.etaxonomy.taxeditor.store.CdmStore;
71
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
72
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
73

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

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

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

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

    
95

    
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
	static String prefKey(String name) {
111
	    return name + "_"+  ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
112
	}
113

    
114
	public static String prefOverrideKey(String name) {
115
        return name + "_OVERRIDE_";
116
    }
117

    
118
	/**
119
     * <p>
120
     * setStringValue
121
     * </p>
122
     *
123
     *
124
     **/
125
    public static void setStringValue(String name, String value) {
126
        if (value != null){
127
            getPreferenceStore().setValue(prefKey(name), value);
128
        }else{
129
            getPreferenceStore().setToDefault(name);
130
        }
131
    }
132

    
133
    /**
134
     * <p>
135
     * setIntValue
136
     * </p>
137
     *
138
     *
139
     **/
140
    public static void setIntValue(String name, int value) {
141
        getPreferenceStore().setValue(prefKey(name), value);
142
    }
143

    
144
    /**
145
     * <p>
146
     * setBooleanValue
147
     * </p>
148
     *
149
     *
150
     **/
151
    public static void setBooleanValue(String name, boolean value) {
152
        getPreferenceStore().setValue(prefKey(name), value);
153
    }
154

    
155
    /**
156
     * <p>
157
     * setBooleanValue
158
     * </p>
159
     *
160
     *
161
     **/
162
    public static void setDoubleValue(String name, double value) {
163
        getPreferenceStore().setValue(prefKey(name), value);
164
    }
165

    
166
    /**
167
     * <p>
168
     * setFloatValue
169
     * </p>
170
     *
171
     *
172
     **/
173
    public static void setFloatValue(String name, float value) {
174
        getPreferenceStore().setValue(name + ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(), value);
175
    }
176

    
177
    /**
178
     * <p>
179
     * setFloatValue
180
     * </p>
181
     *
182
     *
183
     **/
184
    public static void setLongValue(String name, long value) {
185
        getPreferenceStore().setValue(prefKey(name), value);
186
    }
187

    
188
    /**
189
     * <p>
190
     * getStringValue
191
     * </p>
192
     *
193
     *
194
     **/
195
    public static String getStringValue(String name, boolean local) {
196

    
197
        String prefValue = getDBPreferenceValue(name);
198
        if (prefValue == null || local){
199
            String dbSpecific = prefKey(name);
200
            if (getPreferenceStore().contains(dbSpecific)){
201
                prefValue = getPreferenceStore().getString(dbSpecific);
202
            }else{
203
                prefValue = getPreferenceStore().
204
                        getString(name);
205
            }
206
        }
207
        return prefValue;
208

    
209
    }
210

    
211
    public static String getStringValue(String name){
212
        return getStringValue(name, false);
213
    }
214

    
215
    private static String getDBPreferenceValue(String name) {
216
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
217
        if (cache.get(name) != null){
218
            CdmPreference pref = cache.get(name);
219
            if (!pref.isAllowOverride() || !getBooleanValue(prefOverrideKey(name))){
220
                return pref.getValue();
221
            }
222
        }
223
        return null;
224
    }
225

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

    
252

    
253
    }
254

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

    
277
        }else{
278
            return getPreferenceStore().getBoolean(name);
279
        }
280

    
281
    }
282

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

    
309
    }
310

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

    
337
    }
338

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

    
366

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

    
396
    		if (preferenceValue == null){
397
    			preference = controller.getPreferenceService().find(key);
398
    			if (preference == null){
399
    				return null;
400
    			} else{
401
    			    setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
402
    				        preference.getValue());
403

    
404
    				return preference;
405
    			}
406
    		} else{
407
    			preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
408
    			controller.getPreferenceService().set(preference);
409

    
410
    		}
411
	    }
412
        return null;
413

    
414

    
415

    
416
	}
417

    
418
	/**
419
     * <p>
420
     * setPreferredNomenclaturalCode
421
     * </p>
422
     *
423
     * @param preferredCode
424
     *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
425
     *            object.
426
     */
427
    public static void setPreferredNomenclaturalCode(
428
        CdmPreference preference) {
429

    
430
        ICdmRepository controller;
431
        controller = CdmStore.getCurrentApplicationConfiguration();
432
        if (controller == null){
433
            return;
434
        }
435
        PrefKey key = null;
436
        try{
437
            key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
438
        }catch (Exception e){
439
            System.out.println(e.getStackTrace());
440
        }
441

    
442
        controller.getPreferenceService().set(preference);
443

    
444
    }
445

    
446

    
447
	public static NomenclaturalCode getPreferredNomenclaturalCode(){
448
	    if (getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey()))) {
449
            return getPreferredNomenclaturalCode(true);
450
        } else{
451
            return getPreferredNomenclaturalCode(false);
452
        }
453
	}
454

    
455
	/**
456
	 * <p>
457
	 * getPreferredNomenclaturalCode
458
	 * </p>
459
	 *
460
	 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
461
	 */
462
	public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
463

    
464
		CdmPreference pref = null;
465
		if (!useLocal){
466
		    pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
467
		}
468

    
469
	    String preferredCode;
470
	    if(pref == null){
471
	    	preferredCode = getStringValue(
472
					PREFERRED_NOMENCLATURAL_CODE_KEY, true);
473

    
474
	    }else{
475
	    	preferredCode = pref.getValue();
476
	    }
477

    
478
	    return getPreferredNomenclaturalCode(preferredCode);
479

    
480
	}
481

    
482
	/**
483
     * <p>
484
     * getPreferredNomenclaturalCode
485
     * </p>
486
     *
487
     * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
488
     */
489
    public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
490

    
491
        for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
492
            if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
493
                return code;
494
            }
495
        }
496
        return null;
497
    }
498

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

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

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

    
514
	public static boolean isCollectingAreaInGeneralSection(){
515
	    boolean result =  getBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
516
        return result;
517
	}
518

    
519
	public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
520
        ICdmRepository controller;
521
        CdmPreference pref = null;
522

    
523
        try{
524
            if(CdmStore.isActive()){
525
                controller = CdmStore.getCurrentApplicationConfiguration();
526
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
527
                pref = controller.getPreferenceService().find(key);
528
            }
529
        }catch(Exception e){
530
            e.printStackTrace();
531
        }
532

    
533
        return pref;
534

    
535
    }
536

    
537
    public static void setPreferenceToDB(CdmPreference preference){
538
        ICdmRepository controller;
539
        try{
540
            if(CdmStore.isActive()){
541
                controller = CdmStore.getCurrentApplicationConfiguration();
542
                controller.getPreferenceService().set(preference);
543
            }
544
        }catch(Exception e){
545
            e.printStackTrace();
546
        }
547

    
548
    }
549

    
550

    
551

    
552
	public static String getPreferredDefaultLangugae(){
553
	    String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
554
	    if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
555
	        return preferredLanguage;
556
	    }
557
	    return null;
558
	}
559

    
560
	public static boolean isShowMediaPreview(){
561
        boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
562
        return isShowMediaPreview;
563
    }
564

    
565
	/**
566
	 * Get the match strategy for the given class that was stored in preferences
567
	 * or the default strategy if it was not stored in preferences
568
	 *
569
	 * @param clazz
570
	 *            a {@link java.lang.Class} object.
571
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
572
	 */
573
	public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
574
		String className = clazz.getName();
575
		if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
576
			IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
577

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

    
592
			return matchStrategy;
593
		}
594
		return getDefaultMatchStrategy(clazz);
595
	}
596

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

    
608
		List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
609

    
610
		for (FieldMatcher fieldMatcher : fieldMatchers) {
611
			String fieldName = fieldMatcher.getPropertyName();
612
			setStringValue(
613
					getMatchStrategyFieldName(className, fieldName),
614
					fieldMatcher.getMatchMode().name());
615
		}
616
	}
617

    
618
	/**
619
	 * Helper method to create the preference property for a match field.
620
	 *
621
	 * @param className
622
	 * @param fieldName
623
	 * @return
624
	 */
625
	private static String getMatchStrategyFieldName(String className,
626
			String fieldName) {
627
		return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
628
	}
629

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

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

    
654
	/**
655
	 * <p>
656
	 * addTermToPreferredTerms
657
	 * </p>
658
	 *
659
	 * @param term
660
	 *            a T object.
661
	 * @param <T>
662
	 *            a T object.
663
	 */
664
	public static <T extends TermBase> void addTermToPreferredTerms(T term) {
665

    
666
		// VocabularyEnum vocabulary =
667
		// VocabularyEnum.getVocabularyEnum(term.getClass());
668
		//
669
		// getPreferenceStore().setValue(getPreferenceKey(term),
670
		// VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
671
		//
672
		// firePreferencesChanged(term.getClass());
673
	}
674

    
675
	/**
676
	 * Construct a unique key using the CdmBase object's uuid
677
	 *
678
	 * @param cdmBase
679
	 * @return
680
	 */
681
	private static String getPreferenceKey(ICdmBase cdmBase) {
682
		cdmBase = HibernateProxyHelper.deproxy(cdmBase);
683

    
684
		String key = cdmBase.getClass().getName().concat(".")
685
				.concat(cdmBase.getUuid().toString());
686
		if (key.contains("javassist")) {
687
			MessagingUtils.info("proxy");
688
		}
689
		return key;
690
	}
691

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

    
709

    
710

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

    
728
	/**
729
	 * Retrieves search preferences from the preference store
730
	 *
731
	 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
732
	 */
733
	public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
734
		IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
735

    
736
		configurator.setDoTaxa(getBooleanValue(
737
				TAXON_SERVICE_CONFIGURATOR_TAXA));
738
		configurator.setDoSynonyms(getBooleanValue(
739
				TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
740
		configurator.setDoNamesWithoutTaxa(getBooleanValue(
741
				TAXON_SERVICE_CONFIGURATOR_NAMES));
742
		configurator.setDoTaxaByCommonNames(getBooleanValue(
743
				TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
744
		//configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
745

    
746
		return configurator;
747
	}
748

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

    
759
		configurator.setDoTaxa(true);
760
		configurator.setDoSynonyms(true);
761
		configurator.setDoNamesWithoutTaxa(true);
762
		configurator.setDoTaxaByCommonNames(true);
763

    
764
		configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
765
				"name", "name.$", "relationsFromThisTaxon.$"));
766

    
767
		configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
768
				"name", "name.$", "synonyms.relatedTo.*"));
769

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

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

    
803
	/**
804
	 * <p>
805
	 * firePreferencesChanged
806
	 * </p>
807
	 *
808
	 * @param clazz
809
	 *            a {@link java.lang.Class} object.
810
	 */
811
	public static void firePreferencesChanged(Class clazz) {
812
		getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
813
				null, clazz);
814
	}
815

    
816
	public static String createPreferenceString(String property){
817
	   return prefKey(property);
818

    
819
	}
820
	public static String createOverridePreferenceString(String property){
821
	       return prefOverrideKey(property);
822

    
823
	    }
824

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

    
845

    
846
		//Name Details
847
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
848

    
849
		//Navigator preferences
850
		getPreferenceStore().setDefault(createPreferenceString(SORT_NODES), NavigatorOrderEnum.RankAndNameOrder.getKey());
851

    
852
		getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
853
		//override db preferences
854
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.AbcdImportConfig.getKey())), false);
855
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.ShowSpecimen.getKey())), true);
856
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.NameDetailsView.getKey())), false);
857
		getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(EditorPreferencePredicate.DistributionEditorActivated.getKey())), false);
858

    
859
		getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
860
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
861
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
862
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(EditorPreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
863
		getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(EditorPreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
864

    
865
	}
866

    
867
	/**
868
	 * <p>
869
	 * checkNomenclaturalCode
870
	 * </p>
871
	 */
872
	public static void checkNomenclaturalCode() {
873
		// First time Editor is opened, no nomenclatural code has been set
874
		if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
875
			PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
876
		}
877

    
878

    
879

    
880
	}
881
	public static void setNomenclaturalCodePreferences(){
882
	    ICdmRepository controller;
883
        controller = CdmStore.getCurrentApplicationConfiguration();
884
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
885
        CdmPreference preference = null;
886
        if (controller == null){
887
            return ;
888
        }
889
        preference = controller.getPreferenceService().find(key);
890
        if (preference == null){
891
            return;
892
        }
893
//        setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
894

    
895
        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
896
        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
897
        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
898

    
899
        setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
900
                getPreferenceKey(preferredCode));
901

    
902
	}
903

    
904
	public static void checkDefaultLanguage(){
905
	    if(PreferencesUtil.getPreferredDefaultLangugae() == null){
906
	       Shell shell = AbstractUtility.getShell();
907
	       int open = new DefaultLanguageDialog(shell).open();
908
	       if(open == Window.OK){
909
	           PlatformUI.getWorkbench().restart();
910
	       }
911
	    }else{
912
	        //TODO:In case of a reinstall, the config.ini will be overwritten
913
	        //     here you create config.ini with the stored key from preferences
914
	    }
915
	}
916

    
917
	/**
918
	 * <p>
919
	 * getMapServiceAccessPoint
920
	 * </p>
921
	 *
922
	 * @return a {@link java.lang.String} object.
923
	 */
924
	public static String getMapServiceAccessPoint() {
925
		return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
926
	}
927

    
928
	/**
929
	 * <p>
930
	 * shouldConnectAtStartUp
931
	 * </p>
932
	 *
933
	 * @return a boolean.
934
	 */
935
	public static boolean shouldConnectAtStartUp() {
936
		//FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
937
		//return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
938
		return false;
939
	}
940

    
941
	/**
942
	 * <p>
943
	 * getDefaultFeatureTreeForTextualDescription
944
	 * </p>
945
	 *
946
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
947
	 */
948
	public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
949
		String uuidString = getStringValue(
950
				FEATURE_TREE_DEFAULT_TEXT);
951
		if (StringUtils.isBlank(uuidString)) {
952
            return null;
953
        }
954
		FeatureTree tree = CdmStore.getService(
955
	                IFeatureTreeService.class).load(UUID.fromString(uuidString));
956
		if (tree.getId() == 0) {
957
            return null;
958
        }
959
		return tree;
960
	}
961

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

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

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

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

    
1004
	public static Language getGlobalLanguage() {
1005

    
1006

    
1007
		String languageUuidString = getStringValue(
1008
				GLOBAL_LANGUAGE_UUID);
1009

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

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

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

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

    
1030
	}
1031

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

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

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

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

    
1048
		return result;
1049
	}
1050

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

    
1062
	}
1063

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

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

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

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

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

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

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

    
1178

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

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

    
1210
        return p2Repos;
1211
    }
1212

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

    
1230

    
1231

    
1232

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

    
1239
    }
1240

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

    
1247
    }
1248

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

    
1256
    }
1257

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

    
1265
    }
1266

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

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

    
1286
	}
1287

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

    
1299
	}
1300

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

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

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

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

    
1350
    /**
1351
     * @return
1352
     */
1353
    public static String displayAreaInChecklistEditor() {
1354
        String result = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1355
        if (result == null){
1356
            return (String) EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue();
1357
        }
1358
       return result;
1359
    }
1360

    
1361
    /**
1362
     * @return
1363
     */
1364
    public static String displayStatusInChecklistEditor() {
1365
        String result = getStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey());
1366
        if (result == null){
1367
            return (String) EditorPreferencePredicate.DisplayOfStatus.getDefaultValue();
1368
        }
1369
       return result;
1370
    }
1371
    public static void setDisplayStatusInChecklistEditor(String selection) {
1372
        setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), selection);
1373

    
1374
    }
1375

    
1376
    /**
1377
     * @return
1378
     */
1379
    public static boolean isShowRankInChecklistEditor() {
1380
        return getBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey());
1381
    }
1382
    public static void setShowRankInChecklistEditor(boolean selection) {
1383
       setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
1384
    }
1385

    
1386
    /**
1387
     * @param object
1388
     * @param b
1389
     * @return
1390
     */
1391
    public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1392
        NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1393
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
1394
        CdmPreference preference = null;
1395
        String value;
1396
        if (!local) {
1397
            preference = cache.get(EditorPreferencePredicate.NameDetailsView.getKey());
1398
            if (preference == null){
1399
                return null;
1400
            }
1401

    
1402
            setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1403
            value = preference.getValue();
1404
            config.setAllowOverride(preference.isAllowOverride());
1405
            //the preference value is build like this:
1406
            //<section1>:true;<section2>:false....
1407
        }else{
1408
            value = getStringValue(EditorPreferencePredicate.NameDetailsView.getKey(), local);
1409
        }
1410
        String [] sections = value.split(";");
1411
        Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1412
        String[] sectionValues;
1413
        for (String sectionValue: sections){
1414
            sectionValues = sectionValue.split(":");
1415
            sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1416
        }
1417

    
1418
        config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1419

    
1420
            config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1421

    
1422
        config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1423
        config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1424

    
1425
        config.setLSIDActivated(getValue(sectionMap, "lsid"));
1426

    
1427
        config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1428

    
1429
        config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1430

    
1431
        config.setRankActivated(getValue(sectionMap, "rank"));
1432

    
1433
        config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1434

    
1435
        config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1436

    
1437
        config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1438

    
1439
        config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1440

    
1441
        config.setProtologueActivated(getValue(sectionMap,"protologue"));
1442

    
1443
        config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1444

    
1445
        config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1446

    
1447
            config.setHybridActivated(getValue(sectionMap,"hybrid"));
1448

    
1449
        return config;
1450
    }
1451

    
1452
    /**
1453
     * @param object
1454
     * @param b
1455
     * @return
1456
     */
1457
    public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1458
        CdmPreference preference = null;
1459

    
1460
        if (!local) {
1461
            preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.NameDetailsView, config.toString());
1462

    
1463
            setPreferenceToDB(preference);
1464
        }
1465
        else{
1466
            setStringValue(EditorPreferencePredicate.NameDetailsView.getKey(), config.toString());
1467
        }
1468

    
1469

    
1470
    }
1471

    
1472
    private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1473
		if (sectionMap.containsKey(string)){
1474
			return sectionMap.get(string);
1475
		}else{
1476
			return true;
1477
		}
1478

    
1479
	}
1480

    
1481

    
1482

    
1483
    /**
1484
     * <p>
1485
     * setAbcdConfigurator
1486
     * </p>
1487
     *
1488
     * @param preferredConfiguration
1489
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1490
     *            object.
1491
     */
1492
    public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1493

    
1494
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1495
        ICdmRepository controller;
1496
        controller = CdmStore.getCurrentApplicationConfiguration();
1497
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AbcdImportConfig);
1498
        CdmPreference preference = null;
1499
        if (controller == null){
1500
            return null;
1501
        }
1502
        preference = controller.getPreferenceService().find(key);
1503
        if (preference == null){
1504
            return config;
1505
         } else{
1506
             String configString = preference.getValue();
1507
             String[] configArray = configString.split(";");
1508

    
1509
             for (String configItem: configArray){
1510
                 String[] keyValue = configItem.split(":");
1511
                 String keyString = keyValue[0];
1512
                 String valueString = null;
1513
                 if (keyValue.length>1){
1514
                      valueString = keyValue[1];
1515
                 }
1516
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1517
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1518
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1519
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1520
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1521
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1522
                 }else if (keyString.equals("ignoreAuthorship")){
1523
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1524
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1525
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1526
                 }else if (keyString.equals("reuseExistingMetaData")){
1527
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1528
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1529
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1530
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1531
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1532
                 }else if (keyString.equals("deduplicateReferences")){
1533
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1534
                 }else if (keyString.equals("deduplicateClassifications")){
1535
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1536
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1537
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1538
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1539
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1540
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1541
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1542
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1543
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1544
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1545
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1546
                 }else if (keyString.equals("nomenclaturalCode")){
1547
                         config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1548
                 }else{
1549
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1550
                 }
1551

    
1552
             }
1553
        }
1554
        return config;
1555
    }
1556

    
1557
    public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1558
       Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1559

    
1560
        config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1561

    
1562
        config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1563

    
1564
        config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1565
        config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1566
        config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1567
        config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
1568
        config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1569
        config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1570
        config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1571
        config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1572
        config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1573
        config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1574
        config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1575
        config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1576
        config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1577
        config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1578
        config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1579
        config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1580

    
1581
        return config;
1582

    
1583
    }
1584

    
1585

    
1586
    public static void updateAbcdImportConfigurationPreference() {
1587
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
1588
        CdmPreference pref = cache.get(EditorPreferencePredicate.AbcdImportConfig.getKey());
1589

    
1590
        if (!getBooleanValue(prefOverrideKey(EditorPreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
1591
            resetToDBPreferenceAbcdCOnfigurator();
1592

    
1593
        }
1594
    }
1595

    
1596
    public static void resetToDBPreferenceAbcdCOnfigurator(){
1597
        Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
1598
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1599
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1600

    
1601
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1602
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1603
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1604

    
1605
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1606
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1607
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1608
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1609
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1610
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1611
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1612
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1613
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1614
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1615
        setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1616
        if (config.getNomenclaturalCode() != null){
1617
            setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1618
        }
1619
    }
1620

    
1621

    
1622

    
1623

    
1624

    
1625

    
1626

    
1627
/**
1628
 * @return
1629
 */
1630
public static boolean isSortTaxaByRankAndName() {
1631

    
1632
    return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1633
}
1634

    
1635
/**
1636
 * @return
1637
 */
1638
public static String getSortNamedAreasInDistributionEditor() {
1639

    
1640
    return getStringValue(EditorPreferencePredicate.AreasSortedInDistributionEditor.getKey());
1641
}
1642

    
1643
public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
1644
    setStringValue(EditorPreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
1645

    
1646
}
1647

    
1648
/**
1649
 * <p>
1650
 * setPreferredNamedAreasForDistributionEditor
1651
 * </p>
1652
 *
1653
 * @param saveCheckedElements
1654
 * @param saveGrayedElements
1655
 */
1656
public static void setLastSelectedReference(
1657
        List<String> lastSelectedReferences) {
1658

    
1659
        setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1660
    }
1661

    
1662
/**
1663
 * <p>
1664
 * setPreferredNamedAreasForDistributionEditor
1665
 * </p>
1666
 *
1667
 * @param saveCheckedElements
1668
 * @param saveGrayedElements
1669
 */
1670
public static List<String> getLastSelectedReferences() {
1671

    
1672
        //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1673
        String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
1674
        List<String> result = new ArrayList<>();
1675
        if (!StringUtils.isBlank(lastSelected)){
1676
            Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1677
        }
1678
        return result;
1679
    }
1680

    
1681

    
1682
/**
1683
 * <p>
1684
 * setPreferredNamedAreasForDistributionEditor
1685
 * </p>
1686
 *
1687
 * @param saveCheckedElements
1688
 * @param saveGrayedElements
1689
 */
1690
public static void setPreferredNamedAreasForDistributionEditor(
1691
        String saveCheckedElements, String saveGrayedElements, boolean local) {
1692
    if (local){
1693
        setStringValue(EditorPreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
1694

    
1695
    }
1696
    else{
1697
        CdmPreference preference = null;
1698

    
1699
        if (saveCheckedElements == null){
1700
            preference = getPreferenceFromDB(EditorPreferencePredicate.AvailableDistributionAreaTerms);
1701

    
1702
            if (preference == null){
1703
                return ;
1704
            } else{
1705
                setStringValue(EditorPreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1706
                        saveCheckedElements);
1707
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1708
                setPreferenceToDB(preference);
1709

    
1710
            }
1711
        } else{
1712
           preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1713
           setPreferenceToDB(preference);
1714
           setStringValue(EditorPreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1715
                    saveCheckedElements);
1716

    
1717
        }
1718
    }
1719

    
1720
}
1721

    
1722
/**
1723
 * @param saveCheckedElements
1724
 * @param saveCheckedElements2
1725
 * @param b
1726
 */
1727
public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1728
        boolean local, boolean isOverride) {
1729
    if (local){
1730
      setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
1731
      setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
1732
    }
1733
    else{
1734
        ICdmRepository controller;
1735
        CdmPreference preference = null;
1736

    
1737
        if (saveCheckedElements == null){
1738
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1739

    
1740
            if (preference == null){
1741
                return ;
1742
            } else{
1743
                setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1744
                        saveCheckedElements);
1745
                preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1746
                preference.setAllowOverride(isOverride);
1747
                setPreferenceToDB(preference);
1748
            }
1749
        } else{
1750
            preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1751
            preference.setAllowOverride(isOverride);
1752
            setPreferenceToDB(preference);
1753
            setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1754
                    saveCheckedElements);
1755

    
1756
        }
1757
    }
1758
}
1759

    
1760

    
1761

    
1762

    
1763
/**
1764
 * @param saveCheckedElements
1765
 * @param saveCheckedElements2
1766
 * @param b
1767
 */
1768
public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1769
    if (local){
1770

    
1771
        String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
1772
        return pref;
1773
    }
1774
    else{
1775
        CdmPreference preference = null;
1776
        preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1777
        if (preference == null){
1778
            return null;
1779
        } else{
1780
            return preference.getValue();
1781
        }
1782

    
1783
    }
1784

    
1785

    
1786

    
1787
}
1788

    
1789
public static boolean getFilterCommonNameReferences(){
1790
    return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1791
}
1792

    
1793
/**
1794
 *
1795
 */
1796
public static void updateDBPreferences() {
1797
    CdmPreference preference = null;
1798
    CdmPreferenceCache cache = CdmPreferenceCache.instance();
1799
    cache.getAllTaxEditorDBPreferences();
1800

    
1801
    //ABCD Configurator
1802

    
1803
    updateAbcdImportConfigurationPreference();
1804

    
1805
    //Name Details
1806
    NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1807
    if (config != null ){
1808
        if (!getBooleanValue(OVERRIDE_NAME_DETAILS) ||  !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1809
            setPreferredNameDetailsConfiguration(config, false);
1810
        }
1811
    }
1812

    
1813

    
1814

    
1815

    
1816

    
1817

    
1818

    
1819

    
1820
}
1821

    
1822

    
1823

    
1824

    
1825

    
1826

    
1827

    
1828

    
1829
}
(27-27/41)