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
|
package eu.etaxonomy.taxeditor.preference.menu;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.eclipse.jface.preference.BooleanFieldEditor;
|
14
|
import org.eclipse.jface.preference.ComboFieldEditor;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
17
|
import eu.etaxonomy.cdm.api.service.IPreferenceService;
|
18
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
19
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
|
20
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
21
|
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
|
22
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
23
|
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
|
24
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* <p>
|
30
|
* NomenclaturalCodePreferences class.
|
31
|
* </p>
|
32
|
*
|
33
|
* @author p.ciardelli
|
34
|
* @created 16.09.2008
|
35
|
*/
|
36
|
public class NomenclaturalCodePreferences extends FieldEditorPreferencePageE4 {
|
37
|
CdmPreference pref;
|
38
|
@Override
|
39
|
protected void createFieldEditors() {
|
40
|
PreferencesUtil.setPreferredNomenclaturalCode(null, false);
|
41
|
if (pref.isAllowOverride()) {
|
42
|
addField(new ComboFieldEditor(
|
43
|
PreferencesUtil.createPreferenceString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY),
|
44
|
"Available Codes", getLabelAndValues(),
|
45
|
getFieldEditorParent()));
|
46
|
|
47
|
addField(new BooleanFieldEditor(
|
48
|
PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NomenclaturalCode.getKey()),
|
49
|
"Use local nomenclatural code",
|
50
|
getFieldEditorParent()));
|
51
|
} else {
|
52
|
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator.");
|
53
|
}
|
54
|
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* @return
|
59
|
*/
|
60
|
private String[][] getLabelAndValues() {
|
61
|
List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
|
62
|
.getSupportedCodes();
|
63
|
String[][] labelAndValues = new String[supportedCodes.size()][2];
|
64
|
for (int i = 0; i < supportedCodes.size(); i++) {
|
65
|
labelAndValues[i][0] = NomenclaturalCodeHelper
|
66
|
.getDescription(supportedCodes.get(i));
|
67
|
labelAndValues[i][1] = PreferencesUtil
|
68
|
.getPreferenceKey(supportedCodes.get(i));
|
69
|
}
|
70
|
return labelAndValues;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* {@inheritDoc}
|
75
|
*
|
76
|
* Initialize the preference page
|
77
|
*/
|
78
|
@Override
|
79
|
public void init() {
|
80
|
super.init();
|
81
|
if(!CdmStore.isActive()){
|
82
|
return;
|
83
|
}
|
84
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
85
|
if (controller != null){
|
86
|
IPreferenceService service = controller.getPreferenceService();
|
87
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
|
88
|
pref = service.find(key);
|
89
|
//getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, pref == null? true : pref.isAllowOverride());
|
90
|
}
|
91
|
|
92
|
if (pref.isAllowOverride()) {
|
93
|
setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified.");
|
94
|
}else{
|
95
|
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator.");
|
96
|
|
97
|
}
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public boolean performOk() {
|
102
|
|
103
|
boolean result = super.performOk();
|
104
|
// if (result){
|
105
|
// String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY);
|
106
|
// CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
|
107
|
// ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
108
|
// if (controller == null){
|
109
|
// return false;
|
110
|
// }
|
111
|
// IPreferenceService service = controller.getPreferenceService();
|
112
|
// service.set(pref);
|
113
|
// }
|
114
|
return result;
|
115
|
}
|
116
|
|
117
|
}
|