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.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.eclipse.jface.dialogs.Dialog;
|
19
|
import org.eclipse.jface.dialogs.MessageDialog;
|
20
|
import org.eclipse.jface.preference.IPreferenceStore;
|
21
|
import org.eclipse.swt.widgets.Shell;
|
22
|
import org.eclipse.ui.IEditorInput;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;
|
25
|
import eu.etaxonomy.cdm.api.service.config.impl.TaxonServiceConfiguratorImpl;
|
26
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
27
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
29
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
30
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
31
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
|
33
|
import eu.etaxonomy.cdm.model.common.Language;
|
34
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
35
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
36
|
import eu.etaxonomy.cdm.model.description.Feature;
|
37
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
38
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
39
|
import eu.etaxonomy.cdm.model.description.Modifier;
|
40
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
41
|
import eu.etaxonomy.cdm.model.description.Scope;
|
42
|
import eu.etaxonomy.cdm.model.description.Stage;
|
43
|
import eu.etaxonomy.cdm.model.description.State;
|
44
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
45
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
46
|
import eu.etaxonomy.cdm.model.media.RightsTerm;
|
47
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
48
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
49
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
50
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
51
|
import eu.etaxonomy.cdm.model.name.Rank;
|
52
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
53
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationModifier;
|
54
|
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
|
55
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
56
|
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
|
57
|
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
|
58
|
import eu.etaxonomy.cdm.strategy.match.MatchException;
|
59
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
60
|
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
|
61
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
62
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
63
|
import eu.etaxonomy.taxeditor.store.TermStore;
|
64
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
65
|
|
66
|
/**
|
67
|
* <p>PreferencesUtil class.</p>
|
68
|
*
|
69
|
* @author p.ciardelli
|
70
|
* @author n.hoffmann
|
71
|
* @created 05.12.2008
|
72
|
* @version 1.0
|
73
|
*/
|
74
|
public class PreferencesUtil implements IPreferenceKeys{
|
75
|
|
76
|
/**
|
77
|
*
|
78
|
*/
|
79
|
public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
|
80
|
|
81
|
|
82
|
/**
|
83
|
* <p>getPreferenceStore</p>
|
84
|
*
|
85
|
* @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
|
86
|
*/
|
87
|
public static IPreferenceStore getPreferenceStore() {
|
88
|
return TaxeditorStorePlugin.getDefault().getPreferenceStore();
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* <p>setPreferredNomenclaturalCode</p>
|
93
|
*
|
94
|
* @param preferredCode a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
|
95
|
*/
|
96
|
public static void setPreferredNomenclaturalCode(NomenclaturalCode preferredCode) {
|
97
|
getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, getPreferenceKey(preferredCode));
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* <p>getPreferredNomenclaturalCode</p>
|
102
|
*
|
103
|
* @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
|
104
|
*/
|
105
|
public static NomenclaturalCode getPreferredNomenclaturalCode() {
|
106
|
|
107
|
for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
|
108
|
String preferredCode = getPreferenceStore().getString(PREFERRED_NOMENCLATURAL_CODE_KEY);
|
109
|
if (getPreferenceKey(code).equals(preferredCode)) {
|
110
|
return code;
|
111
|
}
|
112
|
}
|
113
|
return null;
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* The ability to edit marker types in the BulkEditor is associated with an input type, e.g. references.
|
118
|
*
|
119
|
* @param input a {@link org.eclipse.ui.IEditorInput} object.
|
120
|
* @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
|
121
|
* @return a boolean.
|
122
|
*/
|
123
|
public static boolean getEditMarkerTypePreference(IEditorInput input, MarkerType markerType) {
|
124
|
return getPreferenceStore().getBoolean(getEditMarkerTypePrefKey(input, markerType));
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* <p>setEditMarkerTypePreference</p>
|
129
|
*
|
130
|
* @param input a {@link org.eclipse.ui.IEditorInput} object.
|
131
|
* @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
|
132
|
* @param edit a boolean.
|
133
|
*/
|
134
|
public static void setEditMarkerTypePreference(IEditorInput input, MarkerType markerType, boolean edit) {
|
135
|
getPreferenceStore().setValue(getEditMarkerTypePrefKey(input, markerType), edit);
|
136
|
}
|
137
|
|
138
|
private static String getEditMarkerTypePrefKey(IEditorInput input, MarkerType markerType) {
|
139
|
markerType = (MarkerType) HibernateProxyHelper.deproxy(markerType);
|
140
|
return EDIT_MARKER_TYPE_PREFIX + "." + input.getClass().getName() + "." + markerType.getUuid().toString();
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* Get the match strategy for the given class that was stored in preferences
|
145
|
* or the default strategy if it was not stored in preferences
|
146
|
*
|
147
|
* @param clazz a {@link java.lang.Class} object.
|
148
|
* @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
|
149
|
*/
|
150
|
public static IMatchStrategy getMatchStrategy(Class clazz){
|
151
|
String className = clazz.getName();
|
152
|
if(getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)){
|
153
|
IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
|
154
|
|
155
|
for(String fieldName : matchStrategy.getMatchFieldPropertyNames()){
|
156
|
String matchModeName = getPreferenceStore().getString(getMatchStrategyFieldName(className, fieldName));
|
157
|
MatchMode matchMode = MatchMode.valueOf(matchModeName);
|
158
|
try {
|
159
|
matchStrategy.setMatchMode(fieldName, matchMode);
|
160
|
} catch (MatchException e) {
|
161
|
StoreUtil.error(PreferencesUtil.class, e);
|
162
|
throw new RuntimeException(e);
|
163
|
}
|
164
|
}
|
165
|
|
166
|
return matchStrategy;
|
167
|
}
|
168
|
return getDefaultMatchStrategy(clazz);
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* Stores a matchStrategy into the preference store.
|
173
|
*
|
174
|
* @param matchStrategy a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
|
175
|
*/
|
176
|
public static void setMatchStrategy(IMatchStrategy matchStrategy){
|
177
|
String className = matchStrategy.getMatchClass().getName();
|
178
|
getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true);
|
179
|
|
180
|
Set<String> matchFields = matchStrategy.getMatchFieldPropertyNames();
|
181
|
|
182
|
for(String fieldName : matchFields){
|
183
|
getPreferenceStore().setValue(getMatchStrategyFieldName(className, fieldName),
|
184
|
matchStrategy.getMatchMode(fieldName).name());
|
185
|
}
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* Helper method to create the preference property for a match field.
|
190
|
*
|
191
|
* @param className
|
192
|
* @param fieldName
|
193
|
* @return
|
194
|
*/
|
195
|
private static String getMatchStrategyFieldName(String className, String fieldName){
|
196
|
return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* Returns the default match strategy for a given class.
|
201
|
*
|
202
|
* @param clazz a {@link java.lang.Class} object.
|
203
|
* @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
|
204
|
*/
|
205
|
public static IMatchStrategy getDefaultMatchStrategy(Class clazz){
|
206
|
return DefaultMatchStrategy.NewInstance(clazz);
|
207
|
}
|
208
|
|
209
|
|
210
|
/**
|
211
|
* <p>getDateFormatPattern</p>
|
212
|
*
|
213
|
* @return a {@link java.lang.String} object.
|
214
|
*/
|
215
|
public static String getDateFormatPattern(){
|
216
|
// TODO make this configurable in properties
|
217
|
String pattern = "Y-M-d H:m";
|
218
|
return pattern;
|
219
|
}
|
220
|
/**
|
221
|
* Generic method to get term preferences for a term vocabulary
|
222
|
*
|
223
|
* @param initialTerms a {@link java.util.List} object.
|
224
|
* @return a {@link java.util.List} object.
|
225
|
*/
|
226
|
public static <T extends DefinedTermBase> List<T> getPreferredTerms(List<T> initialTerms){
|
227
|
|
228
|
// set default for non existent preferences
|
229
|
defaultTerms(initialTerms);
|
230
|
|
231
|
List<T> preferredTerms = new ArrayList<T>();
|
232
|
|
233
|
for (T term : initialTerms){
|
234
|
if(getPreferenceStore().getBoolean(getPreferenceKey((ICdmBase) term))){
|
235
|
preferredTerms.add(term);
|
236
|
}
|
237
|
}
|
238
|
|
239
|
return preferredTerms;
|
240
|
}
|
241
|
|
242
|
private static <T extends DefinedTermBase> boolean defaultTerms(List<T> initialVocabulary){
|
243
|
// set default for non existing preferences
|
244
|
for(T term : initialVocabulary){
|
245
|
if(getPreferenceStore().getBoolean(term.getClass().getName())){
|
246
|
break;
|
247
|
}else{
|
248
|
getPreferenceStore().setValue(term.getClass().getName(), true);
|
249
|
setPreferredTerms(new ArrayList(initialVocabulary), initialVocabulary);
|
250
|
break;
|
251
|
}
|
252
|
}
|
253
|
return true;
|
254
|
}
|
255
|
|
256
|
|
257
|
/**
|
258
|
* <p>getPreferredSpecimenTypeDesignationStatus</p>
|
259
|
*
|
260
|
* @return a {@link java.util.List} object.
|
261
|
*/
|
262
|
public static List<SpecimenTypeDesignationStatus> getPreferredSpecimenTypeDesignationStatus() { return getPreferredTerms(TermStore.getSpecimenTypeDesignationStatus());}
|
263
|
|
264
|
/**
|
265
|
* <p>getPreferredNameTypeDesignationStatus</p>
|
266
|
*
|
267
|
* @return a {@link java.util.List} object.
|
268
|
*/
|
269
|
public static List<NameTypeDesignationStatus> getPreferredNameTypeDesignationStatus() { return getPreferredTerms(TermStore.getNameTypeDesignationStatus()); }
|
270
|
|
271
|
/**
|
272
|
* <p>getPreferredTaxonRelationshipTypes</p>
|
273
|
*
|
274
|
* @return a {@link java.util.List} object.
|
275
|
*/
|
276
|
public static List<TaxonRelationshipType> getPreferredTaxonRelationshipTypes() { return getPreferredTerms(TermStore.getTaxonRelationshipTypes());}
|
277
|
|
278
|
/**
|
279
|
* <p>getPreferredFeatures</p>
|
280
|
*
|
281
|
* @return a {@link java.util.List} object.
|
282
|
*/
|
283
|
public static List<Feature> getPreferredFeatures() { return getPreferredTerms(TermStore.getFeatures());}
|
284
|
|
285
|
/**
|
286
|
* <p>getPreferredRanks</p>
|
287
|
*
|
288
|
* @return a {@link java.util.List} object.
|
289
|
*/
|
290
|
public static List<Rank> getPreferredRanks() { return getPreferredTerms(TermStore.getRanks());}
|
291
|
|
292
|
/**
|
293
|
* <p>getPreferredPresenceAbsenceTerms</p>
|
294
|
*
|
295
|
* @return a {@link java.util.List} object.
|
296
|
*/
|
297
|
public static List<PresenceAbsenceTermBase> getPreferredPresenceAbsenceTerms(){ return getPreferredTerms(TermStore.getPresenceAbsenceTerms());}
|
298
|
|
299
|
/**
|
300
|
* <p>getPreferredNomenclaturalStatusTypes</p>
|
301
|
*
|
302
|
* @return a {@link java.util.List} object.
|
303
|
*/
|
304
|
public static List<NomenclaturalStatusType> getPreferredNomenclaturalStatusTypes(){ return getPreferredTerms(TermStore.getNomenclaturalStatusTypes());}
|
305
|
|
306
|
/**
|
307
|
* <p>getPreferredNameRelationshipTypes</p>
|
308
|
*
|
309
|
* @return a {@link java.util.List} object.
|
310
|
*/
|
311
|
public static List<NameRelationshipType> getPreferredNameRelationshipTypes(){ return getPreferredTerms(TermStore.getNameRelationshipTypes());}
|
312
|
|
313
|
/**
|
314
|
* <p>getPreferredLanguages</p>
|
315
|
*
|
316
|
* @return a {@link java.util.List} object.
|
317
|
*/
|
318
|
public static List<Language> getPreferredLanguages() { return getPreferredTerms(TermStore.getLanguages()); }
|
319
|
|
320
|
/**
|
321
|
* <p>getPreferredMarkerTypes</p>
|
322
|
*
|
323
|
* @return a {@link java.util.List} object.
|
324
|
*/
|
325
|
public static List<MarkerType> getPreferredMarkerTypes() { return getPreferredTerms(TermStore.getNonTechnicalMarkerTypes()); }
|
326
|
|
327
|
/**
|
328
|
* <p>getPreferredExtensionTypes</p>
|
329
|
*
|
330
|
* @return a {@link java.util.List} object.
|
331
|
*/
|
332
|
public static List<ExtensionType> getPreferredExtensionTypes() { return getPreferredTerms(TermStore.getExtensionTypes()); }
|
333
|
|
334
|
/**
|
335
|
* <p>getPreferredRightsTypes</p>
|
336
|
*
|
337
|
* @return a {@link java.util.List} object.
|
338
|
*/
|
339
|
public static List<RightsTerm> getPreferredRightsTypes() { return getPreferredTerms(TermStore.getRightsTypes());}
|
340
|
|
341
|
/**
|
342
|
* <p>getPreferredNamedAreaTypes</p>
|
343
|
*
|
344
|
* @return a {@link java.util.List} object.
|
345
|
*/
|
346
|
public static List<NamedAreaType> getPreferredNamedAreaTypes() { return getPreferredTerms(TermStore.getNamedAreaTypes()); }
|
347
|
|
348
|
/**
|
349
|
* <p>getPreferredAnnotationTypes</p>
|
350
|
*
|
351
|
* @return a {@link java.util.List} object.
|
352
|
*/
|
353
|
public static List<AnnotationType> getPreferredAnnotationTypes() { return getPreferredTerms(TermStore.getAnnotationTypes()); }
|
354
|
|
355
|
/**
|
356
|
* <p>getPreferredStages</p>
|
357
|
*
|
358
|
* @return a {@link java.util.List} object.
|
359
|
*/
|
360
|
public static List<Stage> getPreferredStages() { return getPreferredTerms(TermStore.getStages()); }
|
361
|
|
362
|
/**
|
363
|
* <p>getPreferredPreservationMethods</p>
|
364
|
*
|
365
|
* @return a {@link java.util.List} object.
|
366
|
*/
|
367
|
public static List<PreservationMethod> getPreferredPreservationMethods() { return getPreferredTerms(TermStore.getPreservationMethods()); }
|
368
|
|
369
|
/**
|
370
|
* <p>getPreferredMeasurementUnits</p>
|
371
|
*
|
372
|
* @return a {@link java.util.List} object.
|
373
|
*/
|
374
|
public static List<MeasurementUnit> getPreferredMeasurementUnits() { return getPreferredTerms(TermStore.getMeasurementUnits()); }
|
375
|
|
376
|
/**
|
377
|
* <p>getPreferredStates</p>
|
378
|
*
|
379
|
* @return a {@link java.util.List} object.
|
380
|
*/
|
381
|
public static List<State> getPreferredStates() { return getPreferredTerms(TermStore.getStates()); }
|
382
|
|
383
|
/**
|
384
|
* <p>getPreferredModifiers</p>
|
385
|
*
|
386
|
* @return a {@link java.util.List} object.
|
387
|
*/
|
388
|
public static List<Modifier> getPreferredModifiers() { return getPreferredTerms(TermStore.getModifiers()); }
|
389
|
|
390
|
/**
|
391
|
* <p>getPreferredStatisticalMeasures</p>
|
392
|
*
|
393
|
* @return a {@link java.util.List} object.
|
394
|
*/
|
395
|
public static List<StatisticalMeasure> getPreferredStatisticalMeasures() { return getPreferredTerms(TermStore.getStatisticalMeasures()); }
|
396
|
|
397
|
/**
|
398
|
* <p>getPreferredScopes</p>
|
399
|
*
|
400
|
* @return a {@link java.util.List} object.
|
401
|
*/
|
402
|
public static List<Scope> getPreferredScopes() { return getPreferredTerms(TermStore.getScopes()); }
|
403
|
|
404
|
/**
|
405
|
* <p>getPreferredDeterminationModifiers</p>
|
406
|
*
|
407
|
* @return a {@link java.util.List} object.
|
408
|
*/
|
409
|
public static List<DeterminationModifier> getPreferredDeterminationModifiers() { return getPreferredTerms(TermStore.getDeterminationModifiers()); }
|
410
|
|
411
|
/**
|
412
|
* Generic method to set term preferences
|
413
|
*
|
414
|
* @param preferredTerms a {@link java.util.List} object.
|
415
|
* @param initialVocabulary a {@link java.util.List} object.
|
416
|
* @param <T> a T object.
|
417
|
*/
|
418
|
public static <T extends DefinedTermBase> void setPreferredTerms(List<T> preferredTerms, List<T> initialVocabulary){
|
419
|
for(TermBase term : initialVocabulary){
|
420
|
getPreferenceStore().setValue(getPreferenceKey(term), preferredTerms.contains(term));
|
421
|
}
|
422
|
}
|
423
|
|
424
|
/**
|
425
|
* <p>addTermToPreferredTerms</p>
|
426
|
*
|
427
|
* @param term a T object.
|
428
|
* @param <T> a T object.
|
429
|
*/
|
430
|
public static <T extends TermBase> void addTermToPreferredTerms(T term){
|
431
|
|
432
|
// VocabularyEnum vocabulary = VocabularyEnum.getVocabularyEnum(term.getClass());
|
433
|
//
|
434
|
// getPreferenceStore().setValue(getPreferenceKey(term), VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
|
435
|
//
|
436
|
// firePreferencesChanged(term.getClass());
|
437
|
}
|
438
|
|
439
|
/**
|
440
|
* Construct a unique key using the CdmBase object's uuid
|
441
|
*
|
442
|
* @param cdmBase
|
443
|
* @return
|
444
|
*/
|
445
|
private static String getPreferenceKey(ICdmBase cdmBase) {
|
446
|
cdmBase = (ICdmBase) HibernateProxyHelper.deproxy(cdmBase);
|
447
|
|
448
|
String key = cdmBase.getClass().getName()
|
449
|
. concat(".")
|
450
|
. concat(cdmBase.getUuid().toString());
|
451
|
if (key.contains("javassist")) {
|
452
|
StoreUtil.info("proxy");
|
453
|
}
|
454
|
return key;
|
455
|
}
|
456
|
|
457
|
/**
|
458
|
* Construct a unique key using the CdmBase object's uuid
|
459
|
*
|
460
|
* @param cdmBase
|
461
|
* @return
|
462
|
*/
|
463
|
private static String getPreferenceKey(IDefinedTerm definedTerm) {
|
464
|
definedTerm = (IDefinedTerm) HibernateProxyHelper.deproxy(definedTerm);
|
465
|
String key = definedTerm.getClass().getName()
|
466
|
. concat(".")
|
467
|
. concat(definedTerm.getUuid().toString());
|
468
|
if (key.contains("javassist")) {
|
469
|
StoreUtil.warn(PreferencesUtil.class, "Trying to persist a preference based on a proxy class.");
|
470
|
}
|
471
|
return key;
|
472
|
}
|
473
|
|
474
|
/**
|
475
|
* Retrieves search preferences from the preference store
|
476
|
*
|
477
|
* @return an {@link ITaxonServiceConfigurator} to pass to search methods
|
478
|
*/
|
479
|
public static ITaxonServiceConfigurator getSearchConfigurator() {
|
480
|
ITaxonServiceConfigurator configurator = initializeSearchConfigurator();
|
481
|
|
482
|
configurator.setDoTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_TAXA));
|
483
|
configurator.setDoSynonyms(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
|
484
|
configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_NAMES));
|
485
|
configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
|
486
|
|
487
|
return configurator;
|
488
|
}
|
489
|
|
490
|
/**
|
491
|
* create new preferences, setting all search options to true
|
492
|
*
|
493
|
* @return a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object.
|
494
|
*/
|
495
|
public static ITaxonServiceConfigurator initializeSearchConfigurator(){
|
496
|
ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl.NewInstance();
|
497
|
|
498
|
configurator.setDoTaxa(true);
|
499
|
configurator.setDoSynonyms(true);
|
500
|
configurator.setDoNamesWithoutTaxa(true);
|
501
|
configurator.setDoTaxaByCommonNames(true);
|
502
|
|
503
|
configurator.setTaxonPropertyPath(Arrays.asList("$",
|
504
|
"titleCache", "name", "name.$", "relationsFromThisTaxon.$"));
|
505
|
|
506
|
configurator.setSynonymPropertyPath(Arrays.asList("$",
|
507
|
"titleCache", "name", "name.$", "synonymRelations.relatedTo.*"));
|
508
|
|
509
|
// DEFAULT VALUES
|
510
|
// match mode default only
|
511
|
configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.BEGINNING);
|
512
|
// i don't know what happens to sec at the moment
|
513
|
configurator.setSec(null);
|
514
|
// we set page number and size here as this should always be unlimited
|
515
|
configurator.setPageNumber(0);
|
516
|
// TODO currently limit results to 10000
|
517
|
configurator.setPageSize(10000);
|
518
|
|
519
|
return configurator;
|
520
|
}
|
521
|
|
522
|
/**
|
523
|
* Store search preferences
|
524
|
*
|
525
|
* @param configurator a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object.
|
526
|
*/
|
527
|
public static void setSearchConfigurator(ITaxonServiceConfigurator configurator){
|
528
|
getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, configurator.isDoTaxa());
|
529
|
getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, configurator.isDoSynonyms());
|
530
|
getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, configurator.isDoNamesWithoutTaxa());
|
531
|
getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, configurator.isDoTaxaByCommonNames());
|
532
|
}
|
533
|
|
534
|
/**
|
535
|
* <p>firePreferencesChanged</p>
|
536
|
*
|
537
|
* @param clazz a {@link java.lang.Class} object.
|
538
|
*/
|
539
|
public static void firePreferencesChanged(Class clazz) {
|
540
|
getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE, null, clazz);
|
541
|
}
|
542
|
|
543
|
/**
|
544
|
* Set default values for preferences
|
545
|
*/
|
546
|
public static void setDefaults() {
|
547
|
getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
|
548
|
getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true);
|
549
|
getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT, "http://edit.br.fgov.be/edit_wp5/v1/areas.php");
|
550
|
getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, true);
|
551
|
}
|
552
|
|
553
|
/**
|
554
|
* <p>checkNomenclaturalCode</p>
|
555
|
*/
|
556
|
public static void checkNomenclaturalCode() {
|
557
|
// First time Editor is opened, no nomenclatural code has been set
|
558
|
if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
|
559
|
|
560
|
StoreUtil.info("No nomencatural code set.");
|
561
|
|
562
|
Shell shell = StoreUtil.getShell();
|
563
|
|
564
|
// Query user re: preferred nom. code
|
565
|
Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
|
566
|
dialog.open();
|
567
|
|
568
|
// Short message confirming user's choice
|
569
|
NomenclaturalCode code = PreferencesUtil.getPreferredNomenclaturalCode();
|
570
|
MessageDialog.openInformation(shell, "Nomenclatural code set",
|
571
|
"The following has been set as your preferred nomenclatural code:\n\n\t" +
|
572
|
NomenclaturalCodeHelper.getDescription(code) + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
|
573
|
}
|
574
|
}
|
575
|
|
576
|
/**
|
577
|
* <p>getMapServiceAccessPoint</p>
|
578
|
*
|
579
|
* @return a {@link java.lang.String} object.
|
580
|
*/
|
581
|
public static String getMapServiceAccessPoint() {
|
582
|
return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT);
|
583
|
}
|
584
|
|
585
|
/**
|
586
|
* <p>shouldConnectAtStartUp</p>
|
587
|
*
|
588
|
* @return a boolean.
|
589
|
*/
|
590
|
public static boolean shouldConnectAtStartUp() {
|
591
|
return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
|
592
|
}
|
593
|
|
594
|
/**
|
595
|
* <p>getDefaultFeatureTreeForTextualDescription</p>
|
596
|
*
|
597
|
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
598
|
*/
|
599
|
public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
|
600
|
String uuidString = getPreferenceStore().getString(FEATURE_TREE_DEFAULT_TEXT);
|
601
|
return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getFeatureTreeService().load(UUID.fromString(uuidString));
|
602
|
}
|
603
|
|
604
|
/**
|
605
|
* <p>getDefaultFeatureTreeForStructuredDescription</p>
|
606
|
*
|
607
|
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
|
608
|
*/
|
609
|
public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
|
610
|
String uuidString = getPreferenceStore().getString(FEATURE_TREE_DEFAULT_STRUCTURE);
|
611
|
return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getFeatureTreeService().load(UUID.fromString(uuidString));
|
612
|
}
|
613
|
|
614
|
/**
|
615
|
* <p>setSortRanksHierarchichally</p>
|
616
|
*
|
617
|
* @param selection a boolean.
|
618
|
*/
|
619
|
public static void setSortRanksHierarchichally(boolean selection) {
|
620
|
getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY, selection);
|
621
|
}
|
622
|
|
623
|
/**
|
624
|
* <p>getSortRanksHierarchichally</p>
|
625
|
*
|
626
|
* @return a boolean.
|
627
|
*/
|
628
|
public static boolean getSortRanksHierarchichally(){
|
629
|
return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY);
|
630
|
}
|
631
|
}
|