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
.jface
.layout
.GridLayoutFactory
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.custom
.CLabel
;
16 import org
.eclipse
.swt
.events
.SelectionAdapter
;
17 import org
.eclipse
.swt
.events
.SelectionEvent
;
18 import org
.eclipse
.swt
.events
.SelectionListener
;
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
.Control
;
25 import org
.eclipse
.swt
.widgets
.Label
;
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
{
45 private static final String CATALOGUE_NUMBER
= "Catalogue number";
47 private static final String BARCODE
= "Barcode";
49 private static final String ACCESSION_NUMBER
= "Accession number";
51 protected Abcd206ImportConfigurator configurator
;
53 protected Combo nomenclaturalCodeSelectionCombo
;
55 protected boolean allowOverride
= true;
56 protected boolean override
= true;
57 protected CdmPreference preference
= null;
58 Combo textDNAProviderString
;
59 private Composite composite
;
62 Button checkBoxMediaSpecimen
;
63 Button checkBoxIgnoreExisting
;
64 Button checkBoxIgnoreAuthorship
;
65 Combo checkBoxMapUnitId
;
66 Button checkBoxRemoveCountry
;
67 Button checkBoxMoveToDefaultClassification
;
68 Button checkBoxImportSiblings
;
69 Button checkBoxAddIndividualsAssociations
;
70 Button checkBoxReuseDescriptiveGroups
;
71 Button checkBoxReuseExistingTaxa
;
74 Combo useLocalOrAdmin
;
77 protected Control
createContents(Composite parent
) {
80 if (!isAdminPreference
&& !allowOverride
){
81 Label label
= new Label(parent
, SWT
.NONE
);
82 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.");
83 this.noDefaultAndApplyButton();
86 composite
= new Composite(parent
, SWT
.NULL
);
87 GridLayout gridLayout
= new GridLayout();
88 composite
.setLayout(gridLayout
);
90 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
91 description
.setText(Messages
.AbcdImportPreference_description
);
92 checkBoxMediaSpecimen
= new Button(composite
, SWT
.CHECK
);
93 checkBoxMediaSpecimen
.setText(Messages
.AbcdImportPreference_media_as_mediaSpecimen
);
95 .setToolTipText(Messages
.AbcdImportPreference_media_as_subUnit
);
96 checkBoxMediaSpecimen
.addSelectionListener(new SelectionAdapter() {
98 public void widgetSelected(SelectionEvent e
) {
99 configurator
.setAddMediaAsMediaSpecimen(!configurator
.isAddMediaAsMediaSpecimen());
104 checkBoxIgnoreExisting
= new Button(composite
, SWT
.CHECK
);
106 checkBoxIgnoreExisting
.setText(Messages
.AbcdImportPreference_not_import_existing_specimen
);
107 checkBoxIgnoreExisting
108 .setToolTipText(Messages
.AbcdImportPreference_not_import_existing_specimen_tooltip
);
109 checkBoxIgnoreExisting
.addSelectionListener(new SelectionAdapter() {
111 public void widgetSelected(SelectionEvent e
) {
112 configurator
.setIgnoreImportOfExistingSpecimen(!configurator
.isIgnoreImportOfExistingSpecimen());
117 checkBoxIgnoreAuthorship
= new Button(composite
, SWT
.CHECK
);
119 checkBoxIgnoreAuthorship
.setText(Messages
.AbcdImportPreference_ignore_author
);
120 checkBoxIgnoreAuthorship
121 .setToolTipText(Messages
.AbcdImportPreference_ignore_author_tooltip
);
122 checkBoxIgnoreAuthorship
.addSelectionListener(new SelectionAdapter() {
124 public void widgetSelected(SelectionEvent e
) {
125 configurator
.setIgnoreAuthorship(!configurator
.isIgnoreAuthorship());
131 GridData gridData
= new GridData();
132 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
133 gridData
.horizontalIndent
= 9;
134 gridData
.minimumWidth
=100;
135 // classificationSelection.setLayoutData(gridData);
136 Label unitIdLabel
= new Label(composite
, SWT
.NONE
);
137 unitIdLabel
.setText(Messages
.AbcdImportPreference_map_unit_nr_catalog_number
);
138 checkBoxMapUnitId
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
139 checkBoxMapUnitId
.setLayoutData(gridData
);
140 checkBoxMapUnitId
.add(ACCESSION_NUMBER
);
141 checkBoxMapUnitId
.add(BARCODE
);
142 checkBoxMapUnitId
.add(CATALOGUE_NUMBER
);
144 .setToolTipText(Messages
.AbcdImportPreference_map_unit_number_catalog_number_tooltip
);
145 checkBoxMapUnitId
.addSelectionListener(this);
147 checkBoxRemoveCountry
= new Button(composite
, SWT
.CHECK
);
149 checkBoxRemoveCountry
.setText(Messages
.AbcdImportPreference_remove_country_from_locality
);
150 checkBoxRemoveCountry
151 .setToolTipText(Messages
.AbcdImportPreference_remove_country_from_locality_tooltip
);
152 checkBoxRemoveCountry
.addSelectionListener(new SelectionAdapter() {
154 public void widgetSelected(SelectionEvent e
) {
155 configurator
.setRemoveCountryFromLocalityText(!configurator
.isRemoveCountryFromLocalityText());
160 checkBoxMoveToDefaultClassification
= new Button(composite
, SWT
.CHECK
);
161 checkBoxMoveToDefaultClassification
.setSelection(configurator
.isMoveNewTaxaToDefaultClassification());
162 checkBoxMoveToDefaultClassification
.setText(Messages
.AbcdImportPreference_create_new_classification_new_taxa
);
163 checkBoxMoveToDefaultClassification
164 .setToolTipText(Messages
.AbcdImportPreference_create_new_classification_new_taxa_tooltip
);
165 checkBoxMoveToDefaultClassification
.addSelectionListener(new SelectionAdapter() {
167 public void widgetSelected(SelectionEvent e
) {
168 configurator
.setMoveNewTaxaToDefaultClassification(!configurator
.isMoveNewTaxaToDefaultClassification());
173 checkBoxImportSiblings
= new Button(composite
, SWT
.CHECK
);
175 checkBoxImportSiblings
.setText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues
);
176 checkBoxImportSiblings
177 .setToolTipText(Messages
.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip
);
178 checkBoxImportSiblings
.addSelectionListener(new SelectionAdapter() {
180 public void widgetSelected(SelectionEvent e
) {
181 configurator
.setGetSiblings(!configurator
.isGetSiblings());
186 checkBoxAddIndividualsAssociations
= new Button(composite
, SWT
.CHECK
);
188 checkBoxAddIndividualsAssociations
.setText(Messages
.AbcdImportPreference_create_Individual_Association
);
189 checkBoxAddIndividualsAssociations
190 .setToolTipText(Messages
.AbcdImportPreference_create_Individual_Association_tooltip
);
191 checkBoxAddIndividualsAssociations
.addSelectionListener(new SelectionAdapter() {
193 public void widgetSelected(SelectionEvent e
) {
194 configurator
.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
199 checkBoxReuseDescriptiveGroups
= new Button(composite
, SWT
.CHECK
);
201 checkBoxReuseDescriptiveGroups
.setText(Messages
.AbcdImportPreference_reuse_descriptive_group
);
202 checkBoxReuseDescriptiveGroups
203 .setToolTipText(Messages
.AbcdImportPreference_reuse_descriptive_group_tooltip
);
204 checkBoxReuseDescriptiveGroups
.addSelectionListener(new SelectionAdapter() {
206 public void widgetSelected(SelectionEvent e
) {
207 configurator
.setReuseExistingDescriptiveGroups(!configurator
.isReuseExistingDescriptiveGroups());
212 checkBoxReuseExistingTaxa
= new Button(composite
, SWT
.CHECK
);
214 checkBoxReuseExistingTaxa
.setText(Messages
.AbcdImportPreference_reuse_existing_taxa
);
215 checkBoxReuseExistingTaxa
216 .setToolTipText(Messages
.AbcdImportPreference_reuse_existing_taxa_tooltip
);
217 checkBoxReuseExistingTaxa
.addSelectionListener(new SelectionAdapter() {
219 public void widgetSelected(SelectionEvent e
) {
220 configurator
.setReuseExistingTaxaWhenPossible(!configurator
.isReuseExistingTaxaWhenPossible());
224 GridData sepGrid
= createTextGridData();
225 Label separator
= new Label(composite
, SWT
.HORIZONTAL
|SWT
.SEPARATOR
);
226 separator
.setLayoutData(sepGrid
);
227 separator
.setVisible(false);
228 Label labelRef
= new Label(composite
, SWT
.NONE
);
229 labelRef
.setText("Biocase provider for associated DNA");
230 textDNAProviderString
= new Combo(composite
, SWT
.BORDER
);
232 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
233 gridData
.horizontalIndent
= 9;
234 gridData
.minimumWidth
=200;
236 textDNAProviderString
.setLayoutData(gridData
);
237 GridLayoutFactory
.fillDefaults();
238 String biocaseProvider
= null;
239 CdmPreference pref
= null;
241 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.BioCaseProvider
);
242 biocaseProvider
= pref
!= null? pref
.getValue():null;
244 if (!isAdminPreference
&& ((pref
!= null && pref
.isAllowOverride()) || pref
== null) ){
245 biocaseProvider
= PreferencesUtil
.getStringValue(PreferencePredicate
.BioCaseProvider
.getKey(), true);
247 if (biocaseProvider
!= null){
248 String items
[] = biocaseProvider
.split(";");
249 textDNAProviderString
.setItems(items
);
252 textDNAProviderString
.setEnabled(true);
253 // textDNAProviderString.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
254 textDNAProviderString
.addSelectionListener(this);
256 Label nomenclaturalCodeLabel
= new Label(composite
, SWT
.NONE
);
257 nomenclaturalCodeLabel
.setText("Nomenclatural Code");
258 nomenclaturalCodeSelectionCombo
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
259 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
260 gridData
.horizontalIndent
= 9;
261 nomenclaturalCodeSelectionCombo
.setLayoutData(gridData
);
262 GridLayoutFactory
.fillDefaults();
263 for(NomenclaturalCode code
: NomenclaturalCode
.values()){
264 nomenclaturalCodeSelectionCombo
.add(code
.getKey());
267 nomenclaturalCodeSelectionCombo
.addSelectionListener(this);
268 if (preference
!= null){
269 allowOverride
= preference
.isAllowOverride();
272 Label sep
= new Label(composite
, SWT
.HORIZONTAL
|SWT
.SEPARATOR
);
273 sep
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, true, false));
274 GridLayoutFactory
.fillDefaults();
275 useLocalOrAdmin
= new Combo(parent
, SWT
.BORDER
| SWT
.READ_ONLY
);
276 if (!isAdminPreference
){
277 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Default
.getLabel(), 0);
278 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Local
.getLabel(), 1);
281 useLocalOrAdmin
.add(LocalOrDefaultEnum
.AllowOverride
.getLabel(), 0);
282 useLocalOrAdmin
.add(LocalOrDefaultEnum
.Database
.getLabel(), 1);
285 if (!isAdminPreference
){
286 if (override
&& allowOverride
){
287 useLocalOrAdmin
.select(1);
289 useLocalOrAdmin
.select(0);
290 composite
.setEnabled(false);
294 useLocalOrAdmin
.select(0);
296 useLocalOrAdmin
.select(1);
299 useLocalOrAdmin
.addSelectionListener(this);
300 if (!allowOverride
&& !isAdminPreference
){
301 useLocalOrAdmin
.setEnabled(false);
303 GridData gridDataLocal
= new GridData();
304 gridDataLocal
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
305 // gridDataLocal.horizontalIndent = 9;
306 gridDataLocal
.minimumWidth
=100;
307 gridDataLocal
.widthHint
= nomenclaturalCodeSelectionCombo
.getBorderWidth();
308 useLocalOrAdmin
.setLayoutData(gridDataLocal
);
309 GridLayoutFactory
.fillDefaults();
316 public void widgetSelected(SelectionEvent e
) {
317 if (e
.getSource().equals(nomenclaturalCodeSelectionCombo
)){
318 this.configurator
.setNomenclaturalCode(NomenclaturalCode
.getByKey(nomenclaturalCodeSelectionCombo
.getText()));
320 if (e
.getSource().equals(checkBoxMapUnitId
)){
321 String text
= checkBoxMapUnitId
.getText();
322 if (text
.equals(ACCESSION_NUMBER
)){
323 this.configurator
.setMapUnitIdToAccessionNumber(true);
324 this.configurator
.setMapUnitIdToBarcode(false);
325 this.configurator
.setMapUnitIdToCatalogNumber(false);
326 }else if (text
.equals(BARCODE
)){
327 this.configurator
.setMapUnitIdToAccessionNumber(false);
328 this.configurator
.setMapUnitIdToBarcode(true);
329 this.configurator
.setMapUnitIdToCatalogNumber(false);
331 this.configurator
.setMapUnitIdToAccessionNumber(false);
332 this.configurator
.setMapUnitIdToBarcode(false);
333 this.configurator
.setMapUnitIdToCatalogNumber(true);
336 if (e
.getSource().equals(useLocalOrAdmin
)){
337 if (useLocalOrAdmin
.getText().equals(LocalOrDefaultEnum
.Default
.getLabel()) || useLocalOrAdmin
.getText().equals(LocalOrDefaultEnum
.Database
.getLabel())){
338 composite
.setEnabled(false);
339 PreferencesUtil
.extractAbcdConfiguratorFromPreferenceString(configurator
, preference
.getValue());
342 if (isAdminPreference
){
343 allowOverride
= false;
348 composite
.setEnabled(true);
349 if (isAdminPreference
){
350 allowOverride
= true;
357 if (e
.getSource().equals(textDNAProviderString
)){
358 String textDnaProvider
= textDNAProviderString
.getText();
360 this.configurator
.setDnaSoure(URI
.create(textDnaProvider
));
361 }catch(IllegalArgumentException iae
){
362 //do not set as dna source
368 // PreferencesUtil.recursiveSetEnabled(composite, override);
374 public boolean performOk() {
378 if (configurator
!= null){
380 configurator
.setDnaSoure(URI
.create(textDNAProviderString
.getText()));
381 }catch(IllegalArgumentException e
){
382 //dna provider is not an uri
384 String configString
= configurator
.toString();
388 PreferencesUtil
.setStringValue(PreferencePredicate
.AbcdImportConfig
.getKey(), configString
);
389 PreferencesUtil
.setBooleanValue( PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), override
);
392 PreferencesUtil
.setBooleanValue( PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), override
);
394 PreferencesUtil
.setStringValue(PreferencePredicate
.AbcdImportConfig
.getKey(), "");
405 public void widgetDefaultSelected(SelectionEvent e
) {
406 // TODO Auto-generated method stub
411 protected void performDefaults() {
412 configurator
= Abcd206ImportConfigurator
.NewInstance(null,null);
413 configurator
.setNomenclaturalCode(PreferencesUtil
.getPreferredNomenclaturalCode());
420 public void getValues() {
421 isAdminPreference
= false;
422 configurator
= Abcd206ImportConfigurator
.NewInstance(null,null);
423 ICdmRepository controller
;
424 controller
= CdmStore
.getCurrentApplicationConfiguration();
425 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
);
426 preference
= controller
.getPreferenceService().find(key
);
428 if (preference
!= null ){
429 allowOverride
= preference
.isAllowOverride();
431 preference
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AbcdImportConfig
, configurator
.toString());
434 override
= PreferencesUtil
.getBooleanValue(
435 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(
436 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AbcdImportConfig
.getKey()), true):false;
437 if (allowOverride
&& override
){
438 String configString
= PreferencesUtil
.getStringValue(PreferencePredicate
.AbcdImportConfig
.getKey(), true);
439 configurator
= Abcd206ImportConfigurator
.NewInstance(null, null);
440 PreferencesUtil
.extractAbcdConfiguratorFromPreferenceString(configurator
, configString
);
442 PreferencesUtil
.extractAbcdConfiguratorFromPreferenceString(configurator
, preference
.getValue());
446 protected void setSelections(){
447 checkBoxMediaSpecimen
.setSelection(configurator
.isAddMediaAsMediaSpecimen());
448 checkBoxIgnoreExisting
.setSelection(configurator
.isIgnoreImportOfExistingSpecimen());
449 checkBoxIgnoreAuthorship
.setSelection(configurator
.isIgnoreAuthorship());
450 if (configurator
.isMapUnitIdToAccessionNumber()){
451 checkBoxMapUnitId
.select(0);
452 }else if (configurator
.isMapUnitIdToBarcode()){
453 checkBoxMapUnitId
.select(1);
455 checkBoxMapUnitId
.select(2);
459 checkBoxRemoveCountry
.setSelection(configurator
.isRemoveCountryFromLocalityText());
460 checkBoxImportSiblings
.setSelection(configurator
.isGetSiblings());
461 checkBoxAddIndividualsAssociations
.setSelection(configurator
.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
462 checkBoxReuseDescriptiveGroups
.setSelection(configurator
.isReuseExistingDescriptiveGroups());
463 checkBoxReuseExistingTaxa
.setSelection(configurator
.isReuseExistingTaxaWhenPossible());
465 textDNAProviderString
.setText(configurator
.getDnaSoure()!= null? configurator
.getDnaSoure().toString():"");
467 if (configurator
.getNomenclaturalCode() != null){
468 for (String label
: nomenclaturalCodeSelectionCombo
.getItems()){
469 if (label
.equals(configurator
.getNomenclaturalCode().getKey())){
470 nomenclaturalCodeSelectionCombo
.select(index
);
475 for (String label
: nomenclaturalCodeSelectionCombo
.getItems()){
476 NomenclaturalCode code
= PreferencesUtil
.getPreferredNomenclaturalCode();
477 if (label
.equals(code
.getKey())){
478 nomenclaturalCodeSelectionCombo
.select(index
);
479 configurator
.setNomenclaturalCode(code
);