1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.databasePreferences.wizard;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
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;
|
22
|
|
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;
|
33
|
|
34
|
/**
|
35
|
* @author k.luther
|
36
|
* @date 01.11.2016
|
37
|
*
|
38
|
*/
|
39
|
public class DatabasePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IWizardPage {
|
40
|
|
41
|
/**
|
42
|
* The wizard to which this page belongs; <code>null</code>
|
43
|
* if this page has yet to be added to a wizard.
|
44
|
*/
|
45
|
private IWizard wizard = null;
|
46
|
|
47
|
/**
|
48
|
* Indicates whether this page is complete.
|
49
|
*/
|
50
|
private boolean isPageComplete = true;
|
51
|
|
52
|
/**
|
53
|
* The page that was shown right before this page became visible;
|
54
|
* <code>null</code> if none.
|
55
|
*/
|
56
|
private IWizardPage previousPage = null;
|
57
|
|
58
|
CdmPreference preferedNomenclaturalCode;
|
59
|
|
60
|
/*
|
61
|
*
|
62
|
*/
|
63
|
public DatabasePreferencesPage() {
|
64
|
this.noDefaultAndApplyButton();
|
65
|
}
|
66
|
|
67
|
/* (non-Javadoc)
|
68
|
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
69
|
*/
|
70
|
@Override
|
71
|
public void init(IWorkbench workbench) {
|
72
|
|
73
|
setPreferenceStore(TaxeditorStorePlugin.getDefault()
|
74
|
.getPreferenceStore());
|
75
|
|
76
|
preferedNomenclaturalCode = PreferencesUtil.setPreferredNomenclaturalCode(null, false);
|
77
|
if (super.getPreferenceStore()== null){
|
78
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
79
|
}
|
80
|
|
81
|
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
|
86
|
*/
|
87
|
@Override
|
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);
|
102
|
|
103
|
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Returns the preference store of this preference page.
|
108
|
* <p>
|
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>.
|
112
|
* </p>
|
113
|
*
|
114
|
* @return the preference store, or <code>null</code> if none
|
115
|
*/
|
116
|
@Override
|
117
|
protected IPreferenceStore doGetPreferenceStore() {
|
118
|
return PreferencesUtil.getPreferenceStore();
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* @return
|
123
|
*/
|
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));
|
133
|
}
|
134
|
return labelAndValues;
|
135
|
}
|
136
|
@Override
|
137
|
public boolean performOk() {
|
138
|
if (super.getPreferenceStore()== null){
|
139
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
140
|
}
|
141
|
boolean result = super.performOk();
|
142
|
if (result){
|
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){
|
149
|
return false;
|
150
|
}
|
151
|
IPreferenceService service = controller.getPreferenceService();
|
152
|
service.set(pref);
|
153
|
}
|
154
|
return result;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* {@inheritDoc}
|
159
|
*/
|
160
|
@Override
|
161
|
public boolean canFlipToNextPage() {
|
162
|
// TODO Auto-generated method stub
|
163
|
return true;
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* {@inheritDoc}
|
168
|
*/
|
169
|
@Override
|
170
|
public String getName() {
|
171
|
|
172
|
return "Database Preferences";
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* {@inheritDoc}
|
177
|
*/
|
178
|
@Override
|
179
|
public IWizardPage getNextPage() {
|
180
|
// TODO Auto-generated method stub
|
181
|
return null;
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
* {@inheritDoc}
|
186
|
*/
|
187
|
@Override
|
188
|
public IWizardPage getPreviousPage() {
|
189
|
|
190
|
return previousPage;
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* {@inheritDoc}
|
195
|
*/
|
196
|
@Override
|
197
|
public IWizard getWizard() {
|
198
|
|
199
|
return wizard;
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* {@inheritDoc}
|
204
|
*/
|
205
|
@Override
|
206
|
public boolean isPageComplete() {
|
207
|
|
208
|
return isPageComplete;
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* {@inheritDoc}
|
213
|
*/
|
214
|
@Override
|
215
|
public void setPreviousPage(IWizardPage page) {
|
216
|
this.previousPage = page;
|
217
|
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* {@inheritDoc}
|
222
|
*/
|
223
|
@Override
|
224
|
public void setWizard(IWizard newWizard) {
|
225
|
this.wizard = newWizard;
|
226
|
|
227
|
}
|
228
|
|
229
|
|
230
|
}
|