Project

General

Profile

Download (20.1 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.menu.CdmPreferencePage;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

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

    
42
    private Abcd206ImportConfigurator configurator;
43

    
44
    private Combo nomenclaturalCodeSelectionCombo;
45

    
46
    private boolean allowOverride = true;
47
    private CdmPreference preference = null;
48

    
49
    @Override
50
    protected Control createContents(Composite parent) {
51
        final Composite composite = new Composite(parent, SWT.NULL);
52

    
53
        GridLayout gridLayout = new GridLayout();
54
        composite.setLayout(gridLayout);
55
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
56
        ICdmRepository controller;
57
        controller = CdmStore.getCurrentApplicationConfiguration();
58
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
59

    
60
        if (controller == null){
61
            return null;
62
        }
63
        preference = controller.getPreferenceService().find(key);
64

    
65
        if (preference != null ){
66
            allowOverride = preference.isAllowOverride();
67
        }else{
68
            preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
69
        }
70

    
71
        if (preference != null){
72

    
73
         String configString = preference.getValue();
74
         String[] configArray = configString.split(";"); //$NON-NLS-1$
75

    
76
         for (String configItem: configArray){
77
             String[] keyValue = configItem.split(":"); //$NON-NLS-1$
78
             if(keyValue.length==2){
79
                 String keyString = keyValue[0];
80
                 String valueString = keyValue[1];
81
                 if (keyString.equals("ignoreImportOfExistingSpecimen")){ //$NON-NLS-1$
82
                     configurator.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
83
                 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){ //$NON-NLS-1$
84
                     configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
85
                 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){ //$NON-NLS-1$
86
                     configurator.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
87
                 }else if (keyString.equals("ignoreAuthorship")){ //$NON-NLS-1$
88
                     configurator.setIgnoreAuthorship(Boolean.valueOf(valueString));
89
                 }else if (keyString.equals("addMediaAsMediaSpecimen")){ //$NON-NLS-1$
90
                     configurator.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
91
                 }else if (keyString.equals("reuseExistingMetaData")){ //$NON-NLS-1$
92
                     configurator.setReuseExistingMetaData(Boolean.valueOf(valueString));
93
                 }else if (keyString.equals("reuseExistingDescriptiveGroups")){ //$NON-NLS-1$
94
                     configurator.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
95
                 }else if (keyString.equals("allowReuseOtherClassifications")){ //$NON-NLS-1$
96
                     configurator.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
97
                 }else if (keyString.equals("deduplicateReferences")){ //$NON-NLS-1$
98
                     configurator.setDeduplicateReferences(Boolean.valueOf(valueString));
99
                 }else if (keyString.equals("deduplicateClassifications")){ //$NON-NLS-1$
100
                     configurator.setDeduplicateClassifications(Boolean.valueOf(valueString));
101
                 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){ //$NON-NLS-1$
102
                     configurator.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
103
                 }else if (keyString.equals("mapUnitIdToCatalogNumber")){ //$NON-NLS-1$
104
                     configurator.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
105
                 }else if (keyString.equals("mapUnitIdToAccessionNumber")){ //$NON-NLS-1$
106
                     configurator.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
107
                 }else if (keyString.equals("mapUnitIdToBarcode")){ //$NON-NLS-1$
108
                     configurator.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
109
                 }else if (keyString.equals("overwriteExistingSpecimens")){ //$NON-NLS-1$
110
                     configurator.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
111
                 }else if (keyString.equals("nomenclaturalCode")){ //$NON-NLS-1$
112
                     configurator.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
113
                 }
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
        if (preference != null){
290
            allowOverride = preference.isAllowOverride();
291
        }
292
        Button checkAllowOverride = new Button(composite, SWT.CHECK);
293
        checkAllowOverride.setSelection(allowOverride);
294
        checkAllowOverride.setText(Messages.AbcdImportPreference_allow_override);
295
        checkAllowOverride
296
            .setToolTipText(Messages.AbcdImportPreference_allow_override_tooltip);
297
        checkAllowOverride.addSelectionListener(new SelectionAdapter() {
298
            @Override
299
            public void widgetSelected(SelectionEvent e) {
300
                allowOverride = !allowOverride;
301
            }
302
        });
303

    
304
        return composite;
305
    }
306

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

    
311
    }
312

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

    
321
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configString);
322
            pref.setAllowOverride(allowOverride);
323

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

    
331
        }
332
        return true;
333
    }
334

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

    
342
    }
343

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

    
365
}
(1-1/12)