Project

General

Profile

Download (17.6 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 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
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.swt.widgets.Text;
24

    
25
import eu.etaxonomy.cdm.api.application.ICdmRepository;
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
27
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
28
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
29
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
30
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
32
import eu.etaxonomy.taxeditor.l10n.Messages;
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 IE4PreferencePage, SelectionListener {
42

    
43
    protected Abcd206ImportConfigurator configurator;
44

    
45
    protected Combo nomenclaturalCodeSelectionCombo;
46

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

    
54
    Button checkBoxMediaSpecimen;
55
    Button checkBoxIgnoreExisting;
56
    Button checkBoxIgnoreAuthorship;
57
    Button checkBoxMapUnitIdToCatalogNumber;
58
    Button checkBoxMapUnitIdToAccessionNumber;
59
    Button checkBoxMapUnitIdToBarcode;
60
    Button checkBoxRemoveCountry;
61
    Button checkBoxMoveToDefaultClassification;
62
    Button checkBoxImportSiblings;
63
    Button checkBoxAddIndividualsAssociations;
64
    Button checkBoxReuseDescriptiveGroups;
65
    Button checkBoxReuseExistingTaxa;
66
    Button checkAllowOverride;
67

    
68
    @Override
69
    protected Control createContents(Composite parent) {
70
        getValues();
71

    
72
        if (!isAdminPreference && !allowOverride){
73
            Label label = new Label(parent, SWT.NONE);
74
            label.setText("The CDM settings don't allow to set the abcd import preference locally. If you need to make local settings, please ask an administrator.");
75
            this.noDefaultAndApplyButton();
76
            return parent;
77
        }
78
        final Composite composite = new Composite(parent, SWT.NULL);
79
        GridLayout gridLayout = new GridLayout();
80
        composite.setLayout(gridLayout);
81

    
82
        final CLabel description = new CLabel(composite, SWT.NULL);
83
        description.setText(Messages.AbcdImportPreference_description);
84
        checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
85
        checkBoxMediaSpecimen.setText(Messages.AbcdImportPreference_media_as_mediaSpecimen);
86
        checkBoxMediaSpecimen
87
                .setToolTipText(Messages.AbcdImportPreference_media_as_subUnit);
88
        checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
89
            @Override
90
            public void widgetSelected(SelectionEvent e) {
91
                configurator.setAddMediaAsMediaSpecimen(!configurator.isAddMediaAsMediaSpecimen());
92
                setApply(true);
93
            }
94
        });
95

    
96
        checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
97

    
98
        checkBoxIgnoreExisting.setText(Messages.AbcdImportPreference_not_import_existing_specimen);
99
        checkBoxIgnoreExisting
100
        .setToolTipText(Messages.AbcdImportPreference_not_import_existing_specimen_tooltip);
101
        checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
102
            @Override
103
            public void widgetSelected(SelectionEvent e) {
104
                configurator.setIgnoreImportOfExistingSpecimen(!configurator.isIgnoreImportOfExistingSpecimen());
105
                setApply(true);
106
            }
107
        });
108

    
109
        checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
110

    
111
        checkBoxIgnoreAuthorship.setText(Messages.AbcdImportPreference_ignore_author);
112
        checkBoxIgnoreAuthorship
113
        .setToolTipText(Messages.AbcdImportPreference_ignore_author_tooltip);
114
        checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
115
            @Override
116
            public void widgetSelected(SelectionEvent e) {
117
                configurator.setIgnoreAuthorship(!configurator.isIgnoreAuthorship());
118
                setApply(true);
119
            }
120
        });
121

    
122
        checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.RADIO);
123

    
124
        checkBoxMapUnitIdToCatalogNumber.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
125
        checkBoxMapUnitIdToCatalogNumber
126
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
127
        checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
128
            @Override
129
            public void widgetSelected(SelectionEvent e) {
130
                configurator.setMapUnitIdToCatalogNumber(!configurator.isMapUnitIdToCatalogNumber());
131
                setApply(true);
132
            }
133
        });
134
//TODO: only one of the mappings can be checked!
135
        checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.RADIO);
136

    
137
        checkBoxMapUnitIdToAccessionNumber.setText(Messages.AbcdImportPreference_map_unit_number_to_accession_number);
138
        checkBoxMapUnitIdToAccessionNumber
139
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_accession_number_tooltip);
140
        checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
141
            @Override
142
            public void widgetSelected(SelectionEvent e) {
143
                configurator.setMapUnitIdToAccessionNumber(!configurator.isMapUnitIdToAccessionNumber());
144
                setApply(true);
145
            }
146
        });
147

    
148
        checkBoxMapUnitIdToBarcode = new Button(composite, SWT.RADIO);
149

    
150
        checkBoxMapUnitIdToBarcode.setText(Messages.AbcdImportPreference_map_unit_number_barcode);
151
        checkBoxMapUnitIdToBarcode
152
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_barcode_tooltip);
153
        checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
154
            @Override
155
            public void widgetSelected(SelectionEvent e) {
156
                configurator.setMapUnitIdToBarcode(!configurator.isMapUnitIdToBarcode());
157
                setApply(true);
158
            }
159
        });
160

    
161
        checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
162

    
163
        checkBoxRemoveCountry.setText(Messages.AbcdImportPreference_remove_country_from_locality);
164
        checkBoxRemoveCountry
165
        .setToolTipText(Messages.AbcdImportPreference_remove_country_from_locality_tooltip);
166
        checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
167
            @Override
168
            public void widgetSelected(SelectionEvent e) {
169
                configurator.setRemoveCountryFromLocalityText(!configurator.isRemoveCountryFromLocalityText());
170
                setApply(true);
171
            }
172
        });
173

    
174
        checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
175
        checkBoxMoveToDefaultClassification.setSelection(configurator.isMoveNewTaxaToDefaultClassification());
176
        checkBoxMoveToDefaultClassification.setText(Messages.AbcdImportPreference_create_new_classification_new_taxa);
177
        checkBoxMoveToDefaultClassification
178
        .setToolTipText(Messages.AbcdImportPreference_create_new_classification_new_taxa_tooltip);
179
        checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
180
            @Override
181
            public void widgetSelected(SelectionEvent e) {
182
                configurator.setMoveNewTaxaToDefaultClassification(!configurator.isMoveNewTaxaToDefaultClassification());
183
                setApply(true);
184
            }
185
        });
186

    
187
        checkBoxImportSiblings = new Button(composite, SWT.CHECK);
188

    
189
        checkBoxImportSiblings.setText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues);
190
        checkBoxImportSiblings
191
            .setToolTipText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip);
192
        checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
193
            @Override
194
            public void widgetSelected(SelectionEvent e) {
195
                configurator.setGetSiblings(!configurator.isGetSiblings());
196
                setApply(true);
197
            }
198
        });
199

    
200
        checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
201

    
202
        checkBoxAddIndividualsAssociations.setText(Messages.AbcdImportPreference_create_Individual_Association);
203
        checkBoxAddIndividualsAssociations
204
            .setToolTipText(Messages.AbcdImportPreference_create_Individual_Association_tooltip);
205
        checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
206
            @Override
207
            public void widgetSelected(SelectionEvent e) {
208
                configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
209
                setApply(true);
210
            }
211
        });
212

    
213
        checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
214

    
215
        checkBoxReuseDescriptiveGroups.setText(Messages.AbcdImportPreference_reuse_descriptive_group);
216
        checkBoxReuseDescriptiveGroups
217
            .setToolTipText(Messages.AbcdImportPreference_reuse_descriptive_group_tooltip);
218
        checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
219
            @Override
220
            public void widgetSelected(SelectionEvent e) {
221
                configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
222
                setApply(true);
223
            }
224
        });
225

    
226
        checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
227

    
228
        checkBoxReuseExistingTaxa.setText(Messages.AbcdImportPreference_reuse_existing_taxa);
229
        checkBoxReuseExistingTaxa
230
            .setToolTipText(Messages.AbcdImportPreference_reuse_existing_taxa_tooltip);
231
        checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
232
            @Override
233
            public void widgetSelected(SelectionEvent e) {
234
                configurator.setReuseExistingTaxaWhenPossible(!configurator.isReuseExistingTaxaWhenPossible());
235
                setApply(true);
236
            }
237
        });
238

    
239
        Label labelRef = new Label(composite, SWT.NONE);
240
        labelRef.setText("Biocase provider for associated DNA");
241
       // new Label(composite, SWT.NONE);
242
        textDNAProviderString = new Text(composite, SWT.NONE);
243
        textDNAProviderString.setEnabled(true);
244
        textDNAProviderString.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
245

    
246
        GridData gridData = new GridData();
247
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
248
        gridData.horizontalIndent = 5;
249
//      classificationSelection.setLayoutData(gridData);
250
        Label nomenclaturalCodeLabel = new Label(composite, SWT.NONE);
251
        nomenclaturalCodeLabel.setText("Nomenclatural Code");
252
        nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
253
        nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
254
        nomenclaturalCodeSelectionCombo.add(" - ");
255
        for(NomenclaturalCode code: NomenclaturalCode.values()){
256
            nomenclaturalCodeSelectionCombo.add(code.getKey());
257
        }
258

    
259

    
260

    
261
        // TODO remember last selection
262
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
263
        if (preference != null){
264
            allowOverride = preference.isAllowOverride();
265
        }
266

    
267
        checkAllowOverride = new Button(composite, SWT.CHECK);
268
        if (isAdminPreference){
269
            checkAllowOverride.setSelection(allowOverride);
270
            checkAllowOverride.setText(Messages.AbcdImportPreference_allow_override);
271
            checkAllowOverride
272
                .setToolTipText(Messages.AbcdImportPreference_allow_override_tooltip);
273
        }else{
274
            checkAllowOverride.setSelection(override);
275
            checkAllowOverride.setText(Messages.AbcdImportPreference_override);
276
            checkAllowOverride
277
                .setToolTipText(Messages.AbcdImportPreference_override_tooltip);
278
        }
279
        checkAllowOverride.addSelectionListener(new SelectionAdapter() {
280
            @Override
281
            public void widgetSelected(SelectionEvent e) {
282
                if (isAdminPreference){
283
                    allowOverride = !allowOverride;
284
                }else{
285
                    override = !override;
286
                }
287
                setApply(true);
288
            }
289

    
290
        });
291
        setSelections();
292

    
293
        return composite;
294
    }
295

    
296
    @Override
297
    public void widgetSelected(SelectionEvent e) {
298
        if (e.getSource().equals(nomenclaturalCodeSelectionCombo)){
299
            this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
300
        }
301
        if (e.getSource().equals(overrideCombo)) {
302
            override = overrideCombo.getText().equals(LocalOrDefaultEnum.Local.getLabel())?true:false;
303
        }
304
       // PreferencesUtil.recursiveSetEnabled(composite, override);
305
        setApply(true);
306

    
307
    }
308

    
309
    @Override
310
    public boolean performOk() {
311
        if (!isApply()){
312
            return true;
313
        }
314
        if (configurator != null){
315
            String configString = configurator.toString();
316

    
317

    
318
            if (override){
319
                PreferencesUtil.setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), configString);
320
                PreferencesUtil.setBooleanValue( PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), override);
321

    
322
            }else{
323
                PreferencesUtil.setBooleanValue( PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), override);
324
            }
325

    
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
    @Override
341
    protected void performDefaults() {
342
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
343
        override = true;
344
        setSelections();
345
        setApply(true);
346
    }
347

    
348
    @Override
349
    public void getValues() {
350
        isAdminPreference = false;
351
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
352
        ICdmRepository controller;
353
        controller = CdmStore.getCurrentApplicationConfiguration();
354
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
355
        preference = controller.getPreferenceService().find(key);
356

    
357
        if (preference != null ){
358
            allowOverride = preference.isAllowOverride();
359
        }else{
360
            preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
361
        }
362

    
363
        override = PreferencesUtil.getBooleanValue(
364
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true) != null? PreferencesUtil.getBooleanValue(
365
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true):false;
366

    
367
       configurator = PreferencesUtil.getLocalAbcdImportConfigurator();
368
    }
369

    
370
    protected void setSelections(){
371
        checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
372
        checkBoxIgnoreExisting.setSelection(configurator.isIgnoreImportOfExistingSpecimen());
373
        checkBoxIgnoreAuthorship.setSelection(configurator.isIgnoreAuthorship());
374
        checkBoxMapUnitIdToCatalogNumber.setSelection(configurator.isMapUnitIdToCatalogNumber());
375
        checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
376
        checkBoxMapUnitIdToBarcode.setSelection(configurator.isMapUnitIdToBarcode());
377
        checkBoxRemoveCountry.setSelection(configurator.isRemoveCountryFromLocalityText());
378
        checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
379
        checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
380
        checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
381
        checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
382
        textDNAProviderString.setText(configurator.getDnaSoure().toString());
383
        int index = 0;
384
        if (configurator.getNomenclaturalCode() != null){
385
            for (String label : nomenclaturalCodeSelectionCombo.getItems()){
386
                if (label.equals(configurator.getNomenclaturalCode().getKey())){
387
                    nomenclaturalCodeSelectionCombo.select(index);
388
                }
389
                index++;
390
            }
391
        }else{
392
            nomenclaturalCodeSelectionCombo.select(index);
393
        }
394
        if (isAdminPreference){
395
            checkAllowOverride.setSelection(allowOverride || preference == null);
396
            if (preference == null){
397
                checkAllowOverride.setEnabled(false);
398
            }else{
399
                checkAllowOverride.setEnabled(true);
400
            }
401
        }else{
402
            checkAllowOverride.setSelection(override);
403
        }
404
    }
405

    
406
}
(1-1/52)