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
.Iterator
;
12 import java
.util
.List
;
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
;
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
;
34 * NomenclaturalCodePreferences class.
41 public class NomenclaturalCodePreferences
extends FieldEditorPreferencePage
42 implements IWorkbenchPreferencePage
{
48 * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
52 protected void createFieldEditors() {
54 addField(new RadioGroupFieldEditor(
55 IPreferenceKeys
.PREFERRED_NOMENCLATURAL_CODE_KEY
,
56 "Available Codes", 1, getLabelAndValues(),
57 getFieldEditorParent(), true));
64 private String
[][] getLabelAndValues() {
65 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
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
));
74 return labelAndValues
;
80 * Initialize the preference page
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);
90 public boolean performOk() {
92 boolean result
= super.performOk();
94 String value
= getPreferenceStore().getString(IPreferenceKeys
.PREFERRED_NOMENCLATURAL_CODE_KEY
);
95 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.NomenclaturalCode
, value
);
96 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
97 IPreferenceService service
= controller
.getPreferenceService();