Project

General

Profile

Download (18.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.io.wizard;
11

    
12
import java.net.URI;
13
import java.util.ArrayList;
14
import java.util.List;
15

    
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Combo;
24
import org.eclipse.swt.widgets.Composite;
25

    
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
27
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
28
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.AbstractPreferenceWizard;
29
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
31

    
32
/**
33
 *
34
 * @author pplitzner
35
 *
36
 */
37
public class AbcdImportConfiguratorWizardPage extends AbstractPreferenceWizard implements SelectionListener {
38

    
39
	public static final String PAGE_NAME = "AbcdImportConfiguratorWizardPage";
40

    
41
	private Abcd206ImportConfigurator abcdImportConfigurator;
42

    
43
	private List<URI> biocaseProvider = new ArrayList<>();
44

    
45
	private boolean isPreferencePage = false;
46

    
47
    private Combo nomenclaturalCodeSelectionCombo;
48

    
49
	protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator) {
50
        super(PAGE_NAME);
51
        this.abcdImportConfigurator = configurator;
52
        setTitle(title);
53
        setDescription(description);
54
    }
55

    
56
	protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator, boolean isPreferencePage) {
57
		super(PAGE_NAME);
58
		this.abcdImportConfigurator = configurator;
59
		setTitle(title);
60
		setDescription(description);
61
		this.isPreferencePage = isPreferencePage;
62
	}
63

    
64
	public static AbcdImportConfiguratorWizardPage createPage(Abcd206ImportConfigurator configurator){
65
		return new AbcdImportConfiguratorWizardPage("Configure import parameters",
66
				"Tooltips will explain parameters in more detail", configurator);
67
	}
68

    
69
	public static AbcdImportConfiguratorWizardPage createPreferencePage(Abcd206ImportConfigurator configurator){
70
        return new AbcdImportConfiguratorWizardPage("Configure import parameters",
71
                "Tooltips will explain parameters in more detail", configurator, true);
72
    }
73

    
74

    
75

    
76
	/** {@inheritDoc} */
77
	@Override
78
    public void createControl(Composite parent) {
79
		final Composite composite = new Composite(parent, SWT.NULL);
80
		//composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
81
		GridLayout gridLayout = new GridLayout();
82
		composite.setLayout(gridLayout);
83
//        if (isPreferencePage){
84
//            ListComponent list = new ListComponent(composite, composite.getStyle());
85
//        }
86

    
87
		Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
88
		checkBoxMediaSpecimen.setSelection(abcdImportConfigurator.isAddMediaAsMediaSpecimen());
89
		checkBoxMediaSpecimen.setText("Import media as media specimen");
90
		checkBoxMediaSpecimen
91
				.setToolTipText("Any media attached to a ABCD unit will be imported as a sub derivative of the specimen created from this unit");
92
		checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
93
			@Override
94
			public void widgetSelected(SelectionEvent e) {
95
				abcdImportConfigurator.setAddMediaAsMediaSpecimen(!abcdImportConfigurator.isAddMediaAsMediaSpecimen());
96
			}
97
		});
98

    
99
		Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
100
		checkBoxIgnoreExisting.setSelection(abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
101
		checkBoxIgnoreExisting.setText("Do not import existing specimens");
102
		checkBoxIgnoreExisting
103
		.setToolTipText("Specimens that have previously been imported will be ignored in this import");
104
		checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
105
			@Override
106
			public void widgetSelected(SelectionEvent e) {
107
				abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(!abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
108
			}
109
		});
110

    
111
		Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
112
		checkBoxIgnoreAuthorship.setSelection(abcdImportConfigurator.isIgnoreAuthorship());
113
		checkBoxIgnoreAuthorship.setText("Ignore Authorship for name matching");
114
		checkBoxIgnoreAuthorship
115
		.setToolTipText("Name matching with existing names will be done without "
116
				+ "the authorship part of the name");
117
		checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
118
			@Override
119
			public void widgetSelected(SelectionEvent e) {
120
				abcdImportConfigurator.setIgnoreAuthorship(!abcdImportConfigurator.isIgnoreAuthorship());
121
			}
122
		});
123

    
124
		Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
125
		checkBoxMapUnitIdToCatalogNumber.setSelection(abcdImportConfigurator.isMapUnitIdToCatalogNumber());
126
		checkBoxMapUnitIdToCatalogNumber.setText("Map UnitID to catalog number");
127
		checkBoxMapUnitIdToCatalogNumber
128
		.setToolTipText("The UnitID of every ABCD unit will be mapped the catalog number "
129
				+ "of the specimen");
130
		checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
131
			@Override
132
			public void widgetSelected(SelectionEvent e) {
133
				abcdImportConfigurator.setMapUnitIdToCatalogNumber(!abcdImportConfigurator.isMapUnitIdToCatalogNumber());
134
			}
135
		});
136
//TODO: only one of the mappings can be checked!
137
		Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
138
		checkBoxMapUnitIdToAccessionNumber.setSelection(abcdImportConfigurator.isMapUnitIdToAccessionNumber());
139
		checkBoxMapUnitIdToAccessionNumber.setText("Map UnitID to accession number");
140
		checkBoxMapUnitIdToAccessionNumber
141
		.setToolTipText("The UnitID of every ABCD unit will be mapped the accession number "
142
				+ "of the specimen");
143
		checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
144
			@Override
145
			public void widgetSelected(SelectionEvent e) {
146
				abcdImportConfigurator.setMapUnitIdToAccessionNumber(!abcdImportConfigurator.isMapUnitIdToAccessionNumber());
147
			}
148
		});
149

    
150
		Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
151
		checkBoxMapUnitIdToBarcode.setSelection(abcdImportConfigurator.isMapUnitIdToBarcode());
152
		checkBoxMapUnitIdToBarcode.setText("Map UnitID to barcode");
153
		checkBoxMapUnitIdToBarcode
154
		.setToolTipText("The UnitID of every ABCD unit will be mapped the barcode "
155
				+ "of the specimen");
156
		checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
157
			@Override
158
			public void widgetSelected(SelectionEvent e) {
159
				abcdImportConfigurator.setMapUnitIdToBarcode(!abcdImportConfigurator.isMapUnitIdToBarcode());
160
			}
161
		});
162

    
163
		Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
164
		checkBoxRemoveCountry.setSelection(abcdImportConfigurator.isRemoveCountryFromLocalityText());
165
		checkBoxRemoveCountry.setText("Remove country from locality text");
166
		checkBoxRemoveCountry
167
		.setToolTipText("If the locality text contains information about the "
168
				+ "country which is additionally stored in other ABCD "
169
				+ "elements then it is removed from the locality text");
170
		checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
171
			@Override
172
			public void widgetSelected(SelectionEvent e) {
173
				abcdImportConfigurator.setRemoveCountryFromLocalityText(!abcdImportConfigurator.isRemoveCountryFromLocalityText());
174
			}
175
		});
176

    
177
		Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
178
		checkBoxMoveToDefaultClassification.setSelection(abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
179
		checkBoxMoveToDefaultClassification.setText("Create new classification for new taxa");
180
		checkBoxMoveToDefaultClassification
181
		.setToolTipText("For taxa that do not exist in the data base "
182
				+ "a new classification will be created");
183
		checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
184
			@Override
185
			public void widgetSelected(SelectionEvent e) {
186
				abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(!abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
187
			}
188
		});
189

    
190
		Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
191
		checkBoxImportSiblings.setSelection(abcdImportConfigurator.isGetSiblings());
192
		checkBoxImportSiblings.setText("Import all children of cultures or tissue samples");
193
		checkBoxImportSiblings
194
        	.setToolTipText("For a tissue sample or culture all children will be searched and imported");
195
		checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
196
            @Override
197
            public void widgetSelected(SelectionEvent e) {
198
                abcdImportConfigurator.setGetSiblings(checkBoxImportSiblings.getSelection());
199
            }
200
        });
201

    
202
        Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
203
        checkBoxAddIndividualsAssociations.setSelection(abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
204
        checkBoxAddIndividualsAssociations.setText("Create an Individual Association for each Specimen");
205
        checkBoxAddIndividualsAssociations
206
        	.setToolTipText("For each specimen associated to a taxon an indiviadual association to this taxon is created");
207
        checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
208
            @Override
209
            public void widgetSelected(SelectionEvent e) {
210
                abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
211
            }
212
        });
213

    
214
        Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
215
        checkBoxReuseDescriptiveGroups.setSelection(abcdImportConfigurator.isReuseExistingDescriptiveGroups());
216
        checkBoxReuseDescriptiveGroups.setText("Reuse existing descriptive group");
217
        checkBoxReuseDescriptiveGroups
218
        	.setToolTipText("Reuse one of the existing descriptive groups or create a new one for every import");
219
        checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
220
            @Override
221
            public void widgetSelected(SelectionEvent e) {
222
                abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
223
            }
224
        });
225

    
226
        Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
227
        checkBoxReuseExistingTaxa.setSelection(abcdImportConfigurator.isReuseExistingTaxaWhenPossible());
228
        checkBoxReuseExistingTaxa.setText("Reuse existing taxa when possible");
229
        checkBoxReuseExistingTaxa
230
        	.setToolTipText("Reuse existing taxa when the name matches the identified name of the specimen");
231
        checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
232
            @Override
233
            public void widgetSelected(SelectionEvent e) {
234
                abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
235
            }
236
        });
237

    
238
        GridData gridData = new GridData();
239
        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
240
        gridData.horizontalIndent = 5;
241
//      classificationSelection.setLayoutData(gridData);
242

    
243
        nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
244
        nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
245
        for(NomenclaturalCode code: NomenclaturalCode.values()){
246
            nomenclaturalCodeSelectionCombo.add(code.getKey());
247
        }
248

    
249

    
250

    
251
        // TODO remember last selection
252
        nomenclaturalCodeSelectionCombo.addSelectionListener(this);
253
        int index = 0;
254
        if (abcdImportConfigurator.getNomenclaturalCode() != null){
255
            for (String label : nomenclaturalCodeSelectionCombo.getItems()){
256
                if (label.equals(abcdImportConfigurator.getNomenclaturalCode().getKey())){
257
                    nomenclaturalCodeSelectionCombo.select(index);
258
                }
259
                index++;
260
            }
261
        }
262

    
263
		setControl(composite);
264
	}
265

    
266
	@Override
267
    public void widgetSelected(SelectionEvent e) {
268
        this.abcdImportConfigurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
269

    
270
    }
271

    
272
	 public void saveConfigToPrefernceStore() {
273
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS,
274
	                abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
275
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN,
276
                    abcdImportConfigurator.isAddMediaAsMediaSpecimen());
277
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS,
278
                    abcdImportConfigurator.isAllowReuseOtherClassifications());
279
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS,
280
                    abcdImportConfigurator.isDeduplicateClassifications());
281
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT,
282
                    abcdImportConfigurator.isRemoveCountryFromLocalityText());
283
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES,
284
                    abcdImportConfigurator.isDeduplicateReferences());
285
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS,
286
                    abcdImportConfigurator.isGetSiblings());
287
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP,
288
                    abcdImportConfigurator.isIgnoreAuthorship());
289
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN,
290
                    abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
291
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER,
292
                    abcdImportConfigurator.isMapUnitIdToAccessionNumber());
293
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE,
294
                    abcdImportConfigurator.isMapUnitIdToBarcode());
295
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER,
296
                    abcdImportConfigurator.isMapUnitIdToCatalogNumber());
297
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION,
298
                    abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
299
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN,
300
                    abcdImportConfigurator.isOverwriteExistingSpecimens());
301
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS,
302
                    abcdImportConfigurator.isReuseExistingDescriptiveGroups());
303
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA,
304
                    abcdImportConfigurator.isReuseExistingMetaData());
305
	        PreferencesUtil.setBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE,
306
                    abcdImportConfigurator.isReuseExistingTaxaWhenPossible());
307
	        if ( abcdImportConfigurator.getNomenclaturalCode() != null){
308
	            PreferencesUtil.setStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, abcdImportConfigurator.getNomenclaturalCode().getKey());
309
	        }
310

    
311

    
312
	    }
313

    
314
	 public String createConfigString(){
315
	    return abcdImportConfigurator.toString();
316

    
317
	 }
318

    
319

    
320

    
321
    /* (non-Javadoc)
322
     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
323
     */
324
    @Override
325
    public void widgetDefaultSelected(SelectionEvent e) {
326
        // TODO Auto-generated method stub
327

    
328
    }
329

    
330
    public void createAbcdImportConfig() {
331
        this.abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
332
        this.abcdImportConfigurator.setAddMediaAsMediaSpecimen(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
333
        this.abcdImportConfigurator.setAllowReuseOtherClassifications(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
334
        //this.abcdImportConfigurator.setClassificationUuid(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
335
        this.abcdImportConfigurator.setDeduplicateClassifications(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
336
        this.abcdImportConfigurator.setDeduplicateReferences(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
337
       // this.abcdImportConfigurator.setDefaultAuthor(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
338
        this.abcdImportConfigurator.setGetSiblings(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
339
        this.abcdImportConfigurator.setIgnoreAuthorship(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
340
        this.abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
341
        this.abcdImportConfigurator.setMapUnitIdToAccessionNumber(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
342
        this.abcdImportConfigurator.setMapUnitIdToBarcode(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
343
        this.abcdImportConfigurator.setMapUnitIdToCatalogNumber(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
344
        this.abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
345
        this.abcdImportConfigurator.setReuseExistingDescriptiveGroups(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
346
        this.abcdImportConfigurator.setReuseExistingTaxaWhenPossible(PreferencesUtil.getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
347

    
348
    }
349
}
(1-1/30)