Project

General

Profile

Download (65.4 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.Set;
26
import java.util.StringTokenizer;
27
import java.util.UUID;
28

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

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

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

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

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

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

    
93

    
94

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

    
106
	/**
107
	 * <p>
108
	 * setPreferredNomenclaturalCode
109
	 * </p>
110
	 *
111
	 * @param preferredCode
112
	 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
113
	 *            object.
114
	 */
115
	public static CdmPreference setPreferredNomenclaturalCode(
116
			String preferenceKey, boolean local) {
117
	    if (local){
118
	        getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
119
	                preferenceKey);
120
	    }
121
	    else{
122
    		ICdmRepository controller;
123
    		controller = CdmStore.getCurrentApplicationConfiguration();
124
    		if (controller == null){
125
                return null;
126
            }
127
    		PrefKey key = null;
128
    		try{
129
    		    key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
130
    		}catch (Exception e){
131
    		    System.out.println(e.getStackTrace());
132
    		}
133
    		CdmPreference preference = null;
134

    
135
    		if (preferenceKey == null){
136
    			preference = controller.getPreferenceService().find(key);
137
    			if (preference == null){
138
    				return null;
139
    			} else{
140
//    				int index = StringUtils.lastIndexOf(preference.getValue(), ".");
141
//    				UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
142
//    				preferredCode = NomenclaturalCode.getByUuid(uuid);
143

    
144
    				getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
145
    				        preferenceKey);
146
    				getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
147
    				return preference;
148
    			}
149
    		} else{
150
    			preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceKey);
151
    			controller.getPreferenceService().set(preference);
152

    
153
    		}
154
	    }
155
        return null;
156

    
157

    
158

    
159
	}
160

    
161
	public static NomenclaturalCode getPreferredNomenclaturalCode(){
162
	    if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
163
            return getPreferredNomenclaturalCode(true);
164
        } else{
165
            return getPreferredNomenclaturalCode(false);
166
        }
167
	}
168

    
169
	/**
170
	 * <p>
171
	 * getPreferredNomenclaturalCode
172
	 * </p>
173
	 *
174
	 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
175
	 */
176
	public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
177

    
178
		CdmPreference pref = null;
179
		if (!useLocal){
180
		    pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
181
		}
182

    
183
	    String preferredCode;
184
	    if(pref == null){
185
	    	preferredCode = getPreferenceStore().getString(
186
					PREFERRED_NOMENCLATURAL_CODE_KEY);
187

    
188
	    }else{
189
	    	preferredCode = pref.getValue();
190
	    }
191

    
192
	    return getPreferredNomenclaturalCode(preferredCode);
193

    
194
	}
195

    
196
	/**
197
     * <p>
198
     * getPreferredNomenclaturalCode
199
     * </p>
200
     *
201
     * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
202
     */
203
    public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
204

    
205
        for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
206
            if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
207
                return code;
208
            }
209
        }
210
        return null;
211
    }
212

    
213
	public static boolean isShowTaxonAssociations(){
214
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
215
            return getPreferenceStore().getBoolean(SHOW_TAXON_ASSOCIATIONS);
216
        } else{
217
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
218

    
219
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
220
        }
221
    }
222

    
223
	public static boolean isShowLifeForm(){
224
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
225
            return getPreferenceStore().getBoolean(SHOW_LIFE_FORM);
226
        } else{
227
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
228

    
229
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
230
        }
231
    }
232

    
233
	public static boolean isDeterminationOnlyForFieldUnits(){
234
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
235
            return getPreferenceStore().getBoolean(DETERMINATION_ONLY_FOR_FIELD_UNITS);
236
        } else{
237
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
238

    
239
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
240
        }
241
    }
242

    
243
	public static boolean isCollectingAreaInGeneralSection(){
244
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
245
            return getPreferenceStore().getBoolean(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
246
        } else{
247
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
248

    
249
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
250
        }
251
    }
252

    
253
	public static boolean isShowSimpleDetailsView(){
254
        if (getPreferenceStore().getBoolean(OVERRIDE_NAME_DETAILS) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_NAME_DETAILS)) {
255
            return getPreferenceStore().getBoolean(SHOW_SIMPLE_NAME_DETAILS_SECTION);
256
        } else{
257
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
258

    
259
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
260
        }
261
    }
262

    
263

    
264

    
265
    public static CdmPreference getPreferenceFromDB(PreferencePredicate predicate){
266
        ICdmRepository controller;
267
        CdmPreference pref = null;
268

    
269
        try{
270
            if(CdmStore.isActive()){
271
                controller = CdmStore.getCurrentApplicationConfiguration();
272
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), predicate);
273
                pref = controller.getPreferenceService().find(key);
274
            }
275
        }catch(Exception e){
276
            e.printStackTrace();
277
        }
278

    
279
        return pref;
280

    
281
    }
282

    
283
    public static void setPreferenceToDB(CdmPreference preference){
284
        ICdmRepository controller;
285
        try{
286
            if(CdmStore.isActive()){
287
                controller = CdmStore.getCurrentApplicationConfiguration();
288
                controller.getPreferenceService().set(preference);
289
            }
290
        }catch(Exception e){
291
            e.printStackTrace();
292
        }
293

    
294
    }
295

    
296

    
297

    
298
	public static String getPreferredDefaultLangugae(){
299
	    String preferredLanguage = getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR);
300
	    if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
301
	        return preferredLanguage;
302
	    }
303
	    return null;
304
	}
305

    
306
	public static boolean isShowMediaPreview(){
307
        boolean isShowMediaPreview = getPreferenceStore().getBoolean(SHOW_MEDIA_PREVIEW);
308
        return isShowMediaPreview;
309
    }
310

    
311
	/**
312
	 * Get the match strategy for the given class that was stored in preferences
313
	 * or the default strategy if it was not stored in preferences
314
	 *
315
	 * @param clazz
316
	 *            a {@link java.lang.Class} object.
317
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
318
	 */
319
	public static IMatchStrategy getMatchStrategy(Class clazz) {
320
		String className = clazz.getName();
321
		if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)) {
322
			IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
323

    
324
			for (String fieldName : matchStrategy.getMatchFieldPropertyNames()) {
325
				String matchModeName = getPreferenceStore().getString(
326
						getMatchStrategyFieldName(className, fieldName));
327
				MatchMode matchMode = MatchMode.valueOf(matchModeName);
328
				try {
329
					matchStrategy.setMatchMode(fieldName, matchMode);
330
				} catch (MatchException e) {
331
					MessagingUtils.error(PreferencesUtil.class, e);
332
					throw new RuntimeException(e);
333
				}
334
			}
335

    
336
			return matchStrategy;
337
		}
338
		return getDefaultMatchStrategy(clazz);
339
	}
340

    
341
	/**
342
	 * Stores a matchStrategy into the preference store.
343
	 *
344
	 * @param matchStrategy
345
	 *            a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
346
	 *            object.
347
	 */
348
	public static void setMatchStrategy(IMatchStrategy matchStrategy) {
349
		String className = matchStrategy.getMatchClass().getName();
350
		getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true);
351

    
352
		Set<String> matchFields = matchStrategy.getMatchFieldPropertyNames();
353

    
354
		for (String fieldName : matchFields) {
355
			getPreferenceStore().setValue(
356
					getMatchStrategyFieldName(className, fieldName),
357
					matchStrategy.getMatchMode(fieldName).name());
358
		}
359
	}
360

    
361
	/**
362
	 * Helper method to create the preference property for a match field.
363
	 *
364
	 * @param className
365
	 * @param fieldName
366
	 * @return
367
	 */
368
	private static String getMatchStrategyFieldName(String className,
369
			String fieldName) {
370
		return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
371
	}
372

    
373
	/**
374
	 * Returns the default match strategy for a given class.
375
	 *
376
	 * @param clazz
377
	 *            a {@link java.lang.Class} object.
378
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
379
	 */
380
	public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
381
		return DefaultMatchStrategy.NewInstance(clazz);
382
	}
383

    
384
	/**
385
	 * <p>
386
	 * getDateFormatPattern
387
	 * </p>
388
	 *
389
	 * @return a {@link java.lang.String} object.
390
	 */
391
	public static String getDateFormatPattern() {
392
		// TODO make this configurable in properties
393
		String pattern = "Y-M-d H:m";
394
		return pattern;
395
	}
396

    
397
	/**
398
	 * <p>
399
	 * addTermToPreferredTerms
400
	 * </p>
401
	 *
402
	 * @param term
403
	 *            a T object.
404
	 * @param <T>
405
	 *            a T object.
406
	 */
407
	public static <T extends TermBase> void addTermToPreferredTerms(T term) {
408

    
409
		// VocabularyEnum vocabulary =
410
		// VocabularyEnum.getVocabularyEnum(term.getClass());
411
		//
412
		// getPreferenceStore().setValue(getPreferenceKey(term),
413
		// VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
414
		//
415
		// firePreferencesChanged(term.getClass());
416
	}
417

    
418
	/**
419
	 * Construct a unique key using the CdmBase object's uuid
420
	 *
421
	 * @param cdmBase
422
	 * @return
423
	 */
424
	private static String getPreferenceKey(ICdmBase cdmBase) {
425
		cdmBase = HibernateProxyHelper.deproxy(cdmBase);
426

    
427
		String key = cdmBase.getClass().getName().concat(".")
428
				.concat(cdmBase.getUuid().toString());
429
		if (key.contains("javassist")) {
430
			MessagingUtils.info("proxy");
431
		}
432
		return key;
433
	}
434

    
435
	/**
436
	 * Construct a unique key using the CdmBase object's uuid
437
	 *
438
	 * @param cdmBase
439
	 * @return
440
	 */
441
	public static String getPreferenceKey(ISimpleTerm simpleTerm) {
442
		simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
443
		String key = simpleTerm.getClass().getName().concat(".")
444
				.concat(simpleTerm.getUuid().toString());
445
		if (key.contains("javassist")) {
446
			MessagingUtils.warn(PreferencesUtil.class,
447
					"Trying to persist a preference based on a proxy class.");
448
		}
449
		return key;
450
	}
451

    
452

    
453

    
454
	/**
455
	 * Construct a unique key using the CdmBase object's uuid
456
	 *
457
	 * @param cdmBase
458
	 * @return
459
	 */
460
	public static String getPreferenceKey(IDefinedTerm definedTerm) {
461
		definedTerm = HibernateProxyHelper.deproxy(definedTerm);
462
		String key = definedTerm.getClass().getName().concat(".")
463
				.concat(definedTerm.getUuid().toString());
464
		if (key.contains("javassist")) {
465
			MessagingUtils.warn(PreferencesUtil.class,
466
					"Trying to persist a preference based on a proxy class.");
467
		}
468
		return key;
469
	}
470

    
471
	/**
472
	 * Retrieves search preferences from the preference store
473
	 *
474
	 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
475
	 */
476
	public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
477
		IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
478

    
479
		configurator.setDoTaxa(getPreferenceStore().getBoolean(
480
				TAXON_SERVICE_CONFIGURATOR_TAXA));
481
		configurator.setDoSynonyms(getPreferenceStore().getBoolean(
482
				TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
483
		configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
484
				TAXON_SERVICE_CONFIGURATOR_NAMES));
485
		configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
486
				TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
487
		//configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
488

    
489
		return configurator;
490
	}
491

    
492
	/**
493
	 * create new preferences, setting all search options to true
494
	 *
495
	 * @return a
496
	 *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
497
	 *         object.
498
	 */
499
	public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
500
		IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
501

    
502
		configurator.setDoTaxa(true);
503
		configurator.setDoSynonyms(true);
504
		configurator.setDoNamesWithoutTaxa(true);
505
		configurator.setDoTaxaByCommonNames(true);
506

    
507
		configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
508
				"name", "name.$", "relationsFromThisTaxon.$"));
509

    
510
		configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
511
				"name", "name.$", "synonyms.relatedTo.*"));
512

    
513
		// DEFAULT VALUES
514
		// match mode is a simple like, actually all other match modes are kind
515
		// of bogus
516
		configurator
517
				.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
518
		// we set page number and size here as this should always be unlimited
519
		configurator.setPageNumber(0);
520
		// TODO currently limit results to 10000
521
		configurator.setPageSize(10000);
522

    
523
		return configurator;
524
	}
525

    
526
	/**
527
	 * Store search preferences
528
	 *
529
	 * @param configurator
530
	 *            a
531
	 *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
532
	 *            object.
533
	 */
534
	public static void setSearchConfigurator(
535
			IFindTaxaAndNamesConfigurator configurator) {
536
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
537
				configurator.isDoTaxa());
538
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
539
				configurator.isDoSynonyms());
540
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
541
				configurator.isDoNamesWithoutTaxa());
542
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
543
				configurator.isDoTaxaByCommonNames());
544
	}
545

    
546
	/**
547
	 * <p>
548
	 * firePreferencesChanged
549
	 * </p>
550
	 *
551
	 * @param clazz
552
	 *            a {@link java.lang.Class} object.
553
	 */
554
	public static void firePreferencesChanged(Class clazz) {
555
		getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
556
				null, clazz);
557
	}
558

    
559
	/**
560
	 * Set default values for preferences
561
	 */
562
	public static void setDefaults() {
563
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
564
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
565
				true);
566
		getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT,
567
				"http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
568
		//FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
569
		getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, false);
570
		getPreferenceStore().setDefault(OPENURL_ACCESS_POINT,
571
				"http://www.biodiversitylibrary.org/openurl");
572
		getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000");
573
		getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT, "1000");
574
		//Distribution Editor:
575
		getPreferenceStore().setDefault(DISTRIBUTION_AREA_PREFRENCES_ACTIVE, false);
576
		getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY, true);
577
		getPreferenceStore().setDefault(CHECKLIST_SYMBOL, false);
578

    
579

    
580
		//Name Details
581
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, true);
582
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE, true);
583
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, true);
584
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_HYBRID, true);
585
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_LSID, true);
586
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, true);
587
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAMECACHE, true);
588
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, true);
589
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, true);
590
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, true);
591
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, true);
592
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_RANK, true);
593
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, true);
594
		//Navigator preferences
595
		getPreferenceStore().setDefault(SORT_NODES_NATURALLY, false);
596
		getPreferenceStore().setDefault(SORT_NODES_ALPHABETICALLY, false);
597
		getPreferenceStore().setDefault(SORT_TAXA_BY_RANK_AND_NAME, true);
598
		//override db preferences
599
		getPreferenceStore().setDefault(ABCD_IMPORT_OVERRIDE, false);
600
		getPreferenceStore().setDefault(OVERRIDE_SPECIMEN_PREF, false);
601
		getPreferenceStore().setDefault(OVERRIDE_NAME_DETAILS, false);
602
		getPreferenceStore().setDefault(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE, false);
603

    
604

    
605
	}
606

    
607
	/**
608
	 * <p>
609
	 * checkNomenclaturalCode
610
	 * </p>
611
	 */
612
	public static void checkNomenclaturalCode() {
613
		// First time Editor is opened, no nomenclatural code has been set
614
		if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
615
			PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
616
		}
617

    
618

    
619

    
620
	}
621
	public static void setNomenclaturalCodePreferences(){
622
	    ICdmRepository controller;
623
        controller = CdmStore.getCurrentApplicationConfiguration();
624
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
625
        CdmPreference preference = null;
626
        if (controller == null){
627
            return ;
628
        }
629
        preference = controller.getPreferenceService().find(key);
630
        if (preference == null){
631
            return;
632
        }
633
        getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
634

    
635
        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
636
        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
637
        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
638

    
639
        getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
640
                getPreferenceKey(preferredCode));
641

    
642
	}
643

    
644
	public static void checkDefaultLanguage(){
645
	    if(PreferencesUtil.getPreferredDefaultLangugae() == null){
646
	       Shell shell = AbstractUtility.getShell();
647
	       int open = new DefaultLanguageDialog(shell).open();
648
	       if(open == Window.OK){
649
	           PlatformUI.getWorkbench().restart();
650
	       }
651
	    }else{
652
	        //TODO:In case of a reinstall, the config.ini will be overwritten
653
	        //     here you create config.ini with the stored key from preferences
654
	    }
655
	}
656

    
657
	/**
658
	 * <p>
659
	 * getMapServiceAccessPoint
660
	 * </p>
661
	 *
662
	 * @return a {@link java.lang.String} object.
663
	 */
664
	public static String getMapServiceAccessPoint() {
665
		return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT);
666
	}
667

    
668
	/**
669
	 * <p>
670
	 * shouldConnectAtStartUp
671
	 * </p>
672
	 *
673
	 * @return a boolean.
674
	 */
675
	public static boolean shouldConnectAtStartUp() {
676
		//FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
677
		//return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
678
		return false;
679
	}
680

    
681
	/**
682
	 * <p>
683
	 * getDefaultFeatureTreeForTextualDescription
684
	 * </p>
685
	 *
686
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
687
	 */
688
	public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
689
		String uuidString = getPreferenceStore().getString(
690
				FEATURE_TREE_DEFAULT_TEXT);
691
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
692
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
693
	}
694

    
695
	/**
696
	 * <p>
697
	 * getDefaultFeatureTreeForStructuredDescription
698
	 * </p>
699
	 *
700
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
701
	 */
702
	public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
703
		String uuidString = getPreferenceStore().getString(
704
				FEATURE_TREE_DEFAULT_STRUCTURE);
705
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
706
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
707
	}
708

    
709
	/**
710
	 * <p>
711
	 * setSortRanksHierarchichally
712
	 * </p>
713
	 *
714
	 * @param selection
715
	 *            a boolean.
716
	 */
717
	public static void setSortRanksHierarchichally(boolean selection) {
718
		getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY, selection);
719
	}
720

    
721
	/**
722
	 * <p>
723
	 * getSortRanksHierarchichally
724
	 * </p>
725
	 *
726
	 * @return a boolean.
727
	 */
728
	public static boolean getSortRanksHierarchichally() {
729
		return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY);
730
	}
731

    
732
	public static boolean isMultilanguageTextEditingCapability() {
733
		return getPreferenceStore().getBoolean(
734
				MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
735
	}
736

    
737
	public static Language getGlobalLanguage() {
738

    
739

    
740
		String languageUuidString = getPreferenceStore().getString(
741
				GLOBAL_LANGUAGE_UUID);
742

    
743
		if(!CdmStore.isActive()) {
744
            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
745
            return null;
746
        }
747

    
748
		if (CdmUtils.isBlank(languageUuidString)) {
749
			return Language.getDefaultLanguage();
750
		}
751

    
752
		UUID languageUuid = UUID.fromString(languageUuidString);
753
		return (Language) CdmStore.getService(ITermService.class).load(
754
				languageUuid);
755
	}
756

    
757
	public static void setGlobalLanguage(Language language) {
758
	    if(language != null) {
759
	        getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
760
	        CdmStore.setDefaultLanguage(language);
761
	    }
762

    
763
	}
764

    
765
	/**
766
	 * @return
767
	 */
768
	public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
769
		List<MarkerType> markerTypes = CdmStore.getTermManager()
770
				.getPreferredTerms(MarkerType.class);
771

    
772
		Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
773

    
774
		for (MarkerType markerType : markerTypes) {
775
			String name = getMarkerTypeEditingPreferenceKey(markerType);
776
			Boolean value = getPreferenceStore().getBoolean(name);
777

    
778
			result.put(markerType, value);
779
		}
780

    
781
		return result;
782
	}
783

    
784
	/**
785
	 * @param markerTypeEditingMap
786
	 */
787
	public static void setEditMarkerTypePreferences(
788
			Map<MarkerType, Boolean> markerTypeEditingMap) {
789
		for (MarkerType markerType : markerTypeEditingMap.keySet()) {
790
			String name = getMarkerTypeEditingPreferenceKey(markerType);
791
			getPreferenceStore().setValue(name,
792
					markerTypeEditingMap.get(markerType));
793
		}
794

    
795
	}
796

    
797
	private static String getMarkerTypeEditingPreferenceKey(
798
			MarkerType markerType) {
799
		markerType = HibernateProxyHelper.deproxy(markerType);
800
		return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
801
	}
802

    
803
	/**
804
	 * <p>
805
	 * setEditMarkerTypePreference
806
	 * </p>
807
	 *
808
	 * @param input
809
	 *            a {@link org.eclipse.ui.IEditorInput} object.
810
	 * @param markerType
811
	 *            a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
812
	 * @param edit
813
	 *            a boolean.
814
	 */
815
	public static void setEditMarkerTypePreference(MarkerType markerType,
816
			boolean edit) {
817
		getPreferenceStore().setValue(
818
				getMarkerTypeEditingPreferenceKey(markerType), edit);
819
	}
820

    
821
	/**
822
	 * @return
823
	 */
824
	public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
825
		DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
826
				.NewInstance();
827
		configurator.setMoveDerivedUnitMediaToGallery(true);
828
		configurator.setMoveFieldObjectMediaToGallery(true);
829
		return configurator;
830
	}
831

    
832
	/**
833
	 * This method will write language properties to the config.ini located in the configuration folder
834
	 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
835
	 *
836
	 * @param setLanguage 0 is for german and 1 for english.
837
	 * @throws IOException
838
	 */
839
    public void writePropertyToConfigFile(int setLanguage) throws IOException {
840
        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
841
        //give warning to user if the directory has no write access
842
        if(file == null){
843
            throw new IOException();
844
        }
845
        Properties properties = load(file.getAbsolutePath()+"/config.ini");
846
        switch(setLanguage){
847
        case 0:
848
            properties.setProperty("osgi.nl", "de");
849
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
850
            break;
851
        case 1:
852
            properties.setProperty("osgi.nl", "en");
853
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
854
            break;
855
        default:
856
            break;
857
        }
858
        save(file+"/config.ini", properties);
859
    }
860

    
861
    /**
862
     * This method loads a property from a given file and returns it.
863
     *
864
     * @param filename
865
     * @return
866
     * @throws IOException
867
     */
868
    private Properties load(String filename) throws IOException {
869
        FileInputStream in = new FileInputStream(filename);
870
        Properties prop = new Properties();
871
        prop.load(in);
872
        in.close();
873
        return prop;
874
    }
875

    
876
    /**
877
     * This method saves a property to the specified file.
878
     *
879
     * @param filename
880
     * @param properties
881
     * @throws IOException
882
     */
883
    private void save(String filename, Properties properties) throws IOException{
884
        FileOutputStream fos =  new FileOutputStream(filename);
885
        properties.store(fos, "");
886
        fos.close();
887
    }
888

    
889
    /**
890
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
891
     *
892
     * @param p2Repos
893
     */
894
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
895
        StringBuilder sb = new StringBuilder();
896
        for(MetadataRepositoryElement p2Repo : p2Repos) {
897
            sb.append(P2_REPOSITORIES_DELIM);
898
            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
899
                sb.append("-");
900
            } else {
901
                sb.append(p2Repo.getName());
902
            }
903
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
904
            sb.append(p2Repo.getLocation().toString());
905
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
906
            sb.append(String.valueOf(p2Repo.isEnabled()));
907
        }
908
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
909
    }
910

    
911

    
912
    /**
913
     * Retrieves a list of previously saved P2 repositories
914
     *
915
     * @return
916
     */
917
    public static List<MetadataRepositoryElement> getP2Repositories() {
918
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
919
        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
920
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
921
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
922

    
923
            while(p2ReposPrefST.hasMoreTokens()) {
924
                String p2RepoStr = p2ReposPrefST.nextToken();
925
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
926
                if(p2ReposStrST.countTokens()==3) {
927
                    String nickname = p2ReposStrST.nextToken();
928
                    URI uri = null;
929
                    try {
930
                        uri = new URI(p2ReposStrST.nextToken());
931
                    } catch (URISyntaxException e) {
932
                        continue;
933
                    }
934
                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
935
                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
936
                    mre.setNickname(nickname);
937
                    mre.setEnabled(enabled);
938
                    p2Repos.add(mre);
939
                }
940
            }
941
        }
942

    
943
        return p2Repos;
944
    }
945

    
946
    /**
947
     * enables/disables nested composite. <br>
948
     *
949
     * @param ctrl - Composite to be en-/disabeld
950
     * @param enabled - boolean
951
     */
952
    public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
953
        if (ctrl instanceof Composite) {
954
            Composite comp = (Composite) ctrl;
955
            for (Control c : comp.getChildren()) {
956
                recursiveSetEnabled(c, enabled);
957
            }
958
        } else {
959
            ctrl.setEnabled(enabled);
960
        }
961
    }
962

    
963
    /**
964
	 * <p>
965
	 * getSortRanksNaturally
966
	 * </p>
967
    	 *
968
    	 * @return a boolean.
969
	 */
970
	public static boolean getSortNodesNaturally() {
971
		return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY);
972
	}
973

    
974
	/**
975
	 * <p>
976
	 * setSortRanksNaturally
977
	 * </p>
978
	 *
979
	 * @param selection
980
	 *            a boolean.
981
	 */
982
	public static void setSortNodesNaturally(boolean selection) {
983
		getPreferenceStore().setValue(SORT_NODES_NATURALLY, selection);
984
	}
985

    
986

    
987
	/**
988
	 * <p>
989
	 * getSortRanksNaturally
990
	 * </p>
991
	 *
992
	 * @return a boolean.
993
	 */
994
	public static boolean getSortNodesStrictlyAlphabetically() {
995
		return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY);
996
	}
997

    
998
	/**
999
	 * <p>
1000
	 * setSortRanksNaturally
1001
	 * </p>
1002
	 *
1003
	 * @param selection
1004
	 *            a boolean.
1005
	 */
1006
	public static void setSortNodesStrictlyAlphabetically(boolean selection) {
1007
		getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY, selection);
1008
	}
1009

    
1010
	/**
1011
	 * <p>
1012
	 * setStoreNavigatorState
1013
	 * </p>
1014
	 *
1015
	 * @param selection
1016
	 *            a boolean.
1017
	 */
1018
	public static boolean isStoreNavigatorState() {
1019
		return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE);
1020

    
1021
	}
1022

    
1023
	/**
1024
	 * <p>
1025
	 * setStoreNavigatorState
1026
	 * </p>
1027
	 *
1028
	 * @param selection
1029
	 *            a boolean.
1030
	 */
1031
	public static void setStoreNavigatorState(boolean selection) {
1032
		getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE, selection);
1033

    
1034
	}
1035

    
1036
    /**
1037
     * @return
1038
     */
1039
    public static boolean isShowUpWidgetIsDisposedMessages() {
1040
       return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1041
    }
1042
    public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1043
        getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1044
    }
1045

    
1046
    /**
1047
     * @return
1048
     */
1049
    public static boolean isShowIdInVocabularyInChecklistEditor() {
1050
       return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY);
1051
    }
1052
    public static void setShowIdInVocabularyInChecklistEditor(boolean selection) {
1053
        getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY, selection);
1054
    }
1055

    
1056
    /**
1057
     * @return
1058
     */
1059
    public static boolean isShowSymbolInChecklistEditor() {
1060
       return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SYMBOL);
1061
    }
1062
    public static void setShowSymbolInChecklistEditor(boolean selection) {
1063
        getPreferenceStore().setValue(CHECKLIST_SYMBOL, selection);
1064
    }
1065

    
1066
    /**
1067
     * @return
1068
     */
1069
    public static boolean isShowRankInChecklistEditor() {
1070
        return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SHOW_RANK);
1071
    }
1072
    public static void setShowRankInChecklistEditor(boolean selection) {
1073
        getPreferenceStore().setValue(CHECKLIST_SHOW_RANK, selection);
1074
    }
1075

    
1076
    /**
1077
     * @param object
1078
     * @param b
1079
     * @return
1080
     */
1081
    public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1082
        NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1083

    
1084
        CdmPreference preference = null;
1085

    
1086
        if (!local) {
1087
            preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
1088
            if (preference == null){
1089
                return null;
1090
            }
1091

    
1092
            getPreferenceStore().setValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1093

    
1094
            //the preference value is build like this:
1095
            //<section1>:true;<section2>:false....
1096

    
1097
            String value = preference.getValue();
1098
            String [] sections = value.split(";");
1099
            Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1100
            String[] sectionValues;
1101
            for (String sectionValue: sections){
1102
                sectionValues = sectionValue.split(":");
1103
                sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1104
            }
1105
            config.setAllowOverride(preference.isAllowOverride());
1106
            config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1107

    
1108
    //        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
1109
    //                (getValue(sectionMap, "taxon")));
1110
            config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1111

    
1112
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
1113
    //                (getValue(sectionMap, "lsid")));
1114
            config.setLSIDActivated(getValue(sectionMap, "lsid"));
1115

    
1116
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1117
    //                (getValue(sectionMap, "nc")));
1118
            config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1119

    
1120
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1121
    //                (getValue(sectionMap, "ap")));
1122
            config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1123

    
1124
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
1125
    //                (getValue(sectionMap, "rank")));
1126
            config.setRankActivated(getValue(sectionMap, "rank"));
1127

    
1128

    
1129
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1130
    //                (getValue(sectionMap, "atomisedEpithets")));
1131
            config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1132

    
1133
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1134
    //                (getValue(sectionMap,"author")));
1135
            config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1136

    
1137
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1138
    //                (getValue(sectionMap, "nomRef")));
1139
            config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1140

    
1141
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1142
    //                (getValue(sectionMap, "nomStat")));
1143
            config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1144

    
1145

    
1146
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1147
    //                (getValue(sectionMap,"protologue")));
1148
            config.setProtologueActivated(getValue(sectionMap,"protologue"));
1149

    
1150
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1151
    //                (getValue(sectionMap,"typeDes")));
1152
            config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1153

    
1154
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1155
    //                (getValue(sectionMap,"nameRelation")));
1156
            config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1157

    
1158
    //        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
1159
    //                (getValue(sectionMap, "hybrid")));
1160
            config.setHybridActivated(getValue(sectionMap,"hybrid"));
1161
        }else{
1162
            config.setSimpleDetailsViewActivated(getPreferenceStore().getBoolean(SHOW_SIMPLE_NAME_DETAILS_SECTION));
1163
            config.setTaxonSectionActivated(getPreferenceStore().getBoolean(SHOW_SIMPLE_NAME_DETAILS_TAXON));
1164
            config.setLSIDActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_LSID));
1165
            config.setNomenclaturalCodeActived(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1166
            config.setAppendedPhraseActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1167
            config.setRankActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_RANK));
1168
            config.setAtomisedEpithetsActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1169
            config.setAuthorshipSectionActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1170
            config.setNomenclaturalReferenceSectionActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1171
            config.setNomenclaturalStatusSectionActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1172
            config.setProtologueActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1173
            config.setTypeDesignationSectionActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1174
            config.setNameRelationsSectionActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1175
            config.setHybridActivated(getPreferenceStore().getBoolean(SHOW_NAME_DETAILS_SECTION_HYBRID));
1176
        }
1177
        return config;
1178
    }
1179

    
1180
    /**
1181
     * @param object
1182
     * @param b
1183
     * @return
1184
     */
1185
    public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1186
        CdmPreference preference = null;
1187

    
1188
        if (!local) {
1189
            preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NameDetailsView, config.toString());
1190

    
1191
            setPreferenceToDB(preference);
1192
        }
1193
        //also add to local preferences
1194
        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_SECTION, config.isSimpleDetailsViewActivated());
1195
        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1196
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1197
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, config.isNomenclaturalCodeActived());
1198
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, config.isAppendedPhraseActivated());
1199
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1200
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, config.isAtomisedEpithetsActivated());
1201
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, config.isAuthorshipSectionActivated());
1202
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, config.isNomenclaturalReferenceSectionActivated());
1203
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, config.isNomenclaturalStatusSectionActivated());
1204
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, config.isProtologueActivated());
1205
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, config.isTypeDesignationSectionActivated());
1206
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, config.isNameRelationsSectionActivated());
1207
        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID, config.isHybridActivated());
1208

    
1209
    }
1210

    
1211
    private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1212
		if (sectionMap.containsKey(string)){
1213
			return sectionMap.get(string);
1214
		}else{
1215
			return true;
1216
		}
1217

    
1218
	}
1219

    
1220

    
1221

    
1222
    /**
1223
     * <p>
1224
     * setAbcdConfigurator
1225
     * </p>
1226
     *
1227
     * @param preferredConfiguration
1228
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1229
     *            object.
1230
     */
1231
    public static Abcd206ImportConfigurator getAbcdImportConfigurationPreference() {
1232

    
1233
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1234
        ICdmRepository controller;
1235
        controller = CdmStore.getCurrentApplicationConfiguration();
1236
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
1237
        CdmPreference preference = null;
1238
        if (controller == null){
1239
            return null;
1240
        }
1241
        preference = controller.getPreferenceService().find(key);
1242
        boolean allowOverride = true;
1243
        if (preference != null && !preference.isAllowOverride()){
1244
            allowOverride = false;
1245
        }
1246
        if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_OVERRIDE) && allowOverride){
1247

    
1248
            config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1249

    
1250
            config.setAddMediaAsMediaSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1251

    
1252
            config.setAllowReuseOtherClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1253
            config.setDeduplicateClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1254
            config.setDeduplicateReferences(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1255

    
1256
            config.setGetSiblings(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1257
            config.setIgnoreAuthorship(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1258
            config.setIgnoreImportOfExistingSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1259
            config.setMapUnitIdToAccessionNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1260
            config.setMapUnitIdToBarcode(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1261
            config.setMapUnitIdToCatalogNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1262
            config.setMoveNewTaxaToDefaultClassification(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1263
            config.setOverwriteExistingSpecimens(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1264
            config.setReuseExistingDescriptiveGroups(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1265
            config.setReuseExistingMetaData(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1266
            config.setReuseExistingTaxaWhenPossible(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1267
            config.setNomenclaturalCode(NomenclaturalCode.getByKey(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1268
            return config;
1269

    
1270
        }
1271

    
1272
            if (preference == null){
1273
                return config;
1274
             } else{
1275
             String configString = preference.getValue();
1276
             String[] configArray = configString.split(";");
1277

    
1278
             for (String configItem: configArray){
1279
                 String[] keyValue = configItem.split(":");
1280
                 String keyString = keyValue[0];
1281
                 String valueString = keyValue[1];
1282
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1283
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1284
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1285
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1286
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1287
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1288
                 }else if (keyString.equals("ignoreAuthorship")){
1289
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1290
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1291
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1292
                 }else if (keyString.equals("reuseExistingMetaData")){
1293
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1294
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1295
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1296
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1297
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1298
                 }else if (keyString.equals("deduplicateReferences")){
1299
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1300
                 }else if (keyString.equals("deduplicateClassifications")){
1301
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1302
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1303
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1304
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1305
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1306
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1307
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1308
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1309
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1310
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1311
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1312
                 }else if (keyString.equals("nomenclaturalCode")){
1313
                         config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1314
                 }else{
1315
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1316
                 }
1317

    
1318
            }
1319
        }
1320
        return config;
1321
    }
1322

    
1323

    
1324
    public static void updateAbcdImportConfigurationPreference() {
1325

    
1326
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1327
        ICdmRepository controller;
1328
        controller = CdmStore.getCurrentApplicationConfiguration();
1329
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
1330
        CdmPreference preference = null;
1331
        if (controller == null){
1332
            return ;
1333
        }
1334
        preference = controller.getPreferenceService().find(key);
1335
        boolean allowOverride = true;
1336
        if (preference != null && !preference.isAllowOverride()){
1337
            allowOverride = false;
1338
        }
1339
        if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_OVERRIDE) || !allowOverride){
1340

    
1341
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1342
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1343

    
1344
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1345
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1346
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1347

    
1348
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1349
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1350
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1351
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1352
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1353
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1354
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1355
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1356
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1357
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1358
            getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1359
            if (config.getNomenclaturalCode() != null){
1360
                getPreferenceStore().setValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1361
            }
1362

    
1363

    
1364
        }
1365
    }
1366

    
1367

    
1368
    /**
1369
    *
1370
    */
1371
   public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
1372
       NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1373
       if (local){
1374
          config.setSimpleDetailsViewActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
1375
          config.setAppendedPhraseActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1376
          config.setAtomisedEpithetsActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1377
          config.setAuthorshipSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1378
          config.setLSIDActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
1379
          config.setNameApprobiationActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
1380
          config.setNameCacheActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
1381
          config.setNameRelationsSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1382
          config.setNomenclaturalCodeActived(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1383
          config.setNomenclaturalStatusSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1384
          config.setNomenclaturalReferenceSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1385
          config.setProtologueActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1386
          config.setRankActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
1387
          config.setTaxonSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
1388
          config.setTypeDesignationSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1389
          config.setHybridActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
1390
       }else{
1391

    
1392
       }
1393

    
1394
      return config;
1395
   }
1396

    
1397

    
1398
   public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
1399
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
1400
               config.isSimpleDetailsViewActivated());
1401
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1402
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1403
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1404
               config.isNomenclaturalCodeActived());
1405
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
1406
               config.isNameCacheActivated());
1407
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1408
               config.isAppendedPhraseActivated());
1409
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1410
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1411
               config.isAtomisedEpithetsActivated());
1412
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
1413
               config.isAuthorCacheActivated());
1414
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1415
               config.isAuthorshipSectionActivated());
1416
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1417
               config.isNomenclaturalReferenceSectionActivated());
1418
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1419
               config.isNomenclaturalStatusSectionActivated());
1420
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1421
               config.isProtologueActivated());
1422
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1423
               config.isTypeDesignationSectionActivated());
1424
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1425
               config.isNameRelationsSectionActivated());
1426
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
1427
               config.isHybridActivated());
1428

    
1429
   }
1430

    
1431
/**
1432
 * @return
1433
 */
1434
public static boolean isSortTaxaByRankAndName() {
1435

    
1436
    return getPreferenceStore().getBoolean(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1437
}
1438

    
1439
/**
1440
 * @return
1441
 */
1442
public static boolean isSortNamedAreaByOrderInVocabulary() {
1443

    
1444
    return getPreferenceStore().getBoolean(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER);
1445
}
1446

    
1447
public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
1448
    getPreferenceStore().setValue(IPreferenceKeys.SORT_NAMED_AREA_BY_VOCABULARY_ORDER, isSortByVocabularyOrder);
1449

    
1450
}
1451

    
1452
/**
1453
 * <p>
1454
 * setPreferredNamedAreasForDistributionEditor
1455
 * </p>
1456
 *
1457
 * @param saveCheckedElements
1458
 * @param saveGrayedElements
1459
 */
1460
public static void setLastSelectedReference(
1461
        List<String> lastSelectedReferences) {
1462

    
1463
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1464
        preferenceStore.setValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1465
    }
1466

    
1467
/**
1468
 * <p>
1469
 * setPreferredNamedAreasForDistributionEditor
1470
 * </p>
1471
 *
1472
 * @param saveCheckedElements
1473
 * @param saveGrayedElements
1474
 */
1475
public static List<String> getLastSelectedReferences() {
1476

    
1477
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1478
        String lastSelected = preferenceStore.getString(PreferencesUtil.LAST_SELECTED_REFERENCES);
1479
        List<String> result = new ArrayList<>();
1480
        if (!StringUtils.isBlank(lastSelected)){
1481
            Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1482
        }
1483
        return result;
1484
    }
1485

    
1486

    
1487
/**
1488
 * <p>
1489
 * setPreferredNamedAreasForDistributionEditor
1490
 * </p>
1491
 *
1492
 * @param saveCheckedElements
1493
 * @param saveGrayedElements
1494
 */
1495
public static void setPreferredNamedAreasForDistributionEditor(
1496
        String saveCheckedElements, String saveGrayedElements, boolean local) {
1497
    if (local){
1498
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1499
        preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
1500
        preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
1501

    
1502
    }
1503
    else{
1504
//        ICdmRepository controller;
1505

    
1506
//        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaTerms);
1507
        CdmPreference preference = null;
1508

    
1509
        if (saveCheckedElements == null){
1510
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1511

    
1512
            if (preference == null){
1513
                return ;
1514
            } else{
1515
                getPreferenceStore().setValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1516
                        saveCheckedElements);
1517
                preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1518
                setPreferenceToDB(preference);
1519

    
1520
            }
1521
        } else{
1522
           preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1523
           setPreferenceToDB(preference);
1524
           getPreferenceStore().setValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1525
                    saveCheckedElements);
1526

    
1527
        }
1528
    }
1529

    
1530
}
1531

    
1532
/**
1533
 * @param saveCheckedElements
1534
 * @param saveCheckedElements2
1535
 * @param b
1536
 */
1537
public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1538
        boolean local) {
1539
    if (local){
1540
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1541
        preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES, saveCheckedElements);
1542

    
1543

    
1544
    }
1545
    else{
1546
        ICdmRepository controller;
1547
        CdmPreference preference = null;
1548

    
1549
        if (saveCheckedElements == null){
1550
            preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1551

    
1552
            if (preference == null){
1553
                return ;
1554
            } else{
1555
                getPreferenceStore().setValue(DISTRIBUTION_VOCABULARIES,
1556
                        saveCheckedElements);
1557
                preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1558
                setPreferenceToDB(preference);
1559

    
1560

    
1561
            }
1562
        } else{
1563
            preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1564
            setPreferenceToDB(preference);
1565
            getPreferenceStore().setValue(DISTRIBUTION_AREA_OCCURENCE_STATUS,
1566
                    saveCheckedElements);
1567

    
1568
        }
1569
    }
1570

    
1571

    
1572

    
1573
}
1574

    
1575
/**
1576
 * @param saveCheckedElements
1577
 * @param saveCheckedElements2
1578
 * @param b
1579
 */
1580
public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1581
    if (local){
1582
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1583
        String pref = preferenceStore.getString(DISTRIBUTION_VOCABULARIES);
1584
        return pref;
1585

    
1586
    }
1587
    else{
1588

    
1589
        CdmPreference preference = null;
1590

    
1591
        preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1592

    
1593
            if (preference == null){
1594
                return null;
1595
            } else{
1596
                return preference.getValue();
1597
            }
1598

    
1599
    }
1600

    
1601

    
1602

    
1603
}
1604

    
1605
/**
1606
 *
1607
 */
1608
public static void updateDBPreferences() {
1609
    CdmPreference preference = null;
1610
    IPreferenceStore prefStore = getPreferenceStore();
1611

    
1612
    //ABCD Configurator
1613

    
1614
    updateAbcdImportConfigurationPreference();
1615

    
1616
    //Specimen Details
1617
    preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
1618
    if (preference != null){
1619
        if(!prefStore.getBoolean(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) ||  !preference.isAllowOverride()){
1620
            prefStore.setValue(SHOW_TAXON_ASSOCIATIONS, preference.getValue());
1621
        }
1622
    }
1623
    preference = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
1624
    if (preference != null){
1625
        if(!prefStore.getBoolean(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) ||  !preference.isAllowOverride()){
1626
            prefStore.setValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, preference.getValue());
1627
        }
1628
    }
1629
    preference = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
1630
    if (preference != null){
1631
        if(!prefStore.getBoolean(SHOW_LIFE_FORM_OVERRIDE) ||  !preference.isAllowOverride()){
1632
            prefStore.setValue(SHOW_LIFE_FORM, preference.getValue());
1633
        }
1634
    }
1635
    preference = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
1636
    if (preference != null){
1637
        if(!prefStore.getBoolean(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) ||  !preference.isAllowOverride()){
1638
            prefStore.setValue(DETERMINATION_ONLY_FOR_FIELD_UNITS, preference.getValue());
1639
        }
1640
    }
1641

    
1642

    
1643
    //Name Details
1644
    NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1645
    if (config != null ){
1646
        if (!prefStore.getBoolean(OVERRIDE_NAME_DETAILS) ||  !prefStore.getBoolean(ALLOW_OVERRIDE_NAME_DETAILS)){
1647
            setPreferredNameDetailsConfiguration(config, false);
1648
        }
1649
    }
1650

    
1651
    //Distribution Editor
1652
    preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1653
    if (preference != null){
1654
        if (!prefStore.getBoolean(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) ||  !preference.isAllowOverride()){
1655
            prefStore.setValue(DISTRIBUTION_VOCABULARIES, preference.getValue());
1656
        }
1657
    }
1658

    
1659
    preference = getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
1660
    if (preference != null){
1661
        if (!prefStore.getBoolean(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) || !preference.isAllowOverride()){
1662
            prefStore.setValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE, preference.getValue());
1663
        }
1664
    }
1665

    
1666
}
1667

    
1668

    
1669

    
1670

    
1671

    
1672

    
1673

    
1674
}
(19-19/24)