Project

General

Profile

Download (50.4 KB) Statistics
| Branch: | Tag: | Revision:
1 3be6ef3e n.hoffmann
/**
2 eed65ec6 n.hoffmann
 * Copyright (C) 2007 EDIT
3 fa69e58f Patric Plitzner
 * European Distributed Institute of Taxonomy
4 eed65ec6 n.hoffmann
 * http://www.e-taxonomy.eu
5 fa69e58f Patric Plitzner
 *
6 eed65ec6 n.hoffmann
 * 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 3be6ef3e n.hoffmann
10
package eu.etaxonomy.taxeditor.preference;
11
12 86cc5c9a Alexander Oppermann
import java.io.File;
13
import java.io.FileInputStream;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16 aa997cff Cherian Mathew
import java.net.URI;
17
import java.net.URISyntaxException;
18
import java.util.ArrayList;
19 3be6ef3e n.hoffmann
import java.util.Arrays;
20 db5e366d n.hoffmann
import java.util.HashMap;
21
import java.util.List;
22
import java.util.Map;
23 86cc5c9a Alexander Oppermann
import java.util.Properties;
24 3be6ef3e n.hoffmann
import java.util.Set;
25 aa997cff Cherian Mathew
import java.util.StringTokenizer;
26 3be6ef3e n.hoffmann
import java.util.UUID;
27
28 4afd9d97 Alexander Oppermann
import org.apache.commons.lang.StringUtils;
29 da948591 Katja Luther
import org.apache.log4j.Logger;
30 aa997cff Cherian Mathew
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
31 3be6ef3e n.hoffmann
import org.eclipse.jface.preference.IPreferenceStore;
32 a31abd30 Patric Plitzner
import org.eclipse.jface.window.Window;
33 b4e62664 Alexander Oppermann
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Control;
35 3be6ef3e n.hoffmann
import org.eclipse.swt.widgets.Shell;
36 4afd9d97 Alexander Oppermann
import org.eclipse.ui.PlatformUI;
37 3be6ef3e n.hoffmann
38 2da9ade2 Andreas Kohlbecker
import eu.etaxonomy.cdm.api.application.ICdmRepository;
39 42982abe n.hoffmann
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
40 db5e366d n.hoffmann
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
41
import eu.etaxonomy.cdm.api.service.ITermService;
42 d70f4b3c Andreas Kohlbecker
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
43
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
44 3be6ef3e n.hoffmann
import eu.etaxonomy.cdm.common.CdmUtils;
45
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46 da948591 Katja Luther
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
47 3be6ef3e n.hoffmann
import eu.etaxonomy.cdm.model.common.ICdmBase;
48
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
49 1c4f6bb6 Cherian Mathew
import eu.etaxonomy.cdm.model.common.ISimpleTerm;
50 3be6ef3e n.hoffmann
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 b9801dc0 Katja Luther
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
55
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
56
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
57
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
58 3be6ef3e n.hoffmann
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
59
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
60
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
61
import eu.etaxonomy.cdm.strategy.match.MatchException;
62
import eu.etaxonomy.cdm.strategy.match.MatchMode;
63 d969af0f Patric Plitzner
import eu.etaxonomy.taxeditor.model.AbstractUtility;
64 41e2f693 Cherian Mathew
import eu.etaxonomy.taxeditor.model.MessagingUtils;
65 3be6ef3e n.hoffmann
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
66
import eu.etaxonomy.taxeditor.store.CdmStore;
67
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
68 4afd9d97 Alexander Oppermann
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
69 3be6ef3e n.hoffmann
70
/**
71 eed65ec6 n.hoffmann
 * <p>
72
 * PreferencesUtil class.
73
 * </p>
74 fa69e58f Patric Plitzner
 *
75 3be6ef3e n.hoffmann
 * @author p.ciardelli
76
 * @author n.hoffmann
77
 * @created 05.12.2008
78
 * @version 1.0
79
 */
80 eed65ec6 n.hoffmann
public class PreferencesUtil implements IPreferenceKeys {
81 3be6ef3e n.hoffmann
82
	/**
83 fa69e58f Patric Plitzner
	 *
84 3be6ef3e n.hoffmann
	 */
85
	public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
86
87 aa997cff Cherian Mathew
	public static final String P2_REPOSITORIES_DELIM = ",";
88
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
89
90 da948591 Katja Luther
	private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
91 e598b1c7 Katja Luther
92 3be6ef3e n.hoffmann
	/**
93 eed65ec6 n.hoffmann
	 * <p>
94
	 * getPreferenceStore
95
	 * </p>
96 fa69e58f Patric Plitzner
	 *
97 3be6ef3e n.hoffmann
	 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
98
	 */
99
	public static IPreferenceStore getPreferenceStore() {
100
		return TaxeditorStorePlugin.getDefault().getPreferenceStore();
101
	}
102 eed65ec6 n.hoffmann
103 3be6ef3e n.hoffmann
	/**
104 eed65ec6 n.hoffmann
	 * <p>
105
	 * setPreferredNomenclaturalCode
106
	 * </p>
107 fa69e58f Patric Plitzner
	 *
108 eed65ec6 n.hoffmann
	 * @param preferredCode
109
	 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
110
	 *            object.
111 3be6ef3e n.hoffmann
	 */
112 e9773ade Katja Luther
	public static CdmPreference setPreferredNomenclaturalCode(
113 be140ab3 Katja Luther
			NomenclaturalCode preferredCode, boolean local) {
114
	    if (local){
115
	        getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
116
                    getPreferenceKey(preferredCode));
117
	    }
118
	    else{
119 2da9ade2 Andreas Kohlbecker
    		ICdmRepository controller;
120 be140ab3 Katja Luther
    		controller = CdmStore.getCurrentApplicationConfiguration();
121
    		PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
122
    		CdmPreference preference = null;
123
    		if (controller == null){
124
    			return null;
125
    		}
126
    		if (preferredCode == null){
127
    			preference = controller.getPreferenceService().find(key);
128
    			if (preference == null){
129
    				return null;
130
    			} else{
131
    				int index = StringUtils.lastIndexOf(preference.getValue(), ".");
132
    				UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
133
    				preferredCode = NomenclaturalCode.getByUuid(uuid);
134 e9773ade Katja Luther
135
    				getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
136
    	                    getPreferenceKey(preferredCode));
137
    				getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
138
    				return preference;
139 be140ab3 Katja Luther
    			}
140
    		} else{
141
    			preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
142
    			controller.getPreferenceService().set(preference);
143
144
    		}
145
	    }
146 e9773ade Katja Luther
        return null;
147 be140ab3 Katja Luther
148
149
150 3be6ef3e n.hoffmann
	}
151 eed65ec6 n.hoffmann
152 b9801dc0 Katja Luther
	public static NomenclaturalCode getPreferredNomenclaturalCode(){
153 be140ab3 Katja Luther
	    if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
154
            return getPreferredNomenclaturalCode(true);
155
        } else{
156
            return getPreferredNomenclaturalCode(false);
157
        }
158 b9801dc0 Katja Luther
	}
159 be140ab3 Katja Luther
160 3be6ef3e n.hoffmann
	/**
161 eed65ec6 n.hoffmann
	 * <p>
162
	 * getPreferredNomenclaturalCode
163
	 * </p>
164 fa69e58f Patric Plitzner
	 *
165 3be6ef3e n.hoffmann
	 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
166
	 */
167 be140ab3 Katja Luther
	public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
168 994548e2 Katja Luther
169 b9801dc0 Katja Luther
		CdmPreference pref = null;
170 be140ab3 Katja Luther
		if (!useLocal){
171 994548e2 Katja Luther
		    pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
172 b9801dc0 Katja Luther
		}
173 be140ab3 Katja Luther
174 b9801dc0 Katja Luther
	    String preferredCode;
175
	    if(pref == null){
176
	    	preferredCode = getPreferenceStore().getString(
177 eed65ec6 n.hoffmann
					PREFERRED_NOMENCLATURAL_CODE_KEY);
178 b7bfcde7 Katja Luther
179 b9801dc0 Katja Luther
	    }else{
180
	    	preferredCode = pref.getValue();
181
	    }
182 be140ab3 Katja Luther
183 b9801dc0 Katja Luther
		for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
184 3be6ef3e n.hoffmann
			if (getPreferenceKey(code).equals(preferredCode)) {
185
				return code;
186
			}
187
		}
188
		return null;
189
	}
190 eed65ec6 n.hoffmann
191 256fbc69 Katja Luther
	public static boolean isShowTaxonAssociations(){
192
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
193
            return getPreferenceStore().getBoolean(SHOW_TAXON_ASSOCIATIONS);
194
        } else{
195
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
196
197 16a96c7c Patrick Plitzner
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
198 256fbc69 Katja Luther
        }
199
    }
200
201
	public static boolean isShowLifeForm(){
202
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
203
            return getPreferenceStore().getBoolean(SHOW_LIFE_FORM);
204
        } else{
205
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
206
207 d018d823 Patrick Plitzner
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
208 256fbc69 Katja Luther
        }
209
    }
210
211
	public static boolean isDeterminationOnlyForFieldUnits(){
212
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
213
            return getPreferenceStore().getBoolean(DETERMINATION_ONLY_FOR_FIELD_UNITS);
214
        } else{
215
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
216
217 d018d823 Patrick Plitzner
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
218 256fbc69 Katja Luther
        }
219
    }
220
221
	public static boolean isCollectingAreaInGeneralSection(){
222
        if (getPreferenceStore().getBoolean(OVERRIDE_SPECIMEN_PREF) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_SPECIMEN_PREF)) {
223
            return getPreferenceStore().getBoolean(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
224
        } else{
225
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
226
227 16a96c7c Patrick Plitzner
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
228 256fbc69 Katja Luther
        }
229
    }
230
231 e5f892b4 Katja Luther
	public static boolean isShowSimpleDetailsView(){
232
        if (getPreferenceStore().getBoolean(OVERRIDE_NAME_DETAILS) && getPreferenceStore().getBoolean(ALLOW_OVERRIDE_NAME_DETAILS)) {
233
            return getPreferenceStore().getBoolean(SHOW_SIMPLE_NAME_DETAILS_SECTION);
234
        } else{
235
            CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
236
237 16a96c7c Patrick Plitzner
            return pref!=null?Boolean.valueOf(pref.getValue()):false;
238 e5f892b4 Katja Luther
        }
239
    }
240
241 994548e2 Katja Luther
242 256fbc69 Katja Luther
243
    public static CdmPreference getPreferenceFromDB(PreferencePredicate predicate){
244 994548e2 Katja Luther
        ICdmRepository controller;
245
        CdmPreference pref = null;
246
247
        try{
248 0fa0610e Patrick Plitzner
            if(CdmStore.isActive()){
249
                controller = CdmStore.getCurrentApplicationConfiguration();
250
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), predicate);
251
                pref = controller.getPreferenceService().find(key);
252
            }
253 994548e2 Katja Luther
        }catch(Exception e){
254
            e.printStackTrace();
255
        }
256
257
        return pref;
258
259
    }
260
261
262 4afd9d97 Alexander Oppermann
	public static String getPreferredDefaultLangugae(){
263
	    String preferredLanguage = getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR);
264
	    if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
265
	        return preferredLanguage;
266
	    }
267
	    return null;
268
	}
269
270 a904e4d0 Katja Luther
	public static boolean isShowMediaPreview(){
271
        boolean isShowMediaPreview = getPreferenceStore().getBoolean(SHOW_MEDIA_PREVIEW);
272
        return isShowMediaPreview;
273
    }
274
275 3be6ef3e n.hoffmann
	/**
276
	 * Get the match strategy for the given class that was stored in preferences
277
	 * or the default strategy if it was not stored in preferences
278 fa69e58f Patric Plitzner
	 *
279 eed65ec6 n.hoffmann
	 * @param clazz
280
	 *            a {@link java.lang.Class} object.
281 3be6ef3e n.hoffmann
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
282
	 */
283 eed65ec6 n.hoffmann
	public static IMatchStrategy getMatchStrategy(Class clazz) {
284 3be6ef3e n.hoffmann
		String className = clazz.getName();
285 eed65ec6 n.hoffmann
		if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)) {
286 3be6ef3e n.hoffmann
			IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
287 eed65ec6 n.hoffmann
288
			for (String fieldName : matchStrategy.getMatchFieldPropertyNames()) {
289
				String matchModeName = getPreferenceStore().getString(
290
						getMatchStrategyFieldName(className, fieldName));
291 3be6ef3e n.hoffmann
				MatchMode matchMode = MatchMode.valueOf(matchModeName);
292
				try {
293
					matchStrategy.setMatchMode(fieldName, matchMode);
294
				} catch (MatchException e) {
295 41e2f693 Cherian Mathew
					MessagingUtils.error(PreferencesUtil.class, e);
296 3be6ef3e n.hoffmann
					throw new RuntimeException(e);
297
				}
298
			}
299 eed65ec6 n.hoffmann
300 3be6ef3e n.hoffmann
			return matchStrategy;
301
		}
302
		return getDefaultMatchStrategy(clazz);
303
	}
304 eed65ec6 n.hoffmann
305 3be6ef3e n.hoffmann
	/**
306
	 * Stores a matchStrategy into the preference store.
307 fa69e58f Patric Plitzner
	 *
308 eed65ec6 n.hoffmann
	 * @param matchStrategy
309
	 *            a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
310
	 *            object.
311 3be6ef3e n.hoffmann
	 */
312 eed65ec6 n.hoffmann
	public static void setMatchStrategy(IMatchStrategy matchStrategy) {
313 3be6ef3e n.hoffmann
		String className = matchStrategy.getMatchClass().getName();
314
		getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true);
315 eed65ec6 n.hoffmann
316 3be6ef3e n.hoffmann
		Set<String> matchFields = matchStrategy.getMatchFieldPropertyNames();
317 eed65ec6 n.hoffmann
318
		for (String fieldName : matchFields) {
319
			getPreferenceStore().setValue(
320
					getMatchStrategyFieldName(className, fieldName),
321 3be6ef3e n.hoffmann
					matchStrategy.getMatchMode(fieldName).name());
322
		}
323
	}
324 eed65ec6 n.hoffmann
325 3be6ef3e n.hoffmann
	/**
326
	 * Helper method to create the preference property for a match field.
327 fa69e58f Patric Plitzner
	 *
328 3be6ef3e n.hoffmann
	 * @param className
329
	 * @param fieldName
330
	 * @return
331
	 */
332 eed65ec6 n.hoffmann
	private static String getMatchStrategyFieldName(String className,
333
			String fieldName) {
334
		return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
335 3be6ef3e n.hoffmann
	}
336 eed65ec6 n.hoffmann
337 3be6ef3e n.hoffmann
	/**
338
	 * Returns the default match strategy for a given class.
339 fa69e58f Patric Plitzner
	 *
340 eed65ec6 n.hoffmann
	 * @param clazz
341
	 *            a {@link java.lang.Class} object.
342 3be6ef3e n.hoffmann
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
343
	 */
344 eed65ec6 n.hoffmann
	public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
345 3be6ef3e n.hoffmann
		return DefaultMatchStrategy.NewInstance(clazz);
346
	}
347 eed65ec6 n.hoffmann
348 3be6ef3e n.hoffmann
	/**
349 eed65ec6 n.hoffmann
	 * <p>
350
	 * getDateFormatPattern
351
	 * </p>
352 fa69e58f Patric Plitzner
	 *
353 3be6ef3e n.hoffmann
	 * @return a {@link java.lang.String} object.
354
	 */
355 eed65ec6 n.hoffmann
	public static String getDateFormatPattern() {
356 3be6ef3e n.hoffmann
		// TODO make this configurable in properties
357
		String pattern = "Y-M-d H:m";
358
		return pattern;
359
	}
360 eed65ec6 n.hoffmann
361 3be6ef3e n.hoffmann
	/**
362 eed65ec6 n.hoffmann
	 * <p>
363
	 * addTermToPreferredTerms
364
	 * </p>
365 fa69e58f Patric Plitzner
	 *
366 eed65ec6 n.hoffmann
	 * @param term
367
	 *            a T object.
368
	 * @param <T>
369
	 *            a T object.
370 3be6ef3e n.hoffmann
	 */
371 eed65ec6 n.hoffmann
	public static <T extends TermBase> void addTermToPreferredTerms(T term) {
372 3be6ef3e n.hoffmann
373 eed65ec6 n.hoffmann
		// VocabularyEnum vocabulary =
374
		// VocabularyEnum.getVocabularyEnum(term.getClass());
375
		//
376
		// getPreferenceStore().setValue(getPreferenceKey(term),
377
		// VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
378
		//
379
		// firePreferencesChanged(term.getClass());
380 3be6ef3e n.hoffmann
	}
381 eed65ec6 n.hoffmann
382 3be6ef3e n.hoffmann
	/**
383
	 * Construct a unique key using the CdmBase object's uuid
384 fa69e58f Patric Plitzner
	 *
385 3be6ef3e n.hoffmann
	 * @param cdmBase
386
	 * @return
387
	 */
388
	private static String getPreferenceKey(ICdmBase cdmBase) {
389 8c1b17fc Katja Luther
		cdmBase = HibernateProxyHelper.deproxy(cdmBase);
390 eed65ec6 n.hoffmann
391
		String key = cdmBase.getClass().getName().concat(".")
392
				.concat(cdmBase.getUuid().toString());
393 3be6ef3e n.hoffmann
		if (key.contains("javassist")) {
394 41e2f693 Cherian Mathew
			MessagingUtils.info("proxy");
395 3be6ef3e n.hoffmann
		}
396
		return key;
397
	}
398 fa69e58f Patric Plitzner
399 1c4f6bb6 Cherian Mathew
	/**
400
	 * Construct a unique key using the CdmBase object's uuid
401 fa69e58f Patric Plitzner
	 *
402 1c4f6bb6 Cherian Mathew
	 * @param cdmBase
403
	 * @return
404
	 */
405
	public static String getPreferenceKey(ISimpleTerm simpleTerm) {
406 8c1b17fc Katja Luther
		simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
407 1c4f6bb6 Cherian Mathew
		String key = simpleTerm.getClass().getName().concat(".")
408
				.concat(simpleTerm.getUuid().toString());
409
		if (key.contains("javassist")) {
410 41e2f693 Cherian Mathew
			MessagingUtils.warn(PreferencesUtil.class,
411 1c4f6bb6 Cherian Mathew
					"Trying to persist a preference based on a proxy class.");
412
		}
413
		return key;
414
	}
415 fa69e58f Patric Plitzner
416
417 3be6ef3e n.hoffmann
418
	/**
419
	 * Construct a unique key using the CdmBase object's uuid
420 fa69e58f Patric Plitzner
	 *
421 3be6ef3e n.hoffmann
	 * @param cdmBase
422
	 * @return
423
	 */
424 eed65ec6 n.hoffmann
	public static String getPreferenceKey(IDefinedTerm definedTerm) {
425 8c1b17fc Katja Luther
		definedTerm = HibernateProxyHelper.deproxy(definedTerm);
426 eed65ec6 n.hoffmann
		String key = definedTerm.getClass().getName().concat(".")
427
				.concat(definedTerm.getUuid().toString());
428 3be6ef3e n.hoffmann
		if (key.contains("javassist")) {
429 41e2f693 Cherian Mathew
			MessagingUtils.warn(PreferencesUtil.class,
430 eed65ec6 n.hoffmann
					"Trying to persist a preference based on a proxy class.");
431 3be6ef3e n.hoffmann
		}
432
		return key;
433
	}
434 eed65ec6 n.hoffmann
435 3be6ef3e n.hoffmann
	/**
436
	 * Retrieves search preferences from the preference store
437 fa69e58f Patric Plitzner
	 *
438 3be6ef3e n.hoffmann
	 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
439
	 */
440 d70f4b3c Andreas Kohlbecker
	public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
441
		IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
442 eed65ec6 n.hoffmann
443
		configurator.setDoTaxa(getPreferenceStore().getBoolean(
444
				TAXON_SERVICE_CONFIGURATOR_TAXA));
445
		configurator.setDoSynonyms(getPreferenceStore().getBoolean(
446
				TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
447
		configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
448
				TAXON_SERVICE_CONFIGURATOR_NAMES));
449
		configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
450
				TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
451 bd6bf04f Katja Luther
		//configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
452 3be6ef3e n.hoffmann
453
		return configurator;
454
	}
455 eed65ec6 n.hoffmann
456 3be6ef3e n.hoffmann
	/**
457
	 * create new preferences, setting all search options to true
458 fa69e58f Patric Plitzner
	 *
459 eed65ec6 n.hoffmann
	 * @return a
460
	 *         {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
461
	 *         object.
462 3be6ef3e n.hoffmann
	 */
463 d70f4b3c Andreas Kohlbecker
	public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
464
		IFindTaxaAndNamesConfigurator configurator = new FindTaxaAndNamesConfiguratorImpl();
465 eed65ec6 n.hoffmann
466 3be6ef3e n.hoffmann
		configurator.setDoTaxa(true);
467
		configurator.setDoSynonyms(true);
468
		configurator.setDoNamesWithoutTaxa(true);
469
		configurator.setDoTaxaByCommonNames(true);
470 eed65ec6 n.hoffmann
471
		configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
472
				"name", "name.$", "relationsFromThisTaxon.$"));
473
474
		configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
475
				"name", "name.$", "synonymRelations.relatedTo.*"));
476
477
		// DEFAULT VALUES
478
		// match mode is a simple like, actually all other match modes are kind
479
		// of bogus
480
		configurator
481 deb874ab Cherian Mathew
				.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
482 3be6ef3e n.hoffmann
		// we set page number and size here as this should always be unlimited
483
		configurator.setPageNumber(0);
484
		// TODO currently limit results to 10000
485
		configurator.setPageSize(10000);
486 eed65ec6 n.hoffmann
487 3be6ef3e n.hoffmann
		return configurator;
488
	}
489 eed65ec6 n.hoffmann
490 3be6ef3e n.hoffmann
	/**
491
	 * Store search preferences
492 fa69e58f Patric Plitzner
	 *
493 eed65ec6 n.hoffmann
	 * @param configurator
494
	 *            a
495
	 *            {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
496
	 *            object.
497 3be6ef3e n.hoffmann
	 */
498 eed65ec6 n.hoffmann
	public static void setSearchConfigurator(
499 d70f4b3c Andreas Kohlbecker
			IFindTaxaAndNamesConfigurator configurator) {
500 eed65ec6 n.hoffmann
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
501
				configurator.isDoTaxa());
502
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
503
				configurator.isDoSynonyms());
504
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
505
				configurator.isDoNamesWithoutTaxa());
506
		getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
507
				configurator.isDoTaxaByCommonNames());
508 3be6ef3e n.hoffmann
	}
509
510
	/**
511 eed65ec6 n.hoffmann
	 * <p>
512
	 * firePreferencesChanged
513
	 * </p>
514 fa69e58f Patric Plitzner
	 *
515 eed65ec6 n.hoffmann
	 * @param clazz
516
	 *            a {@link java.lang.Class} object.
517 3be6ef3e n.hoffmann
	 */
518
	public static void firePreferencesChanged(Class clazz) {
519 eed65ec6 n.hoffmann
		getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
520
				null, clazz);
521 3be6ef3e n.hoffmann
	}
522
523
	/**
524
	 * Set default values for preferences
525
	 */
526
	public static void setDefaults() {
527
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
528 eed65ec6 n.hoffmann
		getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
529
				true);
530
		getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT,
531 fa69e58f Patric Plitzner
				"http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
532 94b0efb6 Cherian Mathew
		//FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
533
		getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, false);
534 eed65ec6 n.hoffmann
		getPreferenceStore().setDefault(OPENURL_ACCESS_POINT,
535
				"http://www.biodiversitylibrary.org/openurl");
536 5d1f3b51 n.hoffmann
		getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000");
537
		getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT, "1000");
538 46dd5dda Alexander Oppermann
		getPreferenceStore().setDefault(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, false);
539 e598b1c7 Katja Luther
		getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY, true);
540 e98bd118 Katja Luther
		getPreferenceStore().setDefault(CHECKLIST_SYMBOL, false);
541 76b874f8 Katja Luther
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, true);
542 cd19940f Katja Luther
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE, true);
543 76b874f8 Katja Luther
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, true);
544
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_HYBRID, true);
545
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_LSID, true);
546
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, true);
547
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAMECACHE, true);
548
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, true);
549
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, true);
550
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, true);
551
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, true);
552
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_RANK, true);
553
		getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, true);
554 98dc1f12 Katja Luther
		getPreferenceStore().setDefault(SORT_NODES_NATURALLY, false);
555
		getPreferenceStore().setDefault(SORT_NODES_ALPHABETICALLY, false);
556
557 3be6ef3e n.hoffmann
	}
558
559
	/**
560 eed65ec6 n.hoffmann
	 * <p>
561
	 * checkNomenclaturalCode
562
	 * </p>
563 3be6ef3e n.hoffmann
	 */
564 eed65ec6 n.hoffmann
	public static void checkNomenclaturalCode() {
565 3be6ef3e n.hoffmann
		// First time Editor is opened, no nomenclatural code has been set
566 4afd9d97 Alexander Oppermann
567
568 b9801dc0 Katja Luther
		if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
569 be140ab3 Katja Luther
			PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP, true);
570 3be6ef3e n.hoffmann
		}
571 e9773ade Katja Luther
572
573
574
	}
575
	public static void setNomenclaturalCodePreferences(){
576 994548e2 Katja Luther
	    ICdmRepository controller;
577 e9773ade Katja Luther
        controller = CdmStore.getCurrentApplicationConfiguration();
578
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
579
        CdmPreference preference = null;
580
        if (controller == null){
581
            return ;
582
        }
583
        preference = controller.getPreferenceService().find(key);
584
        if (preference == null){
585
            return;
586
        }
587
        getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
588
589
        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
590
        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
591
        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
592
593
        getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
594
                getPreferenceKey(preferredCode));
595
596
        if (!preference.isAllowOverride()){
597
            getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
598
                    getPreferenceKey(preferredCode));
599
        }
600 3be6ef3e n.hoffmann
	}
601
602 4afd9d97 Alexander Oppermann
	public static void checkDefaultLanguage(){
603
	    if(PreferencesUtil.getPreferredDefaultLangugae() == null){
604 d969af0f Patric Plitzner
	       Shell shell = AbstractUtility.getShell();
605 4afd9d97 Alexander Oppermann
	       int open = new DefaultLanguageDialog(shell).open();
606 a31abd30 Patric Plitzner
	       if(open == Window.OK){
607 4afd9d97 Alexander Oppermann
	           PlatformUI.getWorkbench().restart();
608
	       }
609
	    }else{
610
	        //TODO:In case of a reinstall, the config.ini will be overwritten
611
	        //     here you create config.ini with the stored key from preferences
612
	    }
613
	}
614
615 3be6ef3e n.hoffmann
	/**
616 eed65ec6 n.hoffmann
	 * <p>
617
	 * getMapServiceAccessPoint
618
	 * </p>
619 fa69e58f Patric Plitzner
	 *
620 3be6ef3e n.hoffmann
	 * @return a {@link java.lang.String} object.
621
	 */
622
	public static String getMapServiceAccessPoint() {
623
		return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT);
624
	}
625
626
	/**
627 eed65ec6 n.hoffmann
	 * <p>
628
	 * shouldConnectAtStartUp
629
	 * </p>
630 fa69e58f Patric Plitzner
	 *
631 3be6ef3e n.hoffmann
	 * @return a boolean.
632
	 */
633
	public static boolean shouldConnectAtStartUp() {
634 2985591f Cherian Mathew
		//FIXME :  force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
635
		//return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
636
		return false;
637 3be6ef3e n.hoffmann
	}
638
639
	/**
640 eed65ec6 n.hoffmann
	 * <p>
641
	 * getDefaultFeatureTreeForTextualDescription
642
	 * </p>
643 fa69e58f Patric Plitzner
	 *
644 3be6ef3e n.hoffmann
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
645
	 */
646
	public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
647 eed65ec6 n.hoffmann
		String uuidString = getPreferenceStore().getString(
648
				FEATURE_TREE_DEFAULT_TEXT);
649
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
650
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
651 3be6ef3e n.hoffmann
	}
652
653
	/**
654 eed65ec6 n.hoffmann
	 * <p>
655
	 * getDefaultFeatureTreeForStructuredDescription
656
	 * </p>
657 fa69e58f Patric Plitzner
	 *
658 3be6ef3e n.hoffmann
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
659
	 */
660
	public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
661 eed65ec6 n.hoffmann
		String uuidString = getPreferenceStore().getString(
662
				FEATURE_TREE_DEFAULT_STRUCTURE);
663
		return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
664
				IFeatureTreeService.class).load(UUID.fromString(uuidString));
665 3be6ef3e n.hoffmann
	}
666
667
	/**
668 eed65ec6 n.hoffmann
	 * <p>
669
	 * setSortRanksHierarchichally
670
	 * </p>
671 fa69e58f Patric Plitzner
	 *
672 eed65ec6 n.hoffmann
	 * @param selection
673
	 *            a boolean.
674 3be6ef3e n.hoffmann
	 */
675
	public static void setSortRanksHierarchichally(boolean selection) {
676
		getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY, selection);
677 eed65ec6 n.hoffmann
	}
678
679 3be6ef3e n.hoffmann
	/**
680 eed65ec6 n.hoffmann
	 * <p>
681
	 * getSortRanksHierarchichally
682
	 * </p>
683 fa69e58f Patric Plitzner
	 *
684 3be6ef3e n.hoffmann
	 * @return a boolean.
685
	 */
686 eed65ec6 n.hoffmann
	public static boolean getSortRanksHierarchichally() {
687 3be6ef3e n.hoffmann
		return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY);
688
	}
689 35861667 n.hoffmann
690
	public static boolean isMultilanguageTextEditingCapability() {
691 eed65ec6 n.hoffmann
		return getPreferenceStore().getBoolean(
692
				MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
693 35861667 n.hoffmann
	}
694 eed65ec6 n.hoffmann
695
	public static Language getGlobalLanguage() {
696 bcad19b9 Cherian Mathew
697
698 eed65ec6 n.hoffmann
		String languageUuidString = getPreferenceStore().getString(
699
				GLOBAL_LANGUAGE_UUID);
700
701 bcad19b9 Cherian Mathew
		if(!CdmStore.isActive()) {
702
            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
703
            return null;
704
        }
705
706 c338dc84 Cherian Mathew
		if (CdmUtils.isBlank(languageUuidString)) {
707
			return Language.getDefaultLanguage();
708 ea781c57 n.hoffmann
		}
709 eed65ec6 n.hoffmann
710 ea781c57 n.hoffmann
		UUID languageUuid = UUID.fromString(languageUuidString);
711 eed65ec6 n.hoffmann
		return (Language) CdmStore.getService(ITermService.class).load(
712
				languageUuid);
713 ea781c57 n.hoffmann
	}
714 eed65ec6 n.hoffmann
715
	public static void setGlobalLanguage(Language language) {
716 bcad19b9 Cherian Mathew
	    if(language != null) {
717
	        getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
718
	        CdmStore.setDefaultLanguage(language);
719
	    }
720
721 ea781c57 n.hoffmann
	}
722 db5e366d n.hoffmann
723
	/**
724
	 * @return
725
	 */
726
	public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
727 eed65ec6 n.hoffmann
		List<MarkerType> markerTypes = CdmStore.getTermManager()
728 b9a0d300 l.morris
				.getPreferredTerms(MarkerType.class);
729 eed65ec6 n.hoffmann
730 db5e366d n.hoffmann
		Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
731 eed65ec6 n.hoffmann
732
		for (MarkerType markerType : markerTypes) {
733 db5e366d n.hoffmann
			String name = getMarkerTypeEditingPreferenceKey(markerType);
734
			Boolean value = getPreferenceStore().getBoolean(name);
735 eed65ec6 n.hoffmann
736 db5e366d n.hoffmann
			result.put(markerType, value);
737
		}
738 eed65ec6 n.hoffmann
739 db5e366d n.hoffmann
		return result;
740
	}
741
742
	/**
743
	 * @param markerTypeEditingMap
744
	 */
745
	public static void setEditMarkerTypePreferences(
746
			Map<MarkerType, Boolean> markerTypeEditingMap) {
747 eed65ec6 n.hoffmann
		for (MarkerType markerType : markerTypeEditingMap.keySet()) {
748 db5e366d n.hoffmann
			String name = getMarkerTypeEditingPreferenceKey(markerType);
749 eed65ec6 n.hoffmann
			getPreferenceStore().setValue(name,
750
					markerTypeEditingMap.get(markerType));
751 db5e366d n.hoffmann
		}
752 eed65ec6 n.hoffmann
753 db5e366d n.hoffmann
	}
754 eed65ec6 n.hoffmann
755
	private static String getMarkerTypeEditingPreferenceKey(
756
			MarkerType markerType) {
757 8c1b17fc Katja Luther
		markerType = HibernateProxyHelper.deproxy(markerType);
758 db5e366d n.hoffmann
		return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
759
	}
760 eed65ec6 n.hoffmann
761 db5e366d n.hoffmann
	/**
762 eed65ec6 n.hoffmann
	 * <p>
763
	 * setEditMarkerTypePreference
764
	 * </p>
765 fa69e58f Patric Plitzner
	 *
766 eed65ec6 n.hoffmann
	 * @param input
767
	 *            a {@link org.eclipse.ui.IEditorInput} object.
768
	 * @param markerType
769
	 *            a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
770
	 * @param edit
771
	 *            a boolean.
772 db5e366d n.hoffmann
	 */
773 eed65ec6 n.hoffmann
	public static void setEditMarkerTypePreference(MarkerType markerType,
774
			boolean edit) {
775
		getPreferenceStore().setValue(
776
				getMarkerTypeEditingPreferenceKey(markerType), edit);
777 db5e366d n.hoffmann
	}
778
779 42982abe n.hoffmann
	/**
780
	 * @return
781
	 */
782
	public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
783 eed65ec6 n.hoffmann
		DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
784
				.NewInstance();
785 42982abe n.hoffmann
		configurator.setMoveDerivedUnitMediaToGallery(true);
786
		configurator.setMoveFieldObjectMediaToGallery(true);
787
		return configurator;
788
	}
789
790 86cc5c9a Alexander Oppermann
	/**
791
	 * This method will write language properties to the config.ini located in the configuration folder
792
	 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
793
	 *
794
	 * @param setLanguage 0 is for german and 1 for english.
795
	 * @throws IOException
796
	 */
797
    public void writePropertyToConfigFile(int setLanguage) throws IOException {
798
        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
799 7a8e7c22 Alexander Oppermann
        //give warning to user if the directory has no write access
800
        if(file == null){
801
            throw new IOException();
802
        }
803 86cc5c9a Alexander Oppermann
        Properties properties = load(file.getAbsolutePath()+"/config.ini");
804
        switch(setLanguage){
805
        case 0:
806
            properties.setProperty("osgi.nl", "de");
807
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
808
            break;
809
        case 1:
810
            properties.setProperty("osgi.nl", "en");
811
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
812
            break;
813
        default:
814
            break;
815
        }
816
        save(file+"/config.ini", properties);
817
    }
818
819
    /**
820
     * This method loads a property from a given file and returns it.
821
     *
822
     * @param filename
823
     * @return
824
     * @throws IOException
825
     */
826
    private Properties load(String filename) throws IOException {
827
        FileInputStream in = new FileInputStream(filename);
828
        Properties prop = new Properties();
829
        prop.load(in);
830
        in.close();
831
        return prop;
832
    }
833
834
    /**
835
     * This method saves a property to the specified file.
836
     *
837
     * @param filename
838
     * @param properties
839
     * @throws IOException
840
     */
841
    private void save(String filename, Properties properties) throws IOException{
842
        FileOutputStream fos =  new FileOutputStream(filename);
843
        properties.store(fos, "");
844
        fos.close();
845
    }
846
847 aa997cff Cherian Mathew
    /**
848
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
849
     *
850
     * @param p2Repos
851
     */
852
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
853
        StringBuilder sb = new StringBuilder();
854
        for(MetadataRepositoryElement p2Repo : p2Repos) {
855
            sb.append(P2_REPOSITORIES_DELIM);
856 c01d683c Cherian Mathew
            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
857
                sb.append("-");
858
            } else {
859
                sb.append(p2Repo.getName());
860
            }
861 aa997cff Cherian Mathew
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
862
            sb.append(p2Repo.getLocation().toString());
863
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
864
            sb.append(String.valueOf(p2Repo.isEnabled()));
865
        }
866
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
867
    }
868
869
870
    /**
871
     * Retrieves a list of previously saved P2 repositories
872
     *
873
     * @return
874
     */
875
    public static List<MetadataRepositoryElement> getP2Repositories() {
876
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
877
        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
878
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
879
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
880 c01d683c Cherian Mathew
881 aa997cff Cherian Mathew
            while(p2ReposPrefST.hasMoreTokens()) {
882
                String p2RepoStr = p2ReposPrefST.nextToken();
883
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
884 c01d683c Cherian Mathew
                if(p2ReposStrST.countTokens()==3) {
885
                    String nickname = p2ReposStrST.nextToken();
886
                    URI uri = null;
887
                    try {
888
                        uri = new URI(p2ReposStrST.nextToken());
889
                    } catch (URISyntaxException e) {
890
                        continue;
891
                    }
892
                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
893
                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
894
                    mre.setNickname(nickname);
895
                    mre.setEnabled(enabled);
896
                    p2Repos.add(mre);
897 aa997cff Cherian Mathew
                }
898
            }
899
        }
900
901
        return p2Repos;
902
    }
903 b4e62664 Alexander Oppermann
904
    /**
905
     * enables/disables nested composite. <br>
906
     *
907
     * @param ctrl - Composite to be en-/disabeld
908
     * @param enabled - boolean
909
     */
910
    public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
911
        if (ctrl instanceof Composite) {
912
            Composite comp = (Composite) ctrl;
913
            for (Control c : comp.getChildren()) {
914
                recursiveSetEnabled(c, enabled);
915
            }
916
        } else {
917
            ctrl.setEnabled(enabled);
918
        }
919
    }
920 8c1b17fc Katja Luther
921 4633f830 Katja Luther
    /**
922
	 * <p>
923
	 * getSortRanksNaturally
924
	 * </p>
925 98dc1f12 Katja Luther
    	 *
926
    	 * @return a boolean.
927 4633f830 Katja Luther
	 */
928
	public static boolean getSortNodesNaturally() {
929
		return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY);
930
	}
931 8c1b17fc Katja Luther
932 4633f830 Katja Luther
	/**
933
	 * <p>
934
	 * setSortRanksNaturally
935
	 * </p>
936
	 *
937
	 * @param selection
938
	 *            a boolean.
939
	 */
940
	public static void setSortNodesNaturally(boolean selection) {
941
		getPreferenceStore().setValue(SORT_NODES_NATURALLY, selection);
942
	}
943 e5de8a59 k.luther
944 8c1b17fc Katja Luther
945 e5de8a59 k.luther
	/**
946
	 * <p>
947
	 * getSortRanksNaturally
948
	 * </p>
949
	 *
950
	 * @return a boolean.
951
	 */
952
	public static boolean getSortNodesStrictlyAlphabetically() {
953
		return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY);
954
	}
955 8c1b17fc Katja Luther
956 e5de8a59 k.luther
	/**
957
	 * <p>
958
	 * setSortRanksNaturally
959
	 * </p>
960
	 *
961
	 * @param selection
962
	 *            a boolean.
963
	 */
964
	public static void setSortNodesStrictlyAlphabetically(boolean selection) {
965
		getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY, selection);
966
	}
967 2b468360 Katja Luther
968
	/**
969
	 * <p>
970
	 * setStoreNavigatorState
971
	 * </p>
972
	 *
973
	 * @param selection
974
	 *            a boolean.
975
	 */
976
	public static boolean isStoreNavigatorState() {
977
		return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE);
978 8c1b17fc Katja Luther
979 2b468360 Katja Luther
	}
980 8c1b17fc Katja Luther
981 2b468360 Katja Luther
	/**
982
	 * <p>
983
	 * setStoreNavigatorState
984
	 * </p>
985
	 *
986
	 * @param selection
987
	 *            a boolean.
988
	 */
989
	public static void setStoreNavigatorState(boolean selection) {
990
		getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE, selection);
991 8c1b17fc Katja Luther
992 2b468360 Katja Luther
	}
993 8c1b17fc Katja Luther
994
    /**
995
     * @return
996
     */
997 d3d01e43 Katja Luther
    public static boolean isShowUpWidgetIsDisposedMessages() {
998
       return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED);
999 8c1b17fc Katja Luther
    }
1000 d3d01e43 Katja Luther
    public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1001
        getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1002 8c1b17fc Katja Luther
    }
1003 7c9efe6c Katja Luther
1004 e598b1c7 Katja Luther
    /**
1005
     * @return
1006
     */
1007
    public static boolean isShowIdInVocabularyInChecklistEditor() {
1008
       return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY);
1009
    }
1010
    public static void setShowIdInVocabularyInChecklistEditor(boolean selection) {
1011
        getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY, selection);
1012
    }
1013 256fbc69 Katja Luther
1014 e98bd118 Katja Luther
    /**
1015
     * @return
1016
     */
1017
    public static boolean isShowSymbolInChecklistEditor() {
1018
       return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SYMBOL);
1019
    }
1020
    public static void setShowSymbolInChecklistEditor(boolean selection) {
1021
        getPreferenceStore().setValue(CHECKLIST_SYMBOL, selection);
1022
    }
1023 941644f3 Katja Luther
1024 a5b15eef Katja Luther
    /**
1025
     * @return
1026
     */
1027
    public static boolean isShowRankInChecklistEditor() {
1028
        return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SHOW_RANK);
1029
    }
1030
    public static void setShowRankInChecklistEditor(boolean selection) {
1031
        getPreferenceStore().setValue(CHECKLIST_SHOW_RANK, selection);
1032
    }
1033 7c9efe6c Katja Luther
1034 23925b61 Katja Luther
    /**
1035
     * @param object
1036
     * @param b
1037
     * @return
1038
     */
1039
    public static NameDetailsConfigurator setPreferredNameDetailsConfiguration( boolean local) {
1040
        NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1041 994548e2 Katja Luther
1042 23925b61 Katja Luther
        CdmPreference preference = null;
1043 994548e2 Katja Luther
1044
        if (!local) {
1045
            preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
1046 23925b61 Katja Luther
        }
1047
        if (preference == null){
1048
            return null;
1049
        }
1050 994548e2 Katja Luther
1051 256fbc69 Katja Luther
        getPreferenceStore().setValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1052 23925b61 Katja Luther
1053
        //the preference value is build like this:
1054
        //<section1>:true;<section2>:false....
1055
1056
        String value = preference.getValue();
1057
        String [] sections = value.split(";");
1058
        Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1059
        String[] sectionValues;
1060
        for (String sectionValue: sections){
1061
            sectionValues = sectionValue.split(":");
1062
            sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1063
        }
1064
1065 f6c0ab3d Katja Luther
        config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1066 23925b61 Katja Luther
1067 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
1068
//                (getValue(sectionMap, "taxon")));
1069 e98bd118 Katja Luther
        config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1070 23925b61 Katja Luther
1071 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
1072
//                (getValue(sectionMap, "lsid")));
1073 e98bd118 Katja Luther
        config.setLSIDActivated(getValue(sectionMap, "lsid"));
1074 23925b61 Katja Luther
1075 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1076
//                (getValue(sectionMap, "nc")));
1077 e98bd118 Katja Luther
        config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1078 23925b61 Katja Luther
1079 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1080
//                (getValue(sectionMap, "ap")));
1081 e98bd118 Katja Luther
        config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1082 23925b61 Katja Luther
1083 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
1084
//                (getValue(sectionMap, "rank")));
1085 e98bd118 Katja Luther
        config.setRankActivated(getValue(sectionMap, "rank"));
1086 23925b61 Katja Luther
1087
1088 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1089
//                (getValue(sectionMap, "atomisedEpithets")));
1090 e98bd118 Katja Luther
        config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1091 23925b61 Katja Luther
1092 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1093
//                (getValue(sectionMap,"author")));
1094 e98bd118 Katja Luther
        config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1095 23925b61 Katja Luther
1096 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1097
//                (getValue(sectionMap, "nomRef")));
1098 23925b61 Katja Luther
        config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1099
1100 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1101
//                (getValue(sectionMap, "nomStat")));
1102 e98bd118 Katja Luther
        config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1103 23925b61 Katja Luther
1104
1105 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1106
//                (getValue(sectionMap,"protologue")));
1107 e98bd118 Katja Luther
        config.setProtologueActivated(getValue(sectionMap,"protologue"));
1108 23925b61 Katja Luther
1109 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1110
//                (getValue(sectionMap,"typeDes")));
1111 e98bd118 Katja Luther
        config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1112 23925b61 Katja Luther
1113 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1114
//                (getValue(sectionMap,"nameRelation")));
1115 e98bd118 Katja Luther
        config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1116 256fbc69 Katja Luther
1117 e5f892b4 Katja Luther
//        getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
1118
//                (getValue(sectionMap, "hybrid")));
1119 e98bd118 Katja Luther
        config.setHybridActivated(getValue(sectionMap,"hybrid"));
1120 23925b61 Katja Luther
1121
        return config;
1122
    }
1123
1124 e98bd118 Katja Luther
    private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1125
		if (sectionMap.containsKey(string)){
1126
			return sectionMap.get(string);
1127
		}else{
1128
			return true;
1129
		}
1130 994548e2 Katja Luther
1131 256fbc69 Katja Luther
	}
1132 994548e2 Katja Luther
1133 256fbc69 Katja Luther
//	public static boolean isDeterminiationOnlyForFieldUnit(boolean local){
1134
//        CdmPreference preference = null;
1135
//
1136
//        if (!local) {
1137
//            preference = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
1138
//        }
1139
//        if (preference == null){
1140
//            return getPreferenceStore().getBoolean(DETERMINATION_ONLY_FOR_FIELD_UNITS);
1141
//        }
1142
//        return Boolean.valueOf(preference.getValue());
1143
//    }
1144
//
1145
//    public static boolean isShowCollectingAreasInGeneralSection(boolean local){
1146
//        CdmPreference preference = null;
1147
//
1148
//        if (!local) {
1149
//            preference = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
1150
//        }
1151
//        if (preference == null){
1152
//            return getPreferenceStore().getBoolean(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
1153
//        }
1154
//        return Boolean.valueOf(preference.getValue());
1155
//    }
1156
//
1157
//    public static boolean isShowTaxonAssociations(boolean local){
1158
//        CdmPreference preference = null;
1159
//
1160
//        if (!local) {
1161
//            preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
1162
//        }
1163
//        if (preference == null){
1164
//            return getPreferenceStore().getBoolean(SHOW_TAXON_ASSOCIATIONS);
1165
//        }
1166
//        return Boolean.valueOf(preference.getValue());
1167
//    }
1168 994548e2 Katja Luther
1169 bde14373 Katja Luther
//    public static boolean getBioCaseProvider(boolean local){
1170
//        CdmPreference preference = null;
1171
//
1172
//        if (!local) {
1173
//            preference = getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
1174
//        }
1175
//        if (preference == null){
1176
//            return getPreferenceStore().getBoolean(SHOW_TAXON_ASSOCIATIONS);
1177
//        }
1178
//        return Boolean.valueOf(preference.getValue());
1179
//    }
1180
1181
1182
    /**
1183
     * <p>
1184
     * setAbcdConfigurator
1185
     * </p>
1186
     *
1187
     * @param preferredConfiguration
1188
     *            a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1189
     *            object.
1190
     */
1191 da948591 Katja Luther
    public static Abcd206ImportConfigurator getAbcdImportConfigurationPreference(boolean useLocal) {
1192
1193
        Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1194
1195
        if (useLocal){
1196
            config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1197
1198
            config.setAddMediaAsMediaSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1199
1200
            config.setAllowReuseOtherClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1201
            config.setDeduplicateClassifications(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1202
            config.setDeduplicateReferences(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1203
1204
            config.setGetSiblings(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1205
            config.setIgnoreAuthorship(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1206
            config.setIgnoreImportOfExistingSpecimen(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1207
            config.setMapUnitIdToAccessionNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1208
            config.setMapUnitIdToBarcode(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1209
            config.setMapUnitIdToCatalogNumber(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1210
            config.setMoveNewTaxaToDefaultClassification(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1211
            config.setOverwriteExistingSpecimens(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1212
            config.setReuseExistingDescriptiveGroups(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1213
            config.setReuseExistingMetaData(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1214
            config.setReuseExistingTaxaWhenPossible(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1215
            return config;
1216
1217
        }
1218
            ICdmRepository controller;
1219
            controller = CdmStore.getCurrentApplicationConfiguration();
1220
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
1221
            CdmPreference preference = null;
1222
            if (controller == null){
1223
                return null;
1224
            }
1225
            preference = controller.getPreferenceService().find(key);
1226
            if (preference == null){
1227
                return config;
1228
             } else{
1229
             String configString = preference.getValue();
1230
             String[] configArray = configString.split(";");
1231
1232
             for (String configItem: configArray){
1233
                 String[] keyValue = configItem.split(":");
1234
                 String keyString = keyValue[0];
1235
                 String valueString = keyValue[1];
1236
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1237
                     config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1238
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1239
                     config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1240
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1241
                     config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1242
                 }else if (keyString.equals("ignoreAuthorship")){
1243
                     config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1244
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1245
                     config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1246
                 }else if (keyString.equals("reuseExistingMetaData")){
1247
                     config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1248
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1249
                     config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1250
                 }else if (keyString.equals("allowReuseOtherClassifications")){
1251
                     config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1252
                 }else if (keyString.equals("deduplicateReferences")){
1253
                     config.setDeduplicateReferences(Boolean.valueOf(valueString));
1254
                 }else if (keyString.equals("deduplicateClassifications")){
1255
                     config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1256
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1257
                     config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1258
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1259
                     config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1260
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1261
                     config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1262
                 }else if (keyString.equals("mapUnitIdToBarcode")){
1263
                     config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1264
                 }else if (keyString.equals("overwriteExistingSpecimens")){
1265
                     config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1266
                 }else{
1267
                     logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1268
                 }
1269
1270
            }
1271
        }
1272
        return config;
1273
1274
1275
1276
    }
1277 bde14373 Katja Luther
1278 e5f892b4 Katja Luther
    /**
1279
    *
1280
    */
1281
   public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
1282
       NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1283
       if (local){
1284
          config.setSimpleDetailsViewActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
1285
          config.setAppendedPhraseActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
1286
          config.setAtomisedEpithetsActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
1287
          config.setAuthorshipSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
1288
          config.setLSIDActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
1289
          config.setNameApprobiationActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
1290
          config.setNameCacheActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
1291
          config.setNameRelationsSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
1292
          config.setNomenclaturalCodeActived(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
1293
          config.setNomenclaturalStatusSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
1294
          config.setNomenclaturalReferenceSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
1295
          config.setProtologueActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
1296
          config.setRankActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
1297
          config.setTaxonSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
1298
          config.setTypeDesignationSectionActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
1299
          config.setHybridActivated(getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
1300
       }else{
1301
1302
       }
1303
1304
      return config;
1305
   }
1306
1307
1308
   public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
1309
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
1310
               config.isSimpleDetailsViewActivated());
1311
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
1312
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
1313
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
1314
               config.isNomenclaturalCodeActived());
1315
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
1316
               config.isNameCacheActivated());
1317
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
1318
               config.isAppendedPhraseActivated());
1319
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
1320
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
1321
               config.isAtomisedEpithetsActivated());
1322
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
1323
               config.isAuthorCacheActivated());
1324
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
1325
               config.isAuthorshipSectionActivated());
1326
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
1327
               config.isNomenclaturalReferenceSectionActivated());
1328
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
1329
               config.isNomenclaturalStatusSectionActivated());
1330
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
1331
               config.isProtologueActivated());
1332
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
1333
               config.isTypeDesignationSectionActivated());
1334
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
1335
               config.isNameRelationsSectionActivated());
1336
       PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
1337
               config.isHybridActivated());
1338
1339
   }
1340 994548e2 Katja Luther
1341
1342
1343 3be6ef3e n.hoffmann
}