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
.preference
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.custom
.CLabel
;
15 import org
.eclipse
.swt
.events
.SelectionAdapter
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.events
.SelectionListener
;
18 import org
.eclipse
.swt
.layout
.GridData
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Button
;
21 import org
.eclipse
.swt
.widgets
.Combo
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Control
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
27 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
28 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
29 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
30 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
31 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
32 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
33 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
34 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
35 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
43 public class AbcdImportPreference
extends CdmPreferencePage
implements IE4PreferencePage
, SelectionListener
{
48 private static final String CATALOGUE_NUMBER
= "Catalogue number";
53 private static final String BARCODE
= "Barcode";
58 private static final String ACCESSION_NUMBER
= "Accession number";
60 protected Abcd206ImportConfigurator configurator
;
62 protected Combo nomenclaturalCodeSelectionCombo
;
64 protected boolean allowOverride
= true;
65 protected boolean override
= true;
66 protected CdmPreference preference
= null;
67 Combo textDNAProviderString
;
68 private Composite composite
;
71 Button checkBoxMediaSpecimen
;
72 Button checkBoxIgnoreExisting
;
73 Button checkBoxIgnoreAuthorship
;
74 Combo checkBoxMapUnitId
;
75 // Button checkBoxMapUnitIdToAccessionNumber;
76 // Button checkBoxMapUnitIdToBarcode;
77 Button checkBoxRemoveCountry
;
78 Button checkBoxMoveToDefaultClassification
;
79 Button checkBoxImportSiblings
;
80 Button checkBoxAddIndividualsAssociations
;
81 Button checkBoxReuseDescriptiveGroups
;
82 Button checkBoxReuseExistingTaxa
;
85 Combo useLocalOrAdmin
;
88 protected Control
createContents(Composite parent
) {
91 if (!isAdminPreference
&& !allowOverride
){
92 Label label
= new Label(parent
, SWT
.NONE
);
93 label
.setText("The CDM settings don't allow to set the abcd import preference locally. If you need to make local settings, please ask an administrator.");
94 this.noDefaultAndApplyButton();
97 composite
= new Composite(parent
, SWT
.NULL
);
98 GridLayout gridLayout
= new GridLayout();
99 composite
.setLayout(gridLayout
);
101 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
102 description
.setText(Messages
.AbcdImportPreference_description
);
103 checkBoxMediaSpecimen
= new Button(composite
, SWT
.CHECK
);
104 checkBoxMediaSpecimen
.setText(Messages
.AbcdImportPreference_media_as_mediaSpecimen
);
105 checkBoxMediaSpecimen
106 .setToolTipText(Messages
.AbcdImportPreference_media_as_subUnit
);
107 checkBoxMediaSpecimen
.addSelectionListener(new SelectionAdapter() {
109 public void widgetSelected(SelectionEvent e
) {
110 configurator
.setAddMediaAsMediaSpecimen(!configurator
.isAddMediaAsMediaSpecimen());
115 checkBoxIgnoreExisting
= new Button(composite
, SWT
.CHECK
);
117 checkBoxIgnoreExisting
.setText(Messages
.AbcdImportPreference_not_import_existing_specimen
);
118 checkBoxIgnoreExisting
119 .setToolTipText(Messages
.AbcdImportPreference_not_import_existing_specimen_tooltip
);
120 checkBoxIgnoreExisting
.addSelectionListener(new SelectionAdapter() {
122 public void widgetSelected(SelectionEvent e
) {
123 configurator
.setIgnoreImportOfExistingSpecimen(!configurator
.isIgnoreImportOfExistingSpecimen());
128 checkBoxIgnoreAuthorship
= new Button(composite
, SWT
.CHECK
);
130 checkBoxIgnoreAuthorship
.setText(Messages
.AbcdImportPreference_ignore_author
);
131 checkBoxIgnoreAuthorship
132 .setToolTipText(Messages
.AbcdImportPreference_ignore_author_tooltip
);
133 checkBoxIgnoreAuthorship
.addSelectionListener(new SelectionAdapter() {
135 public void widgetSelected(SelectionEvent e
) {
136 configurator
.setIgnoreAuthorship(!configurator
.isIgnoreAuthorship());
142 GridData gridData
= new GridData();
143 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
144 gridData
.horizontalIndent
= 5;
145 gridData
.minimumWidth
=100;
146 // classificationSelection.setLayoutData(gridData);
147 Label unitIdLabel
= new Label(composite
, SWT
.NONE
);
148 unitIdLabel
.setText(Messages
.AbcdImportPreference_map_unit_nr_catalog_number
);
149 checkBoxMapUnitId
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
150 checkBoxMapUnitId
.setLayoutData(gridData
);
151 checkBoxMapUnitId
.add(ACCESSION_NUMBER
);
152 checkBoxMapUnitId
.add(BARCODE
);
153 checkBoxMapUnitId
.add(CATALOGUE_NUMBER
);
155 .setToolTipText(Messages
.AbcdImportPreference_map_unit_number_catalog_number_tooltip
);
156 checkBoxMapUnitId
.addSelectionListener(this);
158 checkBoxRemoveCountry
= new Button(composite
, SWT
.CHECK
);
160 checkBoxRemoveCountry
.setText(Messages
.AbcdImportPreference_remove_country_from_locality
);
161 checkBoxRemoveCountry
162 .setToolTipText(Messages
.AbcdImportPreference_remove_country_from_locality_tooltip
);
163 checkBoxRemoveCountry
.addSelectionListener(new SelectionAdapter() {
165 public void widgetSelected(SelectionEvent e
) {
166 configurator
.setRemoveCountryFromLocalityText(!configurator
.isRemoveCountryFromLocalityText());
171 checkBoxMoveToDefaultClassification
= new Button(composite
, SWT
.CHECK
);
172 checkBoxMoveToDefaultClassification
.setSelection(configurator
.isMoveNewTaxaToDefaultClassification());
173 checkBoxMoveToDefaultClassification
.setText(Messages
.AbcdImportPreference_create_new_classification_new_taxa
);
174 checkBoxMoveToDefaultClassification
175 .setToolTipText(Messages
.AbcdImportPreference_create_new_classification_new_taxa_tooltip
);
176 checkBoxMoveToDefaultClassification
.addSelectionListener(new SelectionAdapter() {
178 public void widgetSelected(SelectionEvent e
) {
179 configurator
.setMoveNewTaxaToDefaultClassification(!configurator
.isMoveNewTaxaToDefaultClassification());
184 checkBoxImportSiblings
= new Button(composite
, SWT
.CHECK
);
186 checkBoxImportSiblings
.setText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues
);
187 checkBoxImportSiblings
188 .setToolTipText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip
);
189 checkBoxImportSiblings
.addSelectionListener(new SelectionAdapter() {
191 public void widgetSelected(SelectionEvent e
) {
192 configurator
.setGetSiblings(!configurator
.isGetSiblings());
197 checkBoxAddIndividualsAssociations
= new Button(composite
, SWT
.CHECK
);
199 checkBoxAddIndividualsAssociations
.setText(Messages
.AbcdImportPreference_create_Individual_Association
);
200 checkBoxAddIndividualsAssociations
201 .setToolTipText(Messages
.AbcdImportPreference_create_Individual_Association_tooltip
);
202 checkBoxAddIndividualsAssociations
.addSelectionListener(new SelectionAdapter() {
204 public void widgetSelected(SelectionEvent e
) {
205 configurator
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
210 checkBoxReuseDescriptiveGroups
= new Button(composite
, SWT
.CHECK
);
212 checkBoxReuseDescriptiveGroups
.setText(Messages
.AbcdImportPreference_reuse_descriptive_group
);
213 checkBoxReuseDescriptiveGroups
214 .setToolTipText(Messages
.AbcdImportPreference_reuse_descriptive_group_tooltip
);
215 checkBoxReuseDescriptiveGroups
.addSelectionListener(new SelectionAdapter() {
217 public void widgetSelected(SelectionEvent e
) {
218 configurator
.setReuseExistingDescriptiveGroups(!configurator
.isReuseExistingDescriptiveGroups());
223 checkBoxReuseExistingTaxa
= new Button(composite
, SWT
.CHECK
);
225 checkBoxReuseExistingTaxa
.setText(Messages
.AbcdImportPreference_reuse_existing_taxa
);
226 checkBoxReuseExistingTaxa
227 .setToolTipText(Messages
.AbcdImportPreference_reuse_existing_taxa_tooltip
);
228 checkBoxReuseExistingTaxa
.addSelectionListener(new SelectionAdapter() {
230 public void widgetSelected(SelectionEvent e
) {
231 configurator
.setReuseExistingTaxaWhenPossible(!configurator
.isReuseExistingTaxaWhenPossible());
236 Label labelRef
= new Label(composite
, SWT
.NONE
);
237 labelRef
.setText("Biocase provider for associated DNA");
238 // new Label(composite, SWT.NONE);
240 textDNAProviderString
= new Combo(composite
, SWT
.BORDER
);
241 CdmPreference biocaseProvider
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.BioCaseProvider
);
242 if (biocaseProvider
!= null){
243 String items
[] = biocaseProvider
.getValue().split(";");
244 textDNAProviderString
.setItems(items
);
248 textDNAProviderString
.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
, TableWrapData
.TOP
, 1, 1));
249 textDNAProviderString
.setEnabled(true);
251 textDNAProviderString
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true, 1, 1));
252 textDNAProviderString
.addSelectionListener(this);
254 // classificationSelection.setLayoutData(gridData);
255 Label nomenclaturalCodeLabel
= new Label(composite
, SWT
.NONE
);
256 nomenclaturalCodeLabel
.setText("Nomenclatural Code");
257 nomenclaturalCodeSelectionCombo
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
258 nomenclaturalCodeSelectionCombo
.setLayoutData(gridData
);
259 nomenclaturalCodeSelectionCombo
.add(" - ");
260 for(NomenclaturalCode code
: NomenclaturalCode
.values()){
261 nomenclaturalCodeSelectionCombo
.add(code
.getKey());
266 // TODO remember last selection
267 nomenclaturalCodeSelectionCombo
.addSelectionListener(this);
268 if (preference
!= null){
269 allowOverride
= preference
.isAllowOverride();
272 useLocalOrAdmin
= new Combo(parent
, SWT
.BORDER
| SWT
.READ_ONLY
);
273 if (!isAdminPreference
){
274 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Default
.getLabel(), 0);
275 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Local
.getLabel(), 1);
278 useLocalOrAdmin
.add(LocalOrDefaultEnum
.AllowOverride
.getLabel(), 0);
279 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Database
.getLabel(), 1);
282 if (!isAdminPreference
){
283 if (override
&& allowOverride
){
284 useLocalOrAdmin
.select(1);
286 useLocalOrAdmin
.select(0);
287 composite
.setEnabled(false);
291 useLocalOrAdmin
.select(0);
293 useLocalOrAdmin
.select(1);
296 useLocalOrAdmin
.addSelectionListener(this);
297 if (!allowOverride
&& !isAdminPreference
){
298 useLocalOrAdmin
.setEnabled(false);
306 public void widgetSelected(SelectionEvent e
) {
307 if (e
.getSource().equals(nomenclaturalCodeSelectionCombo
)){
308 this.configurator
.setNomenclaturalCode(NomenclaturalCode
.getByKey(nomenclaturalCodeSelectionCombo
.getText()));
310 if (e
.getSource().equals(checkBoxMapUnitId
)){
311 String text
= checkBoxMapUnitId
.getText();
312 if (text
.equals(ACCESSION_NUMBER
)){
313 this.configurator
.setMapUnitIdToAccessionNumber(true);
314 this.configurator
.setMapUnitIdToBarcode(false);
315 this.configurator
.setMapUnitIdToCatalogNumber(false);
316 }else if (text
.equals(BARCODE
)){
317 this.configurator
.setMapUnitIdToAccessionNumber(false);
318 this.configurator
.setMapUnitIdToBarcode(true);
319 this.configurator
.setMapUnitIdToCatalogNumber(false);
321 this.configurator
.setMapUnitIdToAccessionNumber(false);
322 this.configurator
.setMapUnitIdToBarcode(false);
323 this.configurator
.setMapUnitIdToCatalogNumber(true);
326 if (e
.getSource().equals(useLocalOrAdmin
)){
327 if (useLocalOrAdmin
.getText().equals(LocalOrDefaultEnum
.Default
.getLabel()) || useLocalOrAdmin
.getText().equals(LocalOrDefaultEnum
.Database
.getLabel())){
328 composite
.setEnabled(false);
329 PreferencesUtil
.extractAbcdConfiguratorFromPreferenceString(configurator
, preference
.getValue());
332 if (isAdminPreference
){
333 allowOverride
= false;
338 composite
.setEnabled(true);
339 if (isAdminPreference
){
340 allowOverride
= true;
347 if (e
.getSource().equals(textDNAProviderString
)){
348 String textDnaProvider
= textDNAProviderString
.getText();
350 this.configurator
.setDnaSoure(URI
.create(textDnaProvider
));
351 }catch(IllegalArgumentException iae
){
352 //do not set as dna source
358 // PreferencesUtil.recursiveSetEnabled(composite, override);
364 public boolean performOk() {
368 if (configurator
!= null){
370 configurator
.setDnaSoure(URI
.create(textDNAProviderString
.getText()));
371 }catch(IllegalArgumentException e
){
372 //dna provider is not an uri
374 String configString
= configurator
.toString();
378 PreferencesUtil
.setStringValue(PreferencePredicate
.AbcdImportConfig
.getKey(), configString
);
379 PreferencesUtil
.setBooleanValue( PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), override
);
382 PreferencesUtil
.setBooleanValue( PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), override
);
394 public void widgetDefaultSelected(SelectionEvent e
) {
395 // TODO Auto-generated method stub
400 protected void performDefaults() {
401 configurator
= Abcd206ImportConfigurator
.NewInstance(null,null);
408 public void getValues() {
409 isAdminPreference
= false;
410 configurator
= Abcd206ImportConfigurator
.NewInstance(null,null);
411 ICdmRepository controller
;
412 controller
= CdmStore
.getCurrentApplicationConfiguration();
413 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
);
414 preference
= controller
.getPreferenceService().find(key
);
416 if (preference
!= null ){
417 allowOverride
= preference
.isAllowOverride();
419 preference
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AbcdImportConfig
, configurator
.toString());
422 override
= PreferencesUtil
.getBooleanValue(
423 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(
424 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), true):false;
425 if (allowOverride
&& override
){
426 configurator
= PreferencesUtil
.getLocalAbcdImportConfigurator();
428 PreferencesUtil
.extractAbcdConfiguratorFromPreferenceString(configurator
, preference
.getValue());
432 protected void setSelections(){
433 checkBoxMediaSpecimen
.setSelection(configurator
.isAddMediaAsMediaSpecimen());
434 checkBoxIgnoreExisting
.setSelection(configurator
.isIgnoreImportOfExistingSpecimen());
435 checkBoxIgnoreAuthorship
.setSelection(configurator
.isIgnoreAuthorship());
436 if (configurator
.isMapUnitIdToAccessionNumber()){
437 checkBoxMapUnitId
.select(0);
438 }else if (configurator
.isMapUnitIdToBarcode()){
439 checkBoxMapUnitId
.select(1);
441 checkBoxMapUnitId
.select(2);
445 checkBoxRemoveCountry
.setSelection(configurator
.isRemoveCountryFromLocalityText());
446 checkBoxImportSiblings
.setSelection(configurator
.isGetSiblings());
447 checkBoxAddIndividualsAssociations
.setSelection(configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
448 checkBoxReuseDescriptiveGroups
.setSelection(configurator
.isReuseExistingDescriptiveGroups());
449 checkBoxReuseExistingTaxa
.setSelection(configurator
.isReuseExistingTaxaWhenPossible());
451 textDNAProviderString
.setText(configurator
.getDnaSoure()!= null? configurator
.getDnaSoure().toString():"");
453 if (configurator
.getNomenclaturalCode() != null){
454 for (String label
: nomenclaturalCodeSelectionCombo
.getItems()){
455 if (label
.equals(configurator
.getNomenclaturalCode().getKey())){
456 nomenclaturalCodeSelectionCombo
.select(index
);
461 nomenclaturalCodeSelectionCombo
.select(index
);