Project

General

Profile

Download (20.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.PreferenceSubject;
29
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
30
import eu.etaxonomy.taxeditor.l10n.Messages;
31
import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
33
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
34
import eu.etaxonomy.taxeditor.store.CdmStore;
35

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

    
43
    private Abcd206ImportConfigurator configurator;
44

    
45
    private Combo nomenclaturalCodeSelectionCombo;
46

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

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

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

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

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

    
72
        if (preference != null){
73

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

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

    
120
             }
121

    
122
         }
123
        }
124

    
125

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

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

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

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

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

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

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

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

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

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

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

    
273
        GridData gridData = new GridData();
274
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
275
        gridData.horizontalIndent = 5;
276
//      classificationSelection.setLayoutData(gridData);
277

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

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

    
310
        return composite;
311
    }
312

    
313
    @Override
314
    public void widgetSelected(SelectionEvent e) {
315
        this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
316

    
317
    }
318

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

    
327
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.AbcdImportConfig, configString);
328
            pref.setAllowOverride(allowOverride);
329

    
330
            ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
331
            if (controller == null){
332
                return false;
333
            }
334
            IPreferenceService service = controller.getPreferenceService();
335
            service.set(pref);
336
            PreferencesUtil.updateDBPreferences();
337

    
338
        }
339
        return true;
340
    }
341

    
342
    /**
343
     * {@inheritDoc}
344
     */
345
    @Override
346
    public void widgetDefaultSelected(SelectionEvent e) {
347
        // TODO Auto-generated method stub
348

    
349
    }
350

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

    
372
}
(1-1/13)