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