Project

General

Profile

« Previous | Next » 

Revision 905236e8

Added by Katja Luther over 4 years ago

ref #8385: adapt strucutre of db prefs to local prefs

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AbcdImportPreference.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.preference;
10 10

  
11
import java.net.URI;
12

  
13 11
import org.eclipse.swt.SWT;
14 12
import org.eclipse.swt.custom.CLabel;
15 13
import org.eclipse.swt.events.SelectionAdapter;
......
42 40
 */
43 41
public class AbcdImportPreference extends CdmPreferencePage implements IE4PreferencePage, SelectionListener {
44 42

  
45
    private Abcd206ImportConfigurator configurator;
43
    protected Abcd206ImportConfigurator configurator;
46 44

  
47
    private Combo nomenclaturalCodeSelectionCombo;
45
    protected Combo nomenclaturalCodeSelectionCombo;
48 46

  
49
    private boolean allowOverride = true;
50
    private boolean override = true;
51
    private CdmPreference preference = null;
47
    protected boolean allowOverride = true;
48
    protected boolean override = true;
49
    protected CdmPreference preference = null;
52 50
    Text textDNAProviderString;
53 51
    private Composite composite;
54 52
    Combo overrideCombo;
55 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

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

  
59

  
60

  
61

  
62 70
        getValues();
63 71

  
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);
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;
83 77
        }
84

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

  
78
        final Composite composite = new Composite(parent, SWT.NULL);
87 79
        GridLayout gridLayout = new GridLayout();
88 80
        composite.setLayout(gridLayout);
89
        Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
90
        checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
81

  
82
        final CLabel description = new CLabel(composite, SWT.NULL);
83
        description.setText(Messages.AbcdImportPreference_description);
84
        checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
91 85
        checkBoxMediaSpecimen.setText(Messages.AbcdImportPreference_media_as_mediaSpecimen);
92 86
        checkBoxMediaSpecimen
93 87
                .setToolTipText(Messages.AbcdImportPreference_media_as_subUnit);
......
99 93
            }
100 94
        });
101 95

  
102
        Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
103
        checkBoxIgnoreExisting.setSelection(configurator.isIgnoreImportOfExistingSpecimen());
96
        checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
97

  
104 98
        checkBoxIgnoreExisting.setText(Messages.AbcdImportPreference_not_import_existing_specimen);
105 99
        checkBoxIgnoreExisting
106 100
        .setToolTipText(Messages.AbcdImportPreference_not_import_existing_specimen_tooltip);
......
112 106
            }
113 107
        });
114 108

  
115
        Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
116
        checkBoxIgnoreAuthorship.setSelection(configurator.isIgnoreAuthorship());
109
        checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
110

  
117 111
        checkBoxIgnoreAuthorship.setText(Messages.AbcdImportPreference_ignore_author);
118 112
        checkBoxIgnoreAuthorship
119 113
        .setToolTipText(Messages.AbcdImportPreference_ignore_author_tooltip);
......
125 119
            }
126 120
        });
127 121

  
128
        Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
129
        checkBoxMapUnitIdToCatalogNumber.setSelection(configurator.isMapUnitIdToCatalogNumber());
122
        checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.RADIO);
123

  
130 124
        checkBoxMapUnitIdToCatalogNumber.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
131 125
        checkBoxMapUnitIdToCatalogNumber
132 126
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
......
138 132
            }
139 133
        });
140 134
//TODO: only one of the mappings can be checked!
141
        Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
142
        checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
135
        checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.RADIO);
136

  
143 137
        checkBoxMapUnitIdToAccessionNumber.setText(Messages.AbcdImportPreference_map_unit_number_to_accession_number);
144 138
        checkBoxMapUnitIdToAccessionNumber
145 139
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_accession_number_tooltip);
......
151 145
            }
152 146
        });
153 147

  
154
        Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
155
        checkBoxMapUnitIdToBarcode.setSelection(configurator.isMapUnitIdToBarcode());
148
        checkBoxMapUnitIdToBarcode = new Button(composite, SWT.RADIO);
149

  
156 150
        checkBoxMapUnitIdToBarcode.setText(Messages.AbcdImportPreference_map_unit_number_barcode);
157 151
        checkBoxMapUnitIdToBarcode
158 152
        .setToolTipText(Messages.AbcdImportPreference_map_unit_number_barcode_tooltip);
......
164 158
            }
165 159
        });
166 160

  
167
        Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
168
        checkBoxRemoveCountry.setSelection(configurator.isRemoveCountryFromLocalityText());
161
        checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
162

  
169 163
        checkBoxRemoveCountry.setText(Messages.AbcdImportPreference_remove_country_from_locality);
170 164
        checkBoxRemoveCountry
171 165
        .setToolTipText(Messages.AbcdImportPreference_remove_country_from_locality_tooltip);
......
177 171
            }
178 172
        });
179 173

  
180
        Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
174
        checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
181 175
        checkBoxMoveToDefaultClassification.setSelection(configurator.isMoveNewTaxaToDefaultClassification());
182 176
        checkBoxMoveToDefaultClassification.setText(Messages.AbcdImportPreference_create_new_classification_new_taxa);
183 177
        checkBoxMoveToDefaultClassification
......
190 184
            }
191 185
        });
192 186

  
193
        Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
194
        checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
187
        checkBoxImportSiblings = new Button(composite, SWT.CHECK);
188

  
195 189
        checkBoxImportSiblings.setText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues);
196 190
        checkBoxImportSiblings
197 191
            .setToolTipText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip);
......
203 197
            }
204 198
        });
205 199

  
206
        Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
207
        checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
200
        checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
201

  
208 202
        checkBoxAddIndividualsAssociations.setText(Messages.AbcdImportPreference_create_Individual_Association);
209 203
        checkBoxAddIndividualsAssociations
210 204
            .setToolTipText(Messages.AbcdImportPreference_create_Individual_Association_tooltip);
......
216 210
            }
217 211
        });
218 212

  
219
        Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
220
        checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
213
        checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
214

  
221 215
        checkBoxReuseDescriptiveGroups.setText(Messages.AbcdImportPreference_reuse_descriptive_group);
222 216
        checkBoxReuseDescriptiveGroups
223 217
            .setToolTipText(Messages.AbcdImportPreference_reuse_descriptive_group_tooltip);
......
229 223
            }
230 224
        });
231 225

  
232
        Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
233
        checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
226
        checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
227

  
234 228
        checkBoxReuseExistingTaxa.setText(Messages.AbcdImportPreference_reuse_existing_taxa);
235 229
        checkBoxReuseExistingTaxa
236 230
            .setToolTipText(Messages.AbcdImportPreference_reuse_existing_taxa_tooltip);
......
244 238

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

  
252 246
        GridData gridData = new GridData();
253 247
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
254 248
        gridData.horizontalIndent = 5;
255 249
//      classificationSelection.setLayoutData(gridData);
256

  
250
        Label nomenclaturalCodeLabel = new Label(composite, SWT.NONE);
251
        nomenclaturalCodeLabel.setText("Nomenclatural Code");
257 252
        nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
258 253
        nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
254
        nomenclaturalCodeSelectionCombo.add(" - ");
259 255
        for(NomenclaturalCode code: NomenclaturalCode.values()){
260 256
            nomenclaturalCodeSelectionCombo.add(code.getKey());
261 257
        }
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 258

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

  
272 260

  
273 261
        // TODO remember last selection
274 262
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
......
276 264
            allowOverride = preference.isAllowOverride();
277 265
        }
278 266

  
279
        if (!override){
280
            //composite.setEnabled(false);
281
            PreferencesUtil.recursiveSetEnabled(composite, override);
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);
282 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();
283 292

  
284 293
        return composite;
285 294
    }
......
292 301
        if (e.getSource().equals(overrideCombo)) {
293 302
            override = overrideCombo.getText().equals(LocalOrDefaultEnum.Local.getLabel())?true:false;
294 303
        }
295
        PreferencesUtil.recursiveSetEnabled(composite, override);
304
       // PreferencesUtil.recursiveSetEnabled(composite, override);
296 305
        setApply(true);
297 306

  
298 307
    }
......
331 340
    @Override
332 341
    protected void performDefaults() {
333 342
        configurator = Abcd206ImportConfigurator.NewInstance(null,null);
334
        preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
335
        preference.setAllowOverride(true);
336
        super.performDefaults();
343
        override = true;
344
        setSelections();
345
        setApply(true);
337 346
    }
338 347

  
339 348
    @Override
......
355 364
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true) != null? PreferencesUtil.getBooleanValue(
356 365
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey()), true):false;
357 366

  
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
                    }
367
       configurator = PreferencesUtil.getLocalAbcdImportConfigurator();
368
    }
411 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);
412 388
                }
389
                index++;
413 390
            }
391
        }else{
392
            nomenclaturalCodeSelectionCombo.select(index);
393
        }
394
        if (isAdminPreference){
395
            checkAllowOverride.setSelection(allowOverride);
396
        }else{
397
            checkAllowOverride.setSelection(override);
414 398
        }
415 399
    }
416 400

  

Also available in: Unified diff