minor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / wizard / DatabasePreferencesPage.java
1 /**
2 * Copyright (C) 2016 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.databaseAdmin.wizard;
10
11 import java.util.List;
12
13 import org.eclipse.jface.preference.IPreferenceStore;
14 import org.eclipse.jface.wizard.IWizard;
15 import org.eclipse.jface.wizard.IWizardPage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.ScrolledComposite;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Combo;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25
26 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
27 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
28 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
29 import eu.etaxonomy.taxeditor.l10n.Messages;
30 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
31 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
32 import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
33 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34
35 /**
36 * @author k.luther
37 * @date 01.11.2016
38 *
39 */
40 public class DatabasePreferencesPage extends AbstractPreferenceWizard implements IWizardPage{
41
42 CdmPreference preferedNomenclaturalCode;
43 NameDetailsConfigurator config ;
44 CdmPreference isRedListPreference;
45 CdmPreference determinationOnlyForFieldUnitsPreference;
46 CdmPreference showCollectingAreaInGeneralSectionPreference;
47 CdmPreference showTaxonAssociationsPreference;
48
49 boolean isSimpleDetailsViewActivated;
50
51 Composite child ;
52 NameDetailsViewComposite nameDetailsConfig;
53 protected NameDetailsViewComposite getNameDetailsConfig() {
54 return nameDetailsConfig;
55 }
56
57 String selectedPreferenceKey = null;
58
59 ListComponent biocaseProviderList;
60 Abcd206ImportConfigurator abcdImportConfigurator;
61
62 String[][] labelAndValues;
63
64 /*
65 *
66 */
67 public DatabasePreferencesPage(String pageName) {
68 super(pageName);
69 this.preferedNomenclaturalCode = PreferencesUtil.setPreferredNomenclaturalCode(null, false);
70 this.config = PreferencesUtil.setPreferredNameDetailsConfiguration( false);
71 if (config == null){
72 config = new NameDetailsConfigurator(false);
73 }
74
75
76 }
77
78
79 protected IPreferenceStore doGetPreferenceStore() {
80 return PreferencesUtil.getPreferenceStore();
81 }
82
83 /**
84 * @return
85 */
86 private String[][] getLabelAndValues() {
87 List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
88 .getSupportedCodes();
89 labelAndValues = new String[supportedCodes.size()][2];
90 for (int i = 0; i < supportedCodes.size(); i++) {
91 labelAndValues[i][0] = NomenclaturalCodeHelper
92 .getDescription(supportedCodes.get(i));
93 labelAndValues[i][1] = PreferencesUtil
94 .getPreferenceKey(supportedCodes.get(i));
95 }
96 return labelAndValues;
97 }
98
99
100
101
102 public void createNomenclaturalCodeTab(Composite parent){
103
104 Combo nomenclaturalCodeCombo;
105 Label nomenclaturalCodeLabel;
106
107 composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
108 nomenclaturalCodeCombo = new Combo(composite, SWT.DROP_DOWN);
109
110 List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
111 .getSupportedCodes();
112 for (NomenclaturalCode code: supportedCodes) {
113 nomenclaturalCodeCombo.add(NomenclaturalCodeHelper
114 .getDescription(code));
115
116 }
117 nomenclaturalCodeCombo.select(0);
118 getLabelAndValues();
119 //get the actual nomenclatural code and set it as selection: doGetPreferenceStore().getString(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY);
120 nomenclaturalCodeCombo.addSelectionListener(new SelectionAdapter() {
121 @Override
122 public void widgetSelected(SelectionEvent evt) {
123
124 String name = nomenclaturalCodeCombo.getText();
125
126 for (String[] labelAndValue: labelAndValues){
127 if (labelAndValue[0].equals(name)){
128 selectedPreferenceKey = labelAndValue[1];
129 }
130 }
131
132
133 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY, selectedPreferenceKey);
134
135 }
136 });
137 nomenclaturalCodeLabel = new Label(composite, SWT.READ_ONLY);
138
139
140 final Button useLocalPreference = new Button(composite, SWT.CHECK);
141 boolean isUseLocalPreference = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY);
142 useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
143 useLocalPreference.setSelection(isUseLocalPreference);
144 useLocalPreference.addSelectionListener(new SelectionAdapter(){
145 @Override
146 public void widgetSelected(SelectionEvent e) {
147 boolean isUseLocalPreference = useLocalPreference.getSelection();
148 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, isUseLocalPreference);
149 }
150 });
151
152
153
154
155 }
156
157 public void createBiocaseProviderTab(Composite parent){
158 composite = addTab(Messages.DatabasePreferencesPage_Biocase_Provider);
159 GridLayout gridLayout = new GridLayout();
160 gridLayout.numColumns = 2;
161 composite.setLayout(gridLayout);
162 biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE);
163
164 }
165
166 public ListComponent getBiocaseProviderList() {
167 return biocaseProviderList;
168 }
169
170 public void createNameDetailsViewConfigurationTab(Composite parent, NameDetailsConfigurator config){
171 composite = parent;
172
173 composite = addTab(Messages.DatabasePreferencesPage_details_view_configuration);
174 GridLayout gridLayout = new GridLayout();
175 gridLayout.numColumns = 2;
176 composite.setLayout(gridLayout);
177 nameDetailsConfig = new NameDetailsViewComposite(composite, SWT.SCROLL_LINE, config);
178 }
179
180
181 public void createSpecimenOrObservationTab(Composite parent){
182 composite = addTab(Messages.DatabasePreferencesPage_Specimen_Or_Observation);
183
184 final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
185 boolean isShowCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
186 showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
187 showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
188 showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
189 @Override
190 public void widgetSelected(SelectionEvent e) {
191 boolean isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
192 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, isShowCollectingAreaInGeneralSection);
193 }
194 });
195
196 final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
197 boolean isDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS);
198 determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
199 determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
200 determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
201 @Override
202 public void widgetSelected(SelectionEvent e) {
203 boolean isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
204 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS, isDeterminationOnlyForFieldUnits);
205 }
206 });
207
208 final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
209 boolean isShowTaxonAssociation = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS);
210 showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
211 showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
212 showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
213 @Override
214 public void widgetSelected(SelectionEvent e) {
215 boolean isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
216 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS, isShowTaxonAssociation);
217 }
218 });
219
220 final Button showLifeFormButton = new Button(composite, SWT.CHECK);
221 boolean isShowLifeForm = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_LIFE_FORM);
222 showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
223 showLifeFormButton.setSelection(isShowLifeForm);
224 showLifeFormButton.addSelectionListener(new SelectionAdapter(){
225 @Override
226 public void widgetSelected(SelectionEvent e) {
227 boolean isShowLifeForm = showLifeFormButton.getSelection();
228 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_LIFE_FORM, isShowLifeForm);
229 }
230 });
231
232
233
234 }
235
236 /**
237 * {@inheritDoc}
238 */
239 @Override
240 public boolean canFlipToNextPage() {
241 // TODO Auto-generated method stub
242 return false;
243 }
244
245
246
247 /**
248 * {@inheritDoc}
249 */
250 @Override
251 public String getName() {
252 // TODO Auto-generated method stub
253 return null;
254 }
255
256
257
258 /**
259 * {@inheritDoc}
260 */
261 @Override
262 public IWizardPage getNextPage() {
263 // TODO Auto-generated method stub
264 return null;
265 }
266
267
268
269 /**
270 * {@inheritDoc}
271 */
272 @Override
273 public IWizardPage getPreviousPage() {
274 // TODO Auto-generated method stub
275 return null;
276 }
277
278
279
280 /**
281 * {@inheritDoc}
282 */
283 @Override
284 public IWizard getWizard() {
285 // TODO Auto-generated method stub
286 return null;
287 }
288
289
290
291 /**
292 * {@inheritDoc}
293 */
294 @Override
295 public boolean isPageComplete() {
296
297 return true;
298 }
299
300
301
302 /**
303 * {@inheritDoc}
304 */
305 @Override
306 public void setPreviousPage(IWizardPage page) {
307 // TODO Auto-generated method stub
308
309 }
310
311
312
313 /**
314 * {@inheritDoc}
315 */
316 @Override
317 public void setWizard(IWizard newWizard) {
318 // TODO Auto-generated method stub
319
320 }
321
322 /**
323 * {@inheritDoc}
324 */
325 @Override
326 public void createControl(Composite parent) {
327 createNameDetailsViewConfigurationTab(parent, config);
328 createNomenclaturalCodeTab(parent);
329
330 createSpecimenOrObservationTab(parent);
331 createBiocaseProviderTab(parent);
332 setControl(parent);
333 }
334
335 /**
336 * @return
337 */
338 public NameDetailsConfigurator getConfig() {
339 return config;
340 }
341
342 /**
343 *
344 */
345 public Abcd206ImportConfigurator getAbcdImportConfig() {
346 return abcdImportConfigurator;
347
348 }
349
350 /**
351 * @return
352 */
353 public void createAbcdImportConfig() {
354 this.abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
355 this.abcdImportConfigurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
356 this.abcdImportConfigurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
357 //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
358 this.abcdImportConfigurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
359 this.abcdImportConfigurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
360 // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
361 this.abcdImportConfigurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
362 this.abcdImportConfigurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
363 this.abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
364 this.abcdImportConfigurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
365 this.abcdImportConfigurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
366 this.abcdImportConfigurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
367 this.abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
368 this.abcdImportConfigurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
369 this.abcdImportConfigurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
370
371 }
372
373
374
375
376
377
378
379 }