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