Project

General

Profile

Download (19.5 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

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

    
57
        GridLayout gridLayout = new GridLayout();
58
        composite.setLayout(gridLayout);
59
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
60
        ICdmRepository controller;
61
        controller = CdmStore.getCurrentApplicationConfiguration();
62
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
63
        CdmPreference preference = null;
64
        if (controller == null){
65
            return null;
66
        }
67
        preference = controller.getPreferenceService().find(key);
68

    
69
        if (preference != null ){
70
            allowOverride = preference.isAllowOverride();
71
        }
72

    
73
        if (preference != null){
74

    
75
         String configString = preference.getValue();
76
         String[] configArray = configString.split(";");
77

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

    
116
         }
117
        }
118

    
119

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

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

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

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

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

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

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

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

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

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

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

    
267
        GridData gridData = new GridData();
268
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
269
        gridData.horizontalIndent = 5;
270
//      classificationSelection.setLayoutData(gridData);
271

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

    
287
        // TODO remember last selection
288
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
289

    
290
        allowOverride = preference.isAllowOverride();
291
        Button checkAllowOverride = new Button(composite, SWT.CHECK);
292
        checkAllowOverride.setSelection(allowOverride);
293
        checkAllowOverride.setText(Messages.AbcdImportPreference_allow_override);
294
        checkAllowOverride
295
            .setToolTipText(Messages.AbcdImportPreference_allow_override_tooltip);
296
        checkAllowOverride.addSelectionListener(new SelectionAdapter() {
297
            @Override
298
            public void widgetSelected(SelectionEvent e) {
299
                allowOverride = !allowOverride;
300
            }
301
        });
302

    
303
        return composite;
304
    }
305

    
306
    @Override
307
    public void widgetSelected(SelectionEvent e) {
308
        this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
309

    
310
    }
311

    
312
    @Override
313
    public boolean performOk() {
314
        if (configurator != null){
315
            String configString = configurator.toString();
316

    
317
            CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.AbcdImportConfig, configString);
318
            pref.setAllowOverride(allowOverride);
319

    
320
            ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
321
            if (controller == null){
322
                return false;
323
            }
324
            IPreferenceService service = controller.getPreferenceService();
325
            service.set(pref);
326

    
327
        }
328
        return true;
329
    }
330

    
331
    /**
332
     * {@inheritDoc}
333
     */
334
    @Override
335
    public void widgetDefaultSelected(SelectionEvent e) {
336
        // TODO Auto-generated method stub
337

    
338
    }
339

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

    
359
    }
360

    
361
}
(1-1/10)