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