3 * Copyright (C) 2016 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.preference
;
12 import java
.util
.List
;
14 import org
.eclipse
.jface
.preference
.BooleanFieldEditor
;
15 import org
.eclipse
.jface
.preference
.ComboFieldEditor
;
16 import org
.eclipse
.jface
.preference
.FieldEditorPreferencePage
;
17 import org
.eclipse
.ui
.IWorkbench
;
18 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
25 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
34 public class AdminNomenclaturalCode
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage
{
37 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
40 public void init(IWorkbench workbench
) {
41 setPreferenceStore(TaxeditorStorePlugin
.getDefault()
42 .getPreferenceStore());
43 setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified. \nATTENTION, this preference is stored in DB!");
44 PreferencesUtil
.setPreferredNomenclaturalCode(null, false);
50 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
53 protected void createFieldEditors() {
54 addField(new ComboFieldEditor(
55 IPreferenceKeys
.CDM_NOMENCLATURAL_CODE_KEY
,
56 "Available Codes", getLabelAndValues(),
57 getFieldEditorParent()));
58 addField(new BooleanFieldEditor(
59 IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
,
60 "allow to use local preference",
61 getFieldEditorParent()));
69 private String
[][] getLabelAndValues() {
70 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
72 String
[][] labelAndValues
= new String
[supportedCodes
.size()][2];
73 for (int i
= 0; i
< supportedCodes
.size(); i
++) {
74 labelAndValues
[i
][0] = NomenclaturalCodeHelper
75 .getDescription(supportedCodes
.get(i
));
76 labelAndValues
[i
][1] = PreferencesUtil
77 .getPreferenceKey(supportedCodes
.get(i
));
79 return labelAndValues
;
82 public boolean performOk() {
84 boolean result
= super.performOk();
86 String value
= getPreferenceStore().getString(IPreferenceKeys
.CDM_NOMENCLATURAL_CODE_KEY
);
87 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.NomenclaturalCode
, value
);
88 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
89 if (controller
== null){
92 IPreferenceService service
= controller
.getPreferenceService();