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
.databasePreferences
.wizard
;
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
.jface
.preference
.IPreferenceStore
;
18 import org
.eclipse
.jface
.wizard
.IWizard
;
19 import org
.eclipse
.jface
.wizard
.IWizardPage
;
20 import org
.eclipse
.ui
.IWorkbench
;
21 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
23 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
28 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
29 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
30 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
39 public class DatabasePreferencesPage
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage
, IWizardPage
{
42 * The wizard to which this page belongs; <code>null</code>
43 * if this page has yet to be added to a wizard.
45 private IWizard wizard
= null;
48 * Indicates whether this page is complete.
50 private boolean isPageComplete
= true;
53 * The page that was shown right before this page became visible;
54 * <code>null</code> if none.
56 private IWizardPage previousPage
= null;
58 CdmPreference preferedNomenclaturalCode
;
63 public DatabasePreferencesPage() {
64 this.noDefaultAndApplyButton();
68 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
71 public void init(IWorkbench workbench
) {
73 setPreferenceStore(TaxeditorStorePlugin
.getDefault()
74 .getPreferenceStore());
76 preferedNomenclaturalCode
= PreferencesUtil
.setPreferredNomenclaturalCode(null, false);
77 if (super.getPreferenceStore()== null){
78 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
85 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
88 protected void createFieldEditors() {
89 setMessage("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
90 ComboFieldEditor nomenclaturalCode
= new ComboFieldEditor(
91 IPreferenceKeys
.CDM_NOMENCLATURAL_CODE_KEY
,
92 "Available Codes", getLabelAndValues(),
93 getFieldEditorParent());
94 nomenclaturalCode
.setPreferenceStore(PreferencesUtil
.getPreferenceStore());
95 addField(nomenclaturalCode
);
96 BooleanFieldEditor allowOverride
= new BooleanFieldEditor(
97 IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
,
98 "allow to use local preference",
99 getFieldEditorParent());
100 allowOverride
.setPreferenceStore(PreferencesUtil
.getPreferenceStore());
101 addField(allowOverride
);
107 * Returns the preference store of this preference page.
109 * This is a framework hook method for subclasses to return a
110 * page-specific preference store. The default implementation
111 * returns <code>null</code>.
114 * @return the preference store, or <code>null</code> if none
117 protected IPreferenceStore
doGetPreferenceStore() {
118 return PreferencesUtil
.getPreferenceStore();
124 private String
[][] getLabelAndValues() {
125 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
126 .getSupportedCodes();
127 String
[][] labelAndValues
= new String
[supportedCodes
.size()][2];
128 for (int i
= 0; i
< supportedCodes
.size(); i
++) {
129 labelAndValues
[i
][0] = NomenclaturalCodeHelper
130 .getDescription(supportedCodes
.get(i
));
131 labelAndValues
[i
][1] = PreferencesUtil
132 .getPreferenceKey(supportedCodes
.get(i
));
134 return labelAndValues
;
137 public boolean performOk() {
138 if (super.getPreferenceStore()== null){
139 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
141 boolean result
= super.performOk();
143 String value
=getPreferenceStore().getString(IPreferenceKeys
.CDM_NOMENCLATURAL_CODE_KEY
);
144 boolean allowOverride
= getPreferenceStore().getBoolean(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
);
145 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.NomenclaturalCode
, value
);
146 pref
.setAllowOverride(allowOverride
);
147 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
148 if (controller
== null){
151 IPreferenceService service
= controller
.getPreferenceService();
161 public boolean canFlipToNextPage() {
162 // TODO Auto-generated method stub
170 public String
getName() {
172 return "Database Preferences";
179 public IWizardPage
getNextPage() {
180 // TODO Auto-generated method stub
188 public IWizardPage
getPreviousPage() {
197 public IWizard
getWizard() {
206 public boolean isPageComplete() {
208 return isPageComplete
;
215 public void setPreviousPage(IWizardPage page
) {
216 this.previousPage
= page
;
224 public void setWizard(IWizard newWizard
) {
225 this.wizard
= newWizard
;