2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.preference
;
11 import java
.util
.List
;
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
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
21 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
25 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
26 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
32 * NomenclaturalCodePreferences class.
39 public class NomenclaturalCodePreferences
extends FieldEditorPreferencePage
40 implements IWorkbenchPreferencePage
{
46 * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
50 protected void createFieldEditors() {
51 PreferencesUtil
.setPreferredNomenclaturalCode(null, false);
52 if (getPreferenceStore().getBoolean(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
)) {
53 addField(new ComboFieldEditor(
54 IPreferenceKeys
.PREFERRED_NOMENCLATURAL_CODE_KEY
,
55 "Available Codes", getLabelAndValues(),
56 getFieldEditorParent()));
58 addField(new BooleanFieldEditor(
59 IPreferenceKeys
.OVERRIDE_NOMENCLATURAL_CODE_KEY
,
60 "Use local nomenclatural code",
61 getFieldEditorParent()));
63 setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator.");
71 private String
[][] getLabelAndValues() {
72 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
74 String
[][] labelAndValues
= new String
[supportedCodes
.size()][2];
75 for (int i
= 0; i
< supportedCodes
.size(); i
++) {
76 labelAndValues
[i
][0] = NomenclaturalCodeHelper
77 .getDescription(supportedCodes
.get(i
));
78 labelAndValues
[i
][1] = PreferencesUtil
79 .getPreferenceKey(supportedCodes
.get(i
));
81 return labelAndValues
;
87 * Initialize the preference page
90 public void init(IWorkbench workbench
) {
92 setPreferenceStore(TaxeditorStorePlugin
.getDefault()
93 .getPreferenceStore());
95 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
96 if (controller
!= null){
97 IPreferenceService service
= controller
.getPreferenceService();
98 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
99 CdmPreference pref
= service
.find(key
);
100 getPreferenceStore().setValue(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
, pref
.isAllowOverride());
103 if (getPreferenceStore().getBoolean(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
)) {
104 setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified.");
106 setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator.");
112 public boolean performOk() {
114 boolean result
= super.performOk();
116 // String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY);
117 // CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
118 // ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
119 // if (controller == null){
122 // IPreferenceService service = controller.getPreferenceService();
123 // service.set(pref);