2 * Copyright (C) 2016 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
.databaseAdmin
.wizard
;
11 import java
.util
.List
;
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
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.layout
.GridData
;
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
;
26 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
27 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
28 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
29 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
30 import eu
.etaxonomy
.taxeditor
.databaseAdmin
.preferencePage
.ListComponent
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
33 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
34 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
35 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
42 public class DatabasePreferencesPage
extends AbstractPreferenceWizard
implements IWizardPage
{
44 CdmPreference preferedNomenclaturalCode
;
45 NameDetailsConfigurator config
;
46 CdmPreference isRedListPreference
;
47 CdmPreference determinationOnlyForFieldUnitsPreference
;
48 CdmPreference showCollectingAreaInGeneralSectionPreference
;
49 CdmPreference showTaxonAssociationsPreference
;
50 CdmPreference setPublishFlagAsDefault
;
52 boolean isSimpleDetailsViewActivated
;
55 NameDetailsViewComposite nameDetailsConfig
;
56 protected NameDetailsViewComposite
getNameDetailsConfig() {
57 return nameDetailsConfig
;
60 String selectedPreferenceKey
= null;
62 ListComponent biocaseProviderList
;
63 Abcd206ImportConfigurator abcdImportConfigurator
;
65 String
[][] labelAndValues
;
70 public DatabasePreferencesPage(String pageName
) {
72 this.preferedNomenclaturalCode
= PreferencesUtil
.setPreferredNomenclaturalCode(null, false);
73 this.config
= PreferencesUtil
.setPreferredNameDetailsConfiguration( false);
75 config
= new NameDetailsConfigurator(false);
82 protected IPreferenceStore
doGetPreferenceStore() {
83 return PreferencesUtil
.getPreferenceStore();
89 private String
[][] getLabelAndValues() {
90 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
92 labelAndValues
= new String
[supportedCodes
.size()][2];
93 for (int i
= 0; i
< supportedCodes
.size(); i
++) {
94 labelAndValues
[i
][0] = NomenclaturalCodeHelper
95 .getDescription(supportedCodes
.get(i
));
96 labelAndValues
[i
][1] = PreferencesUtil
97 .getPreferenceKey(supportedCodes
.get(i
));
99 return labelAndValues
;
105 public void createNomenclaturalCodeTab(Composite parent
){
107 Combo nomenclaturalCodeCombo
;
108 Label nomenclaturalCodeLabel
;
110 composite
= addTab(Messages
.DatabasePreferencesPage_Define_Default_NomenclaturalCode
);
111 nomenclaturalCodeCombo
= new Combo(composite
, SWT
.DROP_DOWN
);
113 List
<NomenclaturalCode
> supportedCodes
= NomenclaturalCodeHelper
114 .getSupportedCodes();
115 for (NomenclaturalCode code
: supportedCodes
) {
116 nomenclaturalCodeCombo
.add(NomenclaturalCodeHelper
117 .getDescription(code
));
120 nomenclaturalCodeCombo
.select(0);
122 //get the actual nomenclatural code and set it as selection: doGetPreferenceStore().getString(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY);
123 nomenclaturalCodeCombo
.addSelectionListener(new SelectionAdapter() {
125 public void widgetSelected(SelectionEvent evt
) {
127 String name
= nomenclaturalCodeCombo
.getText();
129 for (String
[] labelAndValue
: labelAndValues
){
130 if (labelAndValue
[0].equals(name
)){
131 selectedPreferenceKey
= labelAndValue
[1];
136 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.CDM_NOMENCLATURAL_CODE_KEY
, selectedPreferenceKey
);
140 nomenclaturalCodeLabel
= new Label(composite
, SWT
.READ_ONLY
);
143 final Button useLocalPreference
= new Button(composite
, SWT
.CHECK
);
144 boolean isUseLocalPreference
= PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
);
145 useLocalPreference
.setText(Messages
.DatabasePreferencesPage_UseLocalPreferences
);
146 useLocalPreference
.setSelection(isUseLocalPreference
);
147 useLocalPreference
.addSelectionListener(new SelectionAdapter(){
149 public void widgetSelected(SelectionEvent e
) {
150 boolean isUseLocalPreference
= useLocalPreference
.getSelection();
151 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
, isUseLocalPreference
);
159 public void createSetPublishFlagTab(Composite parent
){
160 composite
= addTab(Messages
.DatabasePreferencesPage_SetPublishFlag
);
161 GridLayout gridLayout
= new GridLayout();
162 gridLayout
.numColumns
= 2;
163 composite
.setLayout(gridLayout
);
164 //radio buttons for set publish as default, set not publish as default and inherit from parent
169 public void createBiocaseProviderTab(Composite parent
){
170 composite
= addTab(Messages
.DatabasePreferencesPage_Biocase_Provider
);
171 GridLayout gridLayout
= new GridLayout();
172 gridLayout
.numColumns
= 2;
173 composite
.setLayout(gridLayout
);
174 biocaseProviderList
= new ListComponent(composite
, SWT
.SCROLL_LINE
);
178 public ListComponent
getBiocaseProviderList() {
179 return biocaseProviderList
;
182 public void createNameDetailsViewConfigurationTab(Composite parent
, NameDetailsConfigurator config
){
184 composite
= addTab(Messages
.DatabasePreferencesPage_details_view_configuration
);
185 GridLayout gridLayout
= new GridLayout();
186 gridLayout
.numColumns
= 1;
188 composite
.setLayout(gridLayout
);
189 nameDetailsConfig
= new NameDetailsViewComposite(composite
, SWT
.SCROLL_LINE
, config
);
195 public void createSpecimenOrObservationTab(Composite parent
){
196 composite
= addTab(Messages
.DatabasePreferencesPage_Specimen_Or_Observation
);
198 final Button showCollectingAreaInGeneralSectionButton
= new Button(composite
, SWT
.CHECK
);
199 CdmPreference isShowCollectingAreaInGeneralSection
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowCollectingAreasInGeneralSection
);
200 if (isShowCollectingAreaInGeneralSection
== null){
201 isShowCollectingAreaInGeneralSection
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowCollectingAreasInGeneralSection
, Boolean
.toString(false));
203 showCollectingAreaInGeneralSectionButton
.setText(Messages
.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section
);
205 showCollectingAreaInGeneralSectionButton
.setSelection(Boolean
.valueOf(isShowCollectingAreaInGeneralSection
.getValue()));
206 showCollectingAreaInGeneralSectionButton
.addSelectionListener(new SelectionAdapter(){
208 public void widgetSelected(SelectionEvent e
) {
209 boolean isShowCollectingAreaInGeneralSection
= showCollectingAreaInGeneralSectionButton
.getSelection();
210 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION
, isShowCollectingAreaInGeneralSection
);
214 final Button determinationOnlyForFieldUnitsButton
= new Button(composite
, SWT
.CHECK
);
215 // boolean isDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS);
216 CdmPreference isDeterminationOnlyForFieldUnits
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DeterminationOnlyForFieldUnits
);
217 if (isDeterminationOnlyForFieldUnits
== null){
218 isDeterminationOnlyForFieldUnits
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.DeterminationOnlyForFieldUnits
, Boolean
.toString(false));
220 determinationOnlyForFieldUnitsButton
.setText(Messages
.DatabasePreferncesPage_Determination_only_for_field_unnits
);
222 determinationOnlyForFieldUnitsButton
.setSelection(Boolean
.valueOf(isDeterminationOnlyForFieldUnits
.getValue()));
223 determinationOnlyForFieldUnitsButton
.addSelectionListener(new SelectionAdapter(){
225 public void widgetSelected(SelectionEvent e
) {
226 boolean isDeterminationOnlyForFieldUnits
= determinationOnlyForFieldUnitsButton
.getSelection();
227 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DETERMINATION_ONLY_FOR_FIELD_UNITS
, isDeterminationOnlyForFieldUnits
);
231 final Button showTaxonAssociationButton
= new Button(composite
, SWT
.CHECK
);
232 CdmPreference isShowTaxonAssociation
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowTaxonAssociations
);
233 if (isShowTaxonAssociation
== null){
234 isShowTaxonAssociation
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowTaxonAssociations
, Boolean
.toString(false));
236 showTaxonAssociationButton
.setText(Messages
.DatabasePreferncesPage_Taxon_Associations
);
238 showTaxonAssociationButton
.setSelection(Boolean
.valueOf(isShowTaxonAssociation
.getValue()));
239 showTaxonAssociationButton
.addSelectionListener(new SelectionAdapter(){
241 public void widgetSelected(SelectionEvent e
) {
242 boolean isShowTaxonAssociation
= showTaxonAssociationButton
.getSelection();
243 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.SHOW_TAXON_ASSOCIATIONS
, isShowTaxonAssociation
);
247 final Button showLifeFormButton
= new Button(composite
, SWT
.CHECK
);
248 CdmPreference isShowLifeForm
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowLifeForm
);
249 if (isShowLifeForm
== null){
250 isShowLifeForm
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowLifeForm
, Boolean
.toString(false));
253 showLifeFormButton
.setText(Messages
.DatabasePreferncesPage_Life_Form
);
254 showLifeFormButton
.setSelection(Boolean
.valueOf(isShowLifeForm
.getValue()));
255 showLifeFormButton
.addSelectionListener(new SelectionAdapter(){
257 public void widgetSelected(SelectionEvent e
) {
258 boolean isShowLifeForm
= showLifeFormButton
.getSelection();
259 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.SHOW_LIFE_FORM
, isShowLifeForm
);
263 // Composite useLocalComp = new Composite(composite, SWT.NONE);
266 final Button useLocalPreference
= new Button(composite
, SWT
.CHECK
);
267 boolean isUseLocalPreference
= isShowTaxonAssociation
.isAllowOverride();
268 useLocalPreference
.setText(Messages
.DatabasePreferencesPage_UseLocalPreferences
);
269 GridData gridData
= new GridData(SWT
.FILL
, SWT
.BOTTOM
, false, false);
270 gridData
.verticalIndent
= 10;
271 useLocalPreference
.setLayoutData(gridData
);
273 useLocalPreference
.setSelection(isUseLocalPreference
);
274 useLocalPreference
.addSelectionListener(new SelectionAdapter(){
276 public void widgetSelected(SelectionEvent e
) {
277 boolean isUseLocalPreference
= useLocalPreference
.getSelection();
278 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.ALLOW_OVERRIDE_SPECIMEN_PREF
, isUseLocalPreference
);
290 public boolean canFlipToNextPage() {
291 // TODO Auto-generated method stub
301 public String
getName() {
302 // TODO Auto-generated method stub
312 public IWizardPage
getNextPage() {
313 // TODO Auto-generated method stub
323 public IWizardPage
getPreviousPage() {
324 // TODO Auto-generated method stub
334 public IWizard
getWizard() {
335 // TODO Auto-generated method stub
345 public boolean isPageComplete() {
356 public void setPreviousPage(IWizardPage page
) {
357 // TODO Auto-generated method stub
367 public void setWizard(IWizard newWizard
) {
368 // TODO Auto-generated method stub
376 public void createControl(Composite parent
) {
377 createNameDetailsViewConfigurationTab(parent
, config
);
378 createNomenclaturalCodeTab(parent
);
380 createSpecimenOrObservationTab(parent
);
381 createBiocaseProviderTab(parent
);
388 public NameDetailsConfigurator
getConfig() {
395 public Abcd206ImportConfigurator
getAbcdImportConfig() {
396 return abcdImportConfigurator
;
403 public void createAbcdImportConfig() {
404 this.abcdImportConfigurator
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS
));
405 this.abcdImportConfigurator
.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN
));
406 this.abcdImportConfigurator
.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS
));
407 //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
408 this.abcdImportConfigurator
.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS
));
409 this.abcdImportConfigurator
.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES
));
410 // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
411 this.abcdImportConfigurator
.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS
));
412 this.abcdImportConfigurator
.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP
));
413 this.abcdImportConfigurator
.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN
));
414 this.abcdImportConfigurator
.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER
));
415 this.abcdImportConfigurator
.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE
));
416 this.abcdImportConfigurator
.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER
));
417 this.abcdImportConfigurator
.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION
));
418 this.abcdImportConfigurator
.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS
));
419 this.abcdImportConfigurator
.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys
.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE
));