Project

General

Profile

Download (19.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.preferencePage;
10

    
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;
22

    
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.IPreferenceKeys;
33
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

    
37
/**
38
 * @author k.luther
39
 * @since 23.03.2018
40
 *
41
 */
42
public class AbcdImportPreference extends CdmPreferencePage implements IE4AdminPreferencePage, SelectionListener {
43

    
44
    private Abcd206ImportConfigurator configurator;
45

    
46
    private Combo nomenclaturalCodeSelectionCombo;
47

    
48
    private boolean allowOverride = true;
49
    CdmPreference preference = null;
50

    
51
    /**
52
     * {@inheritDoc}
53
     */
54
    @Override
55
    protected Control createContents(Composite parent) {
56
        final Composite composite = new Composite(parent, SWT.NULL);
57

    
58
        GridLayout gridLayout = new GridLayout();
59
        composite.setLayout(gridLayout);
60
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
61
        ICdmRepository controller;
62
        controller = CdmStore.getCurrentApplicationConfiguration();
63
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
64

    
65
        if (controller == null){
66
            return null;
67
        }
68
        preference = controller.getPreferenceService().find(key);
69

    
70
        if (preference != null ){
71
            allowOverride = preference.isAllowOverride();
72
        }else{
73
            preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
74
        }
75

    
76
        if (preference != null){
77

    
78
         String configString = preference.getValue();
79
         String[] configArray = configString.split(";");
80

    
81
         for (String configItem: configArray){
82
             String[] keyValue = configItem.split(":");
83
             String keyString = keyValue[0];
84
             String valueString = keyValue[1];
85
             if (keyString.equals("ignoreImportOfExistingSpecimen")){
86
                 configurator.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
87
             }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
88
                 configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
89
             }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
90
                 configurator.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
91
             }else if (keyString.equals("ignoreAuthorship")){
92
                 configurator.setIgnoreAuthorship(Boolean.valueOf(valueString));
93
             }else if (keyString.equals("addMediaAsMediaSpecimen")){
94
                 configurator.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
95
             }else if (keyString.equals("reuseExistingMetaData")){
96
                 configurator.setReuseExistingMetaData(Boolean.valueOf(valueString));
97
             }else if (keyString.equals("reuseExistingDescriptiveGroups")){
98
                 configurator.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
99
             }else if (keyString.equals("allowReuseOtherClassifications")){
100
                 configurator.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
101
             }else if (keyString.equals("deduplicateReferences")){
102
                 configurator.setDeduplicateReferences(Boolean.valueOf(valueString));
103
             }else if (keyString.equals("deduplicateClassifications")){
104
                 configurator.setDeduplicateClassifications(Boolean.valueOf(valueString));
105
             }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
106
                 configurator.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
107
             }else if (keyString.equals("mapUnitIdToCatalogNumber")){
108
                 configurator.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
109
             }else if (keyString.equals("mapUnitIdToAccessionNumber")){
110
                 configurator.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
111
             }else if (keyString.equals("mapUnitIdToBarcode")){
112
                 configurator.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
113
             }else if (keyString.equals("overwriteExistingSpecimens")){
114
                 configurator.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
115
             }else if (keyString.equals("nomenclaturalCode")){
116
                 configurator.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
117
             }
118

    
119
         }
120
        }
121

    
122

    
123
        //configurator = PreferencesUtil.getAbcdImportConfigurationPreference();
124
        final CLabel description = new CLabel(composite, SWT.NULL);
125
        description.setText(Messages.AbcdImportPreference_description);
126
        Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
127
        checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
128
        checkBoxMediaSpecimen.setText(Messages.AbcdImportPreference_media_as_mediaSpecimen);
129
        checkBoxMediaSpecimen
130
                .setToolTipText(Messages.AbcdImportPreference_media_as_subUnit);
131
        checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
132
            @Override
133
            public void widgetSelected(SelectionEvent e) {
134
                configurator.setAddMediaAsMediaSpecimen(!configurator.isAddMediaAsMediaSpecimen());
135
            }
136
        });
137

    
138
        Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
139
        checkBoxIgnoreExisting.setSelection(configurator.isIgnoreImportOfExistingSpecimen());
140
        checkBoxIgnoreExisting.setText(Messages.AbcdImportPreference_not_import_existing_specimen);
141
        checkBoxIgnoreExisting
142
        .setToolTipText(Messages.AbcdImportPreference_not_import_existing_specimen_tooltip);
143
        checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
144
            @Override
145
            public void widgetSelected(SelectionEvent e) {
146
                configurator.setIgnoreImportOfExistingSpecimen(!configurator.isIgnoreImportOfExistingSpecimen());
147
            }
148
        });
149

    
150
        Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
151
        checkBoxIgnoreAuthorship.setSelection(configurator.isIgnoreAuthorship());
152
        checkBoxIgnoreAuthorship.setText(Messages.AbcdImportPreference_ignore_author);
153
        checkBoxIgnoreAuthorship
154
        .setToolTipText(Messages.AbcdImportPreference_ignore_author_tooltip);
155
        checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
156
            @Override
157
            public void widgetSelected(SelectionEvent e) {
158
                configurator.setIgnoreAuthorship(!configurator.isIgnoreAuthorship());
159
            }
160
        });
161

    
162
        Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
163
        checkBoxMapUnitIdToCatalogNumber.setSelection(configurator.isMapUnitIdToCatalogNumber());
164
        checkBoxMapUnitIdToCatalogNumber.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
165
        checkBoxMapUnitIdToCatalogNumber
166
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
167
        checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
168
            @Override
169
            public void widgetSelected(SelectionEvent e) {
170
                configurator.setMapUnitIdToCatalogNumber(!configurator.isMapUnitIdToCatalogNumber());
171
            }
172
        });
173
//TODO: only one of the mappings can be checked!
174
        Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
175
        checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
176
        checkBoxMapUnitIdToAccessionNumber.setText(Messages.AbcdImportPreference_map_unit_number_to_accession_number);
177
        checkBoxMapUnitIdToAccessionNumber
178
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_accession_number_tooltip);
179
        checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
180
            @Override
181
            public void widgetSelected(SelectionEvent e) {
182
                configurator.setMapUnitIdToAccessionNumber(!configurator.isMapUnitIdToAccessionNumber());
183
            }
184
        });
185

    
186
        Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
187
        checkBoxMapUnitIdToBarcode.setSelection(configurator.isMapUnitIdToBarcode());
188
        checkBoxMapUnitIdToBarcode.setText(Messages.AbcdImportPreference_map_unit_number_barcode);
189
        checkBoxMapUnitIdToBarcode
190
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_barcode_tooltip);
191
        checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
192
            @Override
193
            public void widgetSelected(SelectionEvent e) {
194
                configurator.setMapUnitIdToBarcode(!configurator.isMapUnitIdToBarcode());
195
            }
196
        });
197

    
198
        Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
199
        checkBoxRemoveCountry.setSelection(configurator.isRemoveCountryFromLocalityText());
200
        checkBoxRemoveCountry.setText(Messages.AbcdImportPreference_remove_country_from_locality);
201
        checkBoxRemoveCountry
202
        .setToolTipText(Messages.AbcdImportPreference_remove_country_from_locality_tooltip);
203
        checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
204
            @Override
205
            public void widgetSelected(SelectionEvent e) {
206
                configurator.setRemoveCountryFromLocalityText(!configurator.isRemoveCountryFromLocalityText());
207
            }
208
        });
209

    
210
        Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
211
        checkBoxMoveToDefaultClassification.setSelection(configurator.isMoveNewTaxaToDefaultClassification());
212
        checkBoxMoveToDefaultClassification.setText(Messages.AbcdImportPreference_create_new_classification_new_taxa);
213
        checkBoxMoveToDefaultClassification
214
        .setToolTipText(Messages.AbcdImportPreference_create_new_classification_new_taxa_tooltip);
215
        checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
216
            @Override
217
            public void widgetSelected(SelectionEvent e) {
218
                configurator.setMoveNewTaxaToDefaultClassification(!configurator.isMoveNewTaxaToDefaultClassification());
219
            }
220
        });
221

    
222
        Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
223
        checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
224
        checkBoxImportSiblings.setText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues);
225
        checkBoxImportSiblings
226
            .setToolTipText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip);
227
        checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
228
            @Override
229
            public void widgetSelected(SelectionEvent e) {
230
                configurator.setGetSiblings(checkBoxImportSiblings.getSelection());
231
            }
232
        });
233

    
234
        Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
235
        checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
236
        checkBoxAddIndividualsAssociations.setText(Messages.AbcdImportPreference_create_Individual_Association);
237
        checkBoxAddIndividualsAssociations
238
            .setToolTipText(Messages.AbcdImportPreference_create_Individual_Association_tooltip);
239
        checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
240
            @Override
241
            public void widgetSelected(SelectionEvent e) {
242
                configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
243
            }
244
        });
245

    
246
        Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
247
        checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
248
        checkBoxReuseDescriptiveGroups.setText(Messages.AbcdImportPreference_reuse_descriptive_group);
249
        checkBoxReuseDescriptiveGroups
250
            .setToolTipText(Messages.AbcdImportPreference_reuse_descriptive_group_tooltip);
251
        checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
252
            @Override
253
            public void widgetSelected(SelectionEvent e) {
254
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
255
            }
256
        });
257

    
258
        Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
259
        checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
260
        checkBoxReuseExistingTaxa.setText(Messages.AbcdImportPreference_reuse_existing_taxa);
261
        checkBoxReuseExistingTaxa
262
            .setToolTipText(Messages.AbcdImportPreference_reuse_existing_taxa_tooltip);
263
        checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
264
            @Override
265
            public void widgetSelected(SelectionEvent e) {
266
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
267
            }
268
        });
269

    
270
        GridData gridData = new GridData();
271
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
272
        gridData.horizontalIndent = 5;
273
//      classificationSelection.setLayoutData(gridData);
274

    
275
        nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
276
        nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
277
        for(NomenclaturalCode code: NomenclaturalCode.values()){
278
            nomenclaturalCodeSelectionCombo.add(code.getKey());
279
        }
280
        int index = 0;
281
        if (configurator.getNomenclaturalCode() != null){
282
            for (String label : nomenclaturalCodeSelectionCombo.getItems()){
283
                if (label.equals(configurator.getNomenclaturalCode().getKey())){
284
                    nomenclaturalCodeSelectionCombo.select(index);
285
                }
286
                index++;
287
            }
288
        }
289

    
290
        // TODO remember last selection
291
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
292
        if (preference != null){
293
            allowOverride = preference.isAllowOverride();
294
        }
295
        Button checkAllowOverride = new Button(composite, SWT.CHECK);
296
        checkAllowOverride.setSelection(allowOverride);
297
        checkAllowOverride.setText(Messages.AbcdImportPreference_allow_override);
298
        checkAllowOverride
299
            .setToolTipText(Messages.AbcdImportPreference_allow_override_tooltip);
300
        checkAllowOverride.addSelectionListener(new SelectionAdapter() {
301
            @Override
302
            public void widgetSelected(SelectionEvent e) {
303
                allowOverride = !allowOverride;
304
            }
305
        });
306

    
307
        return composite;
308
    }
309

    
310
    @Override
311
    public void widgetSelected(SelectionEvent e) {
312
        this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
313

    
314
    }
315

    
316
    @Override
317
    public boolean performOk() {
318
        if (preference == null){
319
            return true;
320
        }
321
        if (configurator != null){
322
            String configString = configurator.toString();
323

    
324
            CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.AbcdImportConfig, configString);
325
            pref.setAllowOverride(allowOverride);
326

    
327
            ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
328
            if (controller == null){
329
                return false;
330
            }
331
            IPreferenceService service = controller.getPreferenceService();
332
            service.set(pref);
333

    
334
        }
335
        return true;
336
    }
337

    
338
    /**
339
     * {@inheritDoc}
340
     */
341
    @Override
342
    public void widgetDefaultSelected(SelectionEvent e) {
343
        // TODO Auto-generated method stub
344

    
345
    }
346

    
347
    public void createAbcdImportConfig() {
348
        this.configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
349
        this.configurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
350
        this.configurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
351
        //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
352
        this.configurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
353
        this.configurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
354
       // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
355
        this.configurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
356
        this.configurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
357
        this.configurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
358
        this.configurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
359
        this.configurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
360
        this.configurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
361
        this.configurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
362
        this.configurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
363
        this.configurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
364
        this.configurator.setNomenclaturalCode(PreferencesUtil.getPreferredNomenclaturalCode(doGetPreferenceStore().getString(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
365

    
366
    }
367

    
368
}
(1-1/12)