2 * Copyright (C) 2018 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
.preferencePage
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.custom
.CLabel
;
13 import org
.eclipse
.swt
.events
.SelectionAdapter
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Combo
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
23 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
25 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
27 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
28 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
29 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
30 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 public class AbcdImportPreference
extends CdmPreferencePage
implements IE4AdminPreferencePage
, SelectionListener
{
43 private Abcd206ImportConfigurator configurator
;
45 private Combo nomenclaturalCodeSelectionCombo
;
47 private boolean allowOverride
= true;
48 private CdmPreference preference
= null;
51 protected Control
createContents(Composite parent
) {
52 final Composite composite
= new Composite(parent
, SWT
.NULL
);
54 GridLayout gridLayout
= new GridLayout();
55 composite
.setLayout(gridLayout
);
56 configurator
= Abcd206ImportConfigurator
.NewInstance(null,null);
57 ICdmRepository controller
;
58 controller
= CdmStore
.getCurrentApplicationConfiguration();
59 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
);
61 if (controller
== null){
64 preference
= controller
.getPreferenceService().find(key
);
66 if (preference
!= null ){
67 allowOverride
= preference
.isAllowOverride();
69 preference
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AbcdImportConfig
, configurator
.toString());
72 if (preference
!= null){
74 String configString
= preference
.getValue();
75 String
[] configArray
= configString
.split(";"); //$NON-NLS-1$
77 for (String configItem
: configArray
){
78 String
[] keyValue
= configItem
.split(":"); //$NON-NLS-1$
79 if(keyValue
.length
==2){
80 String keyString
= keyValue
[0];
81 String valueString
= keyValue
[1];
82 if (keyString
.equals("ignoreImportOfExistingSpecimen")){ //$NON-NLS-1$
83 configurator
.setIgnoreImportOfExistingSpecimen(Boolean
.valueOf(valueString
));
84 }else if (keyString
.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){ //$NON-NLS-1$
85 configurator
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean
.valueOf(valueString
));
86 }else if (keyString
.equals("reuseExistingTaxaWhenPossible")){ //$NON-NLS-1$
87 configurator
.setReuseExistingTaxaWhenPossible(Boolean
.valueOf(valueString
));
88 }else if (keyString
.equals("ignoreAuthorship")){ //$NON-NLS-1$
89 configurator
.setIgnoreAuthorship(Boolean
.valueOf(valueString
));
90 }else if (keyString
.equals("addMediaAsMediaSpecimen")){ //$NON-NLS-1$
91 configurator
.setAddMediaAsMediaSpecimen(Boolean
.valueOf(valueString
));
92 }else if (keyString
.equals("reuseExistingMetaData")){ //$NON-NLS-1$
93 configurator
.setReuseExistingMetaData(Boolean
.valueOf(valueString
));
94 }else if (keyString
.equals("reuseExistingDescriptiveGroups")){ //$NON-NLS-1$
95 configurator
.setReuseExistingDescriptiveGroups(Boolean
.valueOf(valueString
));
96 }else if (keyString
.equals("allowReuseOtherClassifications")){ //$NON-NLS-1$
97 configurator
.setAllowReuseOtherClassifications(Boolean
.valueOf(valueString
));
98 }else if (keyString
.equals("deduplicateReferences")){ //$NON-NLS-1$
99 configurator
.setDeduplicateReferences(Boolean
.valueOf(valueString
));
100 }else if (keyString
.equals("deduplicateClassifications")){ //$NON-NLS-1$
101 configurator
.setDeduplicateClassifications(Boolean
.valueOf(valueString
));
102 }else if (keyString
.equals("moveNewTaxaToDefaultClassification")){ //$NON-NLS-1$
103 configurator
.setMoveNewTaxaToDefaultClassification(Boolean
.valueOf(valueString
));
104 }else if (keyString
.equals("mapUnitIdToCatalogNumber")){ //$NON-NLS-1$
105 configurator
.setMapUnitIdToCatalogNumber(Boolean
.valueOf(valueString
));
106 }else if (keyString
.equals("mapUnitIdToAccessionNumber")){ //$NON-NLS-1$
107 configurator
.setMapUnitIdToAccessionNumber(Boolean
.valueOf(valueString
));
108 }else if (keyString
.equals("mapUnitIdToBarcode")){ //$NON-NLS-1$
109 configurator
.setMapUnitIdToBarcode(Boolean
.valueOf(valueString
));
110 }else if (keyString
.equals("overwriteExistingSpecimens")){ //$NON-NLS-1$
111 configurator
.setOverwriteExistingSpecimens(Boolean
.valueOf(valueString
));
112 }else if (keyString
.equals("nomenclaturalCode")){ //$NON-NLS-1$
113 configurator
.setNomenclaturalCode(NomenclaturalCode
.fromString(valueString
));
114 }else if (keyString
.equals("getSiblings")){ //$NON-NLS-1$
115 configurator
.setGetSiblings(Boolean
.valueOf(valueString
));
116 }else if (keyString
.equals("removeCountryFromLocalityText")){ //$NON-NLS-1$
117 configurator
.setRemoveCountryFromLocalityText(Boolean
.valueOf(valueString
));
126 //configurator = PreferencesUtil.getAbcdImportConfigurationPreference();
127 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
128 description
.setText(Messages
.AbcdImportPreference_description
);
129 Button checkBoxMediaSpecimen
= new Button(composite
, SWT
.CHECK
);
130 checkBoxMediaSpecimen
.setSelection(configurator
.isAddMediaAsMediaSpecimen());
131 checkBoxMediaSpecimen
.setText(Messages
.AbcdImportPreference_media_as_mediaSpecimen
);
132 checkBoxMediaSpecimen
133 .setToolTipText(Messages
.AbcdImportPreference_media_as_subUnit
);
134 checkBoxMediaSpecimen
.addSelectionListener(new SelectionAdapter() {
136 public void widgetSelected(SelectionEvent e
) {
137 configurator
.setAddMediaAsMediaSpecimen(!configurator
.isAddMediaAsMediaSpecimen());
142 Button checkBoxIgnoreExisting
= new Button(composite
, SWT
.CHECK
);
143 checkBoxIgnoreExisting
.setSelection(configurator
.isIgnoreImportOfExistingSpecimen());
144 checkBoxIgnoreExisting
.setText(Messages
.AbcdImportPreference_not_import_existing_specimen
);
145 checkBoxIgnoreExisting
146 .setToolTipText(Messages
.AbcdImportPreference_not_import_existing_specimen_tooltip
);
147 checkBoxIgnoreExisting
.addSelectionListener(new SelectionAdapter() {
149 public void widgetSelected(SelectionEvent e
) {
150 configurator
.setIgnoreImportOfExistingSpecimen(!configurator
.isIgnoreImportOfExistingSpecimen());
155 Button checkBoxIgnoreAuthorship
= new Button(composite
, SWT
.CHECK
);
156 checkBoxIgnoreAuthorship
.setSelection(configurator
.isIgnoreAuthorship());
157 checkBoxIgnoreAuthorship
.setText(Messages
.AbcdImportPreference_ignore_author
);
158 checkBoxIgnoreAuthorship
159 .setToolTipText(Messages
.AbcdImportPreference_ignore_author_tooltip
);
160 checkBoxIgnoreAuthorship
.addSelectionListener(new SelectionAdapter() {
162 public void widgetSelected(SelectionEvent e
) {
163 configurator
.setIgnoreAuthorship(!configurator
.isIgnoreAuthorship());
168 Button checkBoxMapUnitIdToCatalogNumber
= new Button(composite
, SWT
.CHECK
);
169 checkBoxMapUnitIdToCatalogNumber
.setSelection(configurator
.isMapUnitIdToCatalogNumber());
170 checkBoxMapUnitIdToCatalogNumber
.setText(Messages
.AbcdImportPreference_map_unit_nr_catalog_number
);
171 checkBoxMapUnitIdToCatalogNumber
172 .setToolTipText(Messages
.AbcdImportPreference_map_unit_number_catalog_number_tooltip
);
173 checkBoxMapUnitIdToCatalogNumber
.addSelectionListener(new SelectionAdapter() {
175 public void widgetSelected(SelectionEvent e
) {
176 configurator
.setMapUnitIdToCatalogNumber(!configurator
.isMapUnitIdToCatalogNumber());
180 //TODO: only one of the mappings can be checked!
181 Button checkBoxMapUnitIdToAccessionNumber
= new Button(composite
, SWT
.CHECK
);
182 checkBoxMapUnitIdToAccessionNumber
.setSelection(configurator
.isMapUnitIdToAccessionNumber());
183 checkBoxMapUnitIdToAccessionNumber
.setText(Messages
.AbcdImportPreference_map_unit_number_to_accession_number
);
184 checkBoxMapUnitIdToAccessionNumber
185 .setToolTipText(Messages
.AbcdImportPreference_map_unit_number_accession_number_tooltip
);
186 checkBoxMapUnitIdToAccessionNumber
.addSelectionListener(new SelectionAdapter() {
188 public void widgetSelected(SelectionEvent e
) {
189 configurator
.setMapUnitIdToAccessionNumber(!configurator
.isMapUnitIdToAccessionNumber());
194 Button checkBoxMapUnitIdToBarcode
= new Button(composite
, SWT
.CHECK
);
195 checkBoxMapUnitIdToBarcode
.setSelection(configurator
.isMapUnitIdToBarcode());
196 checkBoxMapUnitIdToBarcode
.setText(Messages
.AbcdImportPreference_map_unit_number_barcode
);
197 checkBoxMapUnitIdToBarcode
198 .setToolTipText(Messages
.AbcdImportPreference_map_unit_number_barcode_tooltip
);
199 checkBoxMapUnitIdToBarcode
.addSelectionListener(new SelectionAdapter() {
201 public void widgetSelected(SelectionEvent e
) {
202 configurator
.setMapUnitIdToBarcode(!configurator
.isMapUnitIdToBarcode());
207 Button checkBoxRemoveCountry
= new Button(composite
, SWT
.CHECK
);
208 checkBoxRemoveCountry
.setSelection(configurator
.isRemoveCountryFromLocalityText());
209 checkBoxRemoveCountry
.setText(Messages
.AbcdImportPreference_remove_country_from_locality
);
210 checkBoxRemoveCountry
211 .setToolTipText(Messages
.AbcdImportPreference_remove_country_from_locality_tooltip
);
212 checkBoxRemoveCountry
.addSelectionListener(new SelectionAdapter() {
214 public void widgetSelected(SelectionEvent e
) {
215 configurator
.setRemoveCountryFromLocalityText(!configurator
.isRemoveCountryFromLocalityText());
220 Button checkBoxMoveToDefaultClassification
= new Button(composite
, SWT
.CHECK
);
221 checkBoxMoveToDefaultClassification
.setSelection(configurator
.isMoveNewTaxaToDefaultClassification());
222 checkBoxMoveToDefaultClassification
.setText(Messages
.AbcdImportPreference_create_new_classification_new_taxa
);
223 checkBoxMoveToDefaultClassification
224 .setToolTipText(Messages
.AbcdImportPreference_create_new_classification_new_taxa_tooltip
);
225 checkBoxMoveToDefaultClassification
.addSelectionListener(new SelectionAdapter() {
227 public void widgetSelected(SelectionEvent e
) {
228 configurator
.setMoveNewTaxaToDefaultClassification(!configurator
.isMoveNewTaxaToDefaultClassification());
233 Button checkBoxImportSiblings
= new Button(composite
, SWT
.CHECK
);
234 checkBoxImportSiblings
.setSelection(configurator
.isGetSiblings());
235 checkBoxImportSiblings
.setText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues
);
236 checkBoxImportSiblings
237 .setToolTipText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip
);
238 checkBoxImportSiblings
.addSelectionListener(new SelectionAdapter() {
240 public void widgetSelected(SelectionEvent e
) {
241 configurator
.setGetSiblings(!configurator
.isGetSiblings());
246 Button checkBoxAddIndividualsAssociations
= new Button(composite
, SWT
.CHECK
);
247 checkBoxAddIndividualsAssociations
.setSelection(configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
248 checkBoxAddIndividualsAssociations
.setText(Messages
.AbcdImportPreference_create_Individual_Association
);
249 checkBoxAddIndividualsAssociations
250 .setToolTipText(Messages
.AbcdImportPreference_create_Individual_Association_tooltip
);
251 checkBoxAddIndividualsAssociations
.addSelectionListener(new SelectionAdapter() {
253 public void widgetSelected(SelectionEvent e
) {
254 configurator
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
259 Button checkBoxReuseDescriptiveGroups
= new Button(composite
, SWT
.CHECK
);
260 checkBoxReuseDescriptiveGroups
.setSelection(configurator
.isReuseExistingDescriptiveGroups());
261 checkBoxReuseDescriptiveGroups
.setText(Messages
.AbcdImportPreference_reuse_descriptive_group
);
262 checkBoxReuseDescriptiveGroups
263 .setToolTipText(Messages
.AbcdImportPreference_reuse_descriptive_group_tooltip
);
264 checkBoxReuseDescriptiveGroups
.addSelectionListener(new SelectionAdapter() {
266 public void widgetSelected(SelectionEvent e
) {
267 configurator
.setReuseExistingDescriptiveGroups(!configurator
.isReuseExistingDescriptiveGroups());
272 Button checkBoxReuseExistingTaxa
= new Button(composite
, SWT
.CHECK
);
273 checkBoxReuseExistingTaxa
.setSelection(configurator
.isReuseExistingTaxaWhenPossible());
274 checkBoxReuseExistingTaxa
.setText(Messages
.AbcdImportPreference_reuse_existing_taxa
);
275 checkBoxReuseExistingTaxa
276 .setToolTipText(Messages
.AbcdImportPreference_reuse_existing_taxa_tooltip
);
277 checkBoxReuseExistingTaxa
.addSelectionListener(new SelectionAdapter() {
279 public void widgetSelected(SelectionEvent e
) {
280 configurator
.setReuseExistingTaxaWhenPossible(!configurator
.isReuseExistingTaxaWhenPossible());
285 GridData gridData
= new GridData();
286 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
287 gridData
.horizontalIndent
= 5;
288 // classificationSelection.setLayoutData(gridData);
290 nomenclaturalCodeSelectionCombo
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
291 nomenclaturalCodeSelectionCombo
.setLayoutData(gridData
);
292 for(NomenclaturalCode code
: NomenclaturalCode
.values()){
293 nomenclaturalCodeSelectionCombo
.add(code
.getKey());
296 if (configurator
.getNomenclaturalCode() != null){
297 for (String label
: nomenclaturalCodeSelectionCombo
.getItems()){
298 if (label
.equals(configurator
.getNomenclaturalCode().getKey())){
299 nomenclaturalCodeSelectionCombo
.select(index
);
306 // TODO remember last selection
307 nomenclaturalCodeSelectionCombo
.addSelectionListener(this);
308 if (preference
!= null){
309 allowOverride
= preference
.isAllowOverride();
311 Button checkAllowOverride
= new Button(composite
, SWT
.CHECK
);
312 checkAllowOverride
.setSelection(allowOverride
);
313 checkAllowOverride
.setText(Messages
.AbcdImportPreference_allow_override
);
315 .setToolTipText(Messages
.AbcdImportPreference_allow_override_tooltip
);
316 checkAllowOverride
.addSelectionListener(new SelectionAdapter() {
318 public void widgetSelected(SelectionEvent e
) {
319 allowOverride
= !allowOverride
;
328 public void widgetSelected(SelectionEvent e
) {
329 this.configurator
.setNomenclaturalCode(NomenclaturalCode
.getByKey(nomenclaturalCodeSelectionCombo
.getText()));
334 public boolean performOk() {
335 if (preference
== null){
338 if (configurator
!= null){
339 String configString
= configurator
.toString();
341 CdmPreference pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AbcdImportConfig
, configString
);
342 pref
.setAllowOverride(allowOverride
);
344 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
345 if (controller
== null){
348 IPreferenceService service
= controller
.getPreferenceService();
350 PreferencesUtil
.updateDBPreferences();
360 public void widgetDefaultSelected(SelectionEvent e
) {
361 // TODO Auto-generated method stub
365 // private void createAbcdImportConfig() {
366 // this.configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
367 // this.configurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
368 // this.configurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
369 // //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
370 // this.configurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
371 // this.configurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
372 // // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
373 // this.configurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
374 // this.configurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
375 // this.configurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
376 // this.configurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
377 // this.configurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
378 // this.configurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
379 // this.configurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
380 // this.configurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
381 // this.configurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
382 // this.configurator.setNomenclaturalCode(PreferencesUtil.getPreferredNomenclaturalCode(doGetPreferenceStore().getString(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));