Project

General

Profile

Download (20.2 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.preference;
10

    
11
import java.net.URI;
12

    
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.CLabel;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Combo;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26

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

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

    
45
    private Abcd206ImportConfigurator configurator;
46

    
47
    private Combo nomenclaturalCodeSelectionCombo;
48

    
49
    private boolean allowOverride = true;
50
    private boolean override = true;
51
    private CdmPreference preference = null;
52
    Text textDNAProviderString;
53
    private Composite composite;
54
    Combo overrideCombo;
55

    
56
    @Override
57
    protected Control createContents(Composite parent) {
58

    
59

    
60

    
61

    
62
        getValues();
63

    
64

    
65
        //configurator = PreferencesUtil.getAbcdImportConfigurationPreference();
66
        final CLabel description = new CLabel(parent, SWT.NULL);
67
        description.setText(Messages.AbcdImportPreference_description);
68
//        final CLabel overrideDescription = new CLabel(parent, SWT.NULL);
69
//        overrideDescription.setText("");
70
//        GridData textGrid = createTextGridData();
71
//        textGrid.verticalSpan = 2;
72
//        overrideDescription.setLayoutData(textGrid);
73

    
74
        overrideCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
75

    
76
        overrideCombo.add(LocalOrDefaultEnum.Default.getLabel(), 0);
77
        overrideCombo.add(LocalOrDefaultEnum.Local.getLabel(), 1);
78
        overrideCombo.addSelectionListener(this);
79
        if (override){
80
            overrideCombo.select(1);
81
        }else{
82
            overrideCombo.select(0);
83
        }
84

    
85
        composite = new Composite(parent, SWT.NULL);
86

    
87
        GridLayout gridLayout = new GridLayout();
88
        composite.setLayout(gridLayout);
89
        Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
90
        checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
91
        checkBoxMediaSpecimen.setText(Messages.AbcdImportPreference_media_as_mediaSpecimen);
92
        checkBoxMediaSpecimen
93
                .setToolTipText(Messages.AbcdImportPreference_media_as_subUnit);
94
        checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
95
            @Override
96
            public void widgetSelected(SelectionEvent e) {
97
                configurator.setAddMediaAsMediaSpecimen(!configurator.isAddMediaAsMediaSpecimen());
98
                setApply(true);
99
            }
100
        });
101

    
102
        Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
103
        checkBoxIgnoreExisting.setSelection(configurator.isIgnoreImportOfExistingSpecimen());
104
        checkBoxIgnoreExisting.setText(Messages.AbcdImportPreference_not_import_existing_specimen);
105
        checkBoxIgnoreExisting
106
        .setToolTipText(Messages.AbcdImportPreference_not_import_existing_specimen_tooltip);
107
        checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
108
            @Override
109
            public void widgetSelected(SelectionEvent e) {
110
                configurator.setIgnoreImportOfExistingSpecimen(!configurator.isIgnoreImportOfExistingSpecimen());
111
                setApply(true);
112
            }
113
        });
114

    
115
        Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
116
        checkBoxIgnoreAuthorship.setSelection(configurator.isIgnoreAuthorship());
117
        checkBoxIgnoreAuthorship.setText(Messages.AbcdImportPreference_ignore_author);
118
        checkBoxIgnoreAuthorship
119
        .setToolTipText(Messages.AbcdImportPreference_ignore_author_tooltip);
120
        checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
121
            @Override
122
            public void widgetSelected(SelectionEvent e) {
123
                configurator.setIgnoreAuthorship(!configurator.isIgnoreAuthorship());
124
                setApply(true);
125
            }
126
        });
127

    
128
        Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
129
        checkBoxMapUnitIdToCatalogNumber.setSelection(configurator.isMapUnitIdToCatalogNumber());
130
        checkBoxMapUnitIdToCatalogNumber.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
131
        checkBoxMapUnitIdToCatalogNumber
132
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
133
        checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
134
            @Override
135
            public void widgetSelected(SelectionEvent e) {
136
                configurator.setMapUnitIdToCatalogNumber(!configurator.isMapUnitIdToCatalogNumber());
137
                setApply(true);
138
            }
139
        });
140
//TODO: only one of the mappings can be checked!
141
        Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
142
        checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
143
        checkBoxMapUnitIdToAccessionNumber.setText(Messages.AbcdImportPreference_map_unit_number_to_accession_number);
144
        checkBoxMapUnitIdToAccessionNumber
145
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_accession_number_tooltip);
146
        checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
147
            @Override
148
            public void widgetSelected(SelectionEvent e) {
149
                configurator.setMapUnitIdToAccessionNumber(!configurator.isMapUnitIdToAccessionNumber());
150
                setApply(true);
151
            }
152
        });
153

    
154
        Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
155
        checkBoxMapUnitIdToBarcode.setSelection(configurator.isMapUnitIdToBarcode());
156
        checkBoxMapUnitIdToBarcode.setText(Messages.AbcdImportPreference_map_unit_number_barcode);
157
        checkBoxMapUnitIdToBarcode
158
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_barcode_tooltip);
159
        checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
160
            @Override
161
            public void widgetSelected(SelectionEvent e) {
162
                configurator.setMapUnitIdToBarcode(!configurator.isMapUnitIdToBarcode());
163
                setApply(true);
164
            }
165
        });
166

    
167
        Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
168
        checkBoxRemoveCountry.setSelection(configurator.isRemoveCountryFromLocalityText());
169
        checkBoxRemoveCountry.setText(Messages.AbcdImportPreference_remove_country_from_locality);
170
        checkBoxRemoveCountry
171
        .setToolTipText(Messages.AbcdImportPreference_remove_country_from_locality_tooltip);
172
        checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
173
            @Override
174
            public void widgetSelected(SelectionEvent e) {
175
                configurator.setRemoveCountryFromLocalityText(!configurator.isRemoveCountryFromLocalityText());
176
                setApply(true);
177
            }
178
        });
179

    
180
        Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
181
        checkBoxMoveToDefaultClassification.setSelection(configurator.isMoveNewTaxaToDefaultClassification());
182
        checkBoxMoveToDefaultClassification.setText(Messages.AbcdImportPreference_create_new_classification_new_taxa);
183
        checkBoxMoveToDefaultClassification
184
        .setToolTipText(Messages.AbcdImportPreference_create_new_classification_new_taxa_tooltip);
185
        checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
186
            @Override
187
            public void widgetSelected(SelectionEvent e) {
188
                configurator.setMoveNewTaxaToDefaultClassification(!configurator.isMoveNewTaxaToDefaultClassification());
189
                setApply(true);
190
            }
191
        });
192

    
193
        Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
194
        checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
195
        checkBoxImportSiblings.setText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues);
196
        checkBoxImportSiblings
197
            .setToolTipText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip);
198
        checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
199
            @Override
200
            public void widgetSelected(SelectionEvent e) {
201
                configurator.setGetSiblings(!configurator.isGetSiblings());
202
                setApply(true);
203
            }
204
        });
205

    
206
        Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
207
        checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
208
        checkBoxAddIndividualsAssociations.setText(Messages.AbcdImportPreference_create_Individual_Association);
209
        checkBoxAddIndividualsAssociations
210
            .setToolTipText(Messages.AbcdImportPreference_create_Individual_Association_tooltip);
211
        checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
212
            @Override
213
            public void widgetSelected(SelectionEvent e) {
214
                configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
215
                setApply(true);
216
            }
217
        });
218

    
219
        Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
220
        checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
221
        checkBoxReuseDescriptiveGroups.setText(Messages.AbcdImportPreference_reuse_descriptive_group);
222
        checkBoxReuseDescriptiveGroups
223
            .setToolTipText(Messages.AbcdImportPreference_reuse_descriptive_group_tooltip);
224
        checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
225
            @Override
226
            public void widgetSelected(SelectionEvent e) {
227
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
228
                setApply(true);
229
            }
230
        });
231

    
232
        Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
233
        checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
234
        checkBoxReuseExistingTaxa.setText(Messages.AbcdImportPreference_reuse_existing_taxa);
235
        checkBoxReuseExistingTaxa
236
            .setToolTipText(Messages.AbcdImportPreference_reuse_existing_taxa_tooltip);
237
        checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
238
            @Override
239
            public void widgetSelected(SelectionEvent e) {
240
                configurator.setReuseExistingTaxaWhenPossible(!configurator.isReuseExistingTaxaWhenPossible());
241
                setApply(true);
242
            }
243
        });
244

    
245
        Label labelRef = new Label(composite, SWT.NONE);
246
        labelRef.setText("Biocase provider for associated DNA");
247
        new Label(composite, SWT.NONE);
248
        textDNAProviderString = new Text(composite, SWT.NONE);
249
        textDNAProviderString.setEnabled(true);
250
        textDNAProviderString.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
251
        textDNAProviderString.setText(configurator.getDnaSoure().toString());
252
        GridData gridData = new GridData();
253
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
254
        gridData.horizontalIndent = 5;
255
//      classificationSelection.setLayoutData(gridData);
256

    
257
        nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
258
        nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
259
        for(NomenclaturalCode code: NomenclaturalCode.values()){
260
            nomenclaturalCodeSelectionCombo.add(code.getKey());
261
        }
262
        int index = 0;
263
        if (configurator.getNomenclaturalCode() != null){
264
            for (String label : nomenclaturalCodeSelectionCombo.getItems()){
265
                if (label.equals(configurator.getNomenclaturalCode().getKey())){
266
                    nomenclaturalCodeSelectionCombo.select(index);
267

    
268
                }
269
                index++;
270
            }
271
        }
272

    
273
        // TODO remember last selection
274
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
275
        if (preference != null){
276
            allowOverride = preference.isAllowOverride();
277
        }
278

    
279
        if (!override){
280
            //composite.setEnabled(false);
281
            PreferencesUtil.recursiveSetEnabled(composite, override);
282
        }
283

    
284
        return composite;
285
    }
286

    
287
    @Override
288
    public void widgetSelected(SelectionEvent e) {
289
        if (e.getSource().equals(nomenclaturalCodeSelectionCombo)){
290
            this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
291
        }
292
        if (e.getSource().equals(overrideCombo)) {
293
            override = overrideCombo.getText().equals(LocalOrDefaultEnum.Local.getLabel())?true:false;
294
        }
295
        PreferencesUtil.recursiveSetEnabled(composite, override);
296
        setApply(true);
297

    
298
    }
299

    
300
    @Override
301
    public boolean performOk() {
302
        if (!isApply()){
303
            return true;
304
        }
305
        if (configurator != null){
306
            String configString = configurator.toString();
307

    
308

    
309
            if (override){
310
                PreferencesUtil.setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), configString);
311
                PreferencesUtil.setBooleanValue( PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), override);
312

    
313
            }else{
314
                PreferencesUtil.setBooleanValue( PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), override);
315
            }
316

    
317

    
318
        }
319
        return true;
320
    }
321

    
322
    /**
323
     * {@inheritDoc}
324
     */
325
    @Override
326
    public void widgetDefaultSelected(SelectionEvent e) {
327
        // TODO Auto-generated method stub
328

    
329
    }
330

    
331
    @Override
332
    protected void performDefaults() {
333
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
334
        preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
335
        preference.setAllowOverride(true);
336
        super.performDefaults();
337
    }
338

    
339
    @Override
340
    public void getValues() {
341
        isAdminPreference = false;
342
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
343
        ICdmRepository controller;
344
        controller = CdmStore.getCurrentApplicationConfiguration();
345
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
346
        preference = controller.getPreferenceService().find(key);
347

    
348
        if (preference != null ){
349
            allowOverride = preference.isAllowOverride();
350
        }else{
351
            preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
352
        }
353

    
354
        override = PreferencesUtil.getBooleanValue(
355
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true) != null? PreferencesUtil.getBooleanValue(
356
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true):false;
357

    
358
        String configString;
359
        if (!override){
360
            configString = preference.getValue();
361
        }else{
362
            configString = PreferencesUtil.getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), true);
363
        }
364
        if(configString!=null){
365
            String[] configArray = configString.split(";"); //$NON-NLS-1$
366

    
367
            for (String configItem: configArray){
368
                String[] keyValue = configItem.split(":"); //$NON-NLS-1$
369
                if(keyValue.length==2){
370
                    String keyString = keyValue[0];
371
                    String valueString = keyValue[1];
372
                    if (keyString.equals("ignoreImportOfExistingSpecimen")){ //$NON-NLS-1$
373
                        configurator.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
374
                    }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){ //$NON-NLS-1$
375
                        configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
376
                    }else if (keyString.equals("reuseExistingTaxaWhenPossible")){ //$NON-NLS-1$
377
                        configurator.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
378
                    }else if (keyString.equals("ignoreAuthorship")){ //$NON-NLS-1$
379
                        configurator.setIgnoreAuthorship(Boolean.valueOf(valueString));
380
                    }else if (keyString.equals("addMediaAsMediaSpecimen")){ //$NON-NLS-1$
381
                        configurator.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
382
                    }else if (keyString.equals("reuseExistingMetaData")){ //$NON-NLS-1$
383
                        configurator.setReuseExistingMetaData(Boolean.valueOf(valueString));
384
                    }else if (keyString.equals("reuseExistingDescriptiveGroups")){ //$NON-NLS-1$
385
                        configurator.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
386
                    }else if (keyString.equals("allowReuseOtherClassifications")){ //$NON-NLS-1$
387
                        configurator.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
388
                    }else if (keyString.equals("deduplicateReferences")){ //$NON-NLS-1$
389
                        configurator.setDeduplicateReferences(Boolean.valueOf(valueString));
390
                    }else if (keyString.equals("deduplicateClassifications")){ //$NON-NLS-1$
391
                        configurator.setDeduplicateClassifications(Boolean.valueOf(valueString));
392
                    }else if (keyString.equals("moveNewTaxaToDefaultClassification")){ //$NON-NLS-1$
393
                        configurator.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
394
                    }else if (keyString.equals("mapUnitIdToCatalogNumber")){ //$NON-NLS-1$
395
                        configurator.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
396
                    }else if (keyString.equals("mapUnitIdToAccessionNumber")){ //$NON-NLS-1$
397
                        configurator.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
398
                    }else if (keyString.equals("mapUnitIdToBarcode")){ //$NON-NLS-1$
399
                        configurator.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
400
                    }else if (keyString.equals("overwriteExistingSpecimens")){ //$NON-NLS-1$
401
                        configurator.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
402
                    }else if (keyString.equals("nomenclaturalCode")){ //$NON-NLS-1$
403
                        configurator.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
404
                    }else if (keyString.equals("getSiblings")){ //$NON-NLS-1$
405
                        configurator.setGetSiblings(Boolean.valueOf(valueString));
406
                    }else if (keyString.equals("removeCountryFromLocalityText")){ //$NON-NLS-1$
407
                        configurator.setRemoveCountryFromLocalityText(Boolean.valueOf(valueString));
408
                    }else if (keyString.equals("dnaSource")){ //$NON-NLS-1$
409
                        configurator.setDnaSoure(URI.create(valueString));
410
                    }
411

    
412
                }
413
            }
414
        }
415
    }
416

    
417
}
(1-1/51)