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.apache.commons.lang.StringUtils;
|
17
|
import org.eclipse.jface.layout.GridDataFactory;
|
18
|
import org.eclipse.jface.layout.GridLayoutFactory;
|
19
|
import org.eclipse.swt.SWT;
|
20
|
import org.eclipse.swt.events.SelectionAdapter;
|
21
|
import org.eclipse.swt.events.SelectionEvent;
|
22
|
import org.eclipse.swt.events.SelectionListener;
|
23
|
import org.eclipse.swt.layout.GridData;
|
24
|
import org.eclipse.swt.layout.GridLayout;
|
25
|
import org.eclipse.swt.widgets.Button;
|
26
|
import org.eclipse.swt.widgets.Combo;
|
27
|
import org.eclipse.swt.widgets.Composite;
|
28
|
import org.eclipse.swt.widgets.Label;
|
29
|
|
30
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
32
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
33
|
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.AbstractPreferenceWizard;
|
34
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
35
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
36
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
37
|
|
38
|
/**
|
39
|
*
|
40
|
* @author pplitzner
|
41
|
*
|
42
|
*/
|
43
|
public class AbcdImportConfiguratorWizardPage extends AbstractPreferenceWizard implements SelectionListener {
|
44
|
|
45
|
public static final String PAGE_NAME = "AbcdImportConfiguratorWizardPage";
|
46
|
|
47
|
private static final String ACCESSION_NUMBER = "Accession number";
|
48
|
|
49
|
private static final String BARCODE = "Barcode";
|
50
|
|
51
|
private static final String CATALOGUE_NUMBER = "Catalogue number";
|
52
|
|
53
|
private Abcd206ImportConfigurator abcdImportConfigurator;
|
54
|
|
55
|
private List<URI> biocaseProvider = new ArrayList<>();
|
56
|
|
57
|
private boolean isFileImport = false;
|
58
|
private boolean isPreferencePage = false;
|
59
|
|
60
|
private Combo nomenclaturalCodeSelectionCombo;
|
61
|
private Combo checkBoxMapUnitId;
|
62
|
private Combo textDNAProviderString;
|
63
|
|
64
|
protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator) {
|
65
|
this(title, description, configurator, false, false);
|
66
|
}
|
67
|
|
68
|
protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator, boolean isPreferencePage, boolean isFileImport) {
|
69
|
super(PAGE_NAME);
|
70
|
this.abcdImportConfigurator = configurator;
|
71
|
setTitle(title);
|
72
|
setDescription(description);
|
73
|
this.isPreferencePage = isPreferencePage;
|
74
|
this.isFileImport = isFileImport;
|
75
|
}
|
76
|
|
77
|
public static AbcdImportConfiguratorWizardPage createPage(Abcd206ImportConfigurator configurator){
|
78
|
return new AbcdImportConfiguratorWizardPage("Configure import parameters",
|
79
|
"Tooltips will explain parameters in more detail", configurator);
|
80
|
}
|
81
|
public static AbcdImportConfiguratorWizardPage createFileImportPage(Abcd206ImportConfigurator configurator){
|
82
|
return new AbcdImportConfiguratorWizardPage("Configure import parameters",
|
83
|
"Tooltips will explain parameters in more detail", configurator, false, true);
|
84
|
}
|
85
|
|
86
|
public static AbcdImportConfiguratorWizardPage createPreferencePage(Abcd206ImportConfigurator configurator){
|
87
|
return new AbcdImportConfiguratorWizardPage("Configure import parameters",
|
88
|
"Tooltips will explain parameters in more detail", configurator, true, false);
|
89
|
}
|
90
|
|
91
|
|
92
|
|
93
|
/** {@inheritDoc} */
|
94
|
@Override
|
95
|
public void createControl(Composite parent) {
|
96
|
final Composite composite = new Composite(parent, SWT.NULL);
|
97
|
//composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
|
98
|
GridLayout gridLayout = new GridLayout();
|
99
|
composite.setLayout(gridLayout);
|
100
|
// if (isPreferencePage){
|
101
|
// ListComponent list = new ListComponent(composite, composite.getStyle());
|
102
|
// }
|
103
|
|
104
|
Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
|
105
|
checkBoxMediaSpecimen.setSelection(abcdImportConfigurator.isAddMediaAsMediaSpecimen());
|
106
|
checkBoxMediaSpecimen.setText("Import media as media specimen");
|
107
|
checkBoxMediaSpecimen
|
108
|
.setToolTipText("Any media attached to a ABCD unit will be imported as a sub derivative of the specimen created from this unit");
|
109
|
checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
|
110
|
@Override
|
111
|
public void widgetSelected(SelectionEvent e) {
|
112
|
abcdImportConfigurator.setAddMediaAsMediaSpecimen(!abcdImportConfigurator.isAddMediaAsMediaSpecimen());
|
113
|
}
|
114
|
});
|
115
|
|
116
|
Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
|
117
|
checkBoxIgnoreExisting.setSelection(abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
|
118
|
checkBoxIgnoreExisting.setText("Do not import existing specimens");
|
119
|
checkBoxIgnoreExisting
|
120
|
.setToolTipText("Specimens that have previously been imported will be ignored in this import");
|
121
|
checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
|
122
|
@Override
|
123
|
public void widgetSelected(SelectionEvent e) {
|
124
|
abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(!abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
|
125
|
}
|
126
|
});
|
127
|
|
128
|
Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
|
129
|
checkBoxIgnoreAuthorship.setSelection(abcdImportConfigurator.isIgnoreAuthorship());
|
130
|
checkBoxIgnoreAuthorship.setText("Ignore Authorship for name matching");
|
131
|
checkBoxIgnoreAuthorship
|
132
|
.setToolTipText("Name matching with existing names will be done without "
|
133
|
+ "the authorship part of the name");
|
134
|
checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
|
135
|
@Override
|
136
|
public void widgetSelected(SelectionEvent e) {
|
137
|
abcdImportConfigurator.setIgnoreAuthorship(!abcdImportConfigurator.isIgnoreAuthorship());
|
138
|
}
|
139
|
});
|
140
|
|
141
|
Composite unitIdComposite = new Composite(composite, SWT.NULL);
|
142
|
GridLayout gridLayoutUnitId = new GridLayout();
|
143
|
gridLayoutUnitId.numColumns=2;
|
144
|
unitIdComposite.setLayout(gridLayoutUnitId);
|
145
|
|
146
|
Label unitIdLabel = new Label(unitIdComposite, SWT.NONE);
|
147
|
unitIdLabel.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
|
148
|
GridDataFactory.fillDefaults().applyTo(unitIdLabel);
|
149
|
checkBoxMapUnitId = new Combo(unitIdComposite, SWT.BORDER| SWT.READ_ONLY);
|
150
|
GridDataFactory.fillDefaults().applyTo(checkBoxMapUnitId);
|
151
|
checkBoxMapUnitId.add(ACCESSION_NUMBER);
|
152
|
checkBoxMapUnitId.add(BARCODE);
|
153
|
checkBoxMapUnitId.add(CATALOGUE_NUMBER);
|
154
|
checkBoxMapUnitId
|
155
|
.setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
|
156
|
checkBoxMapUnitId.addSelectionListener(this);
|
157
|
|
158
|
if (abcdImportConfigurator.isMapUnitIdToAccessionNumber()){
|
159
|
checkBoxMapUnitId.select(0);
|
160
|
}else if (abcdImportConfigurator.isMapUnitIdToBarcode()){
|
161
|
checkBoxMapUnitId.select(1);
|
162
|
}else {
|
163
|
checkBoxMapUnitId.select(2);
|
164
|
}
|
165
|
|
166
|
GridLayoutFactory.fillDefaults();
|
167
|
Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
|
168
|
checkBoxRemoveCountry.setSelection(abcdImportConfigurator.isRemoveCountryFromLocalityText());
|
169
|
checkBoxRemoveCountry.setText("Remove country from locality text");
|
170
|
checkBoxRemoveCountry
|
171
|
.setToolTipText("If the locality text contains information about the "
|
172
|
+ "country which is additionally stored in other ABCD "
|
173
|
+ "elements then it is removed from the locality text");
|
174
|
checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
|
175
|
@Override
|
176
|
public void widgetSelected(SelectionEvent e) {
|
177
|
abcdImportConfigurator.setRemoveCountryFromLocalityText(!abcdImportConfigurator.isRemoveCountryFromLocalityText());
|
178
|
}
|
179
|
});
|
180
|
|
181
|
Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
|
182
|
checkBoxMoveToDefaultClassification.setSelection(abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
|
183
|
checkBoxMoveToDefaultClassification.setText("Create new classification for new taxa");
|
184
|
checkBoxMoveToDefaultClassification
|
185
|
.setToolTipText("For taxa that do not exist in the data base "
|
186
|
+ "a new classification will be created");
|
187
|
checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
|
188
|
@Override
|
189
|
public void widgetSelected(SelectionEvent e) {
|
190
|
abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(!abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
|
191
|
}
|
192
|
});
|
193
|
|
194
|
Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
|
195
|
checkBoxImportSiblings.setSelection(abcdImportConfigurator.isGetSiblings());
|
196
|
checkBoxImportSiblings.setText("Import all children of cultures or tissue samples");
|
197
|
checkBoxImportSiblings
|
198
|
.setToolTipText("For a tissue sample or culture all children will be searched and imported");
|
199
|
checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
|
200
|
@Override
|
201
|
public void widgetSelected(SelectionEvent e) {
|
202
|
abcdImportConfigurator.setGetSiblings(checkBoxImportSiblings.getSelection());
|
203
|
}
|
204
|
});
|
205
|
|
206
|
Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
|
207
|
checkBoxAddIndividualsAssociations.setSelection(abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
|
208
|
checkBoxAddIndividualsAssociations.setText("Create an Individual Association for each Specimen");
|
209
|
checkBoxAddIndividualsAssociations
|
210
|
.setToolTipText("For each specimen associated to a taxon an indiviadual association to this taxon is created");
|
211
|
checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
|
212
|
@Override
|
213
|
public void widgetSelected(SelectionEvent e) {
|
214
|
abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
|
215
|
}
|
216
|
});
|
217
|
|
218
|
Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
|
219
|
checkBoxReuseDescriptiveGroups.setSelection(abcdImportConfigurator.isReuseExistingDescriptiveGroups());
|
220
|
checkBoxReuseDescriptiveGroups.setText("Reuse existing descriptive group");
|
221
|
checkBoxReuseDescriptiveGroups
|
222
|
.setToolTipText("Reuse one of the existing descriptive groups or create a new one for every import");
|
223
|
checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
|
224
|
@Override
|
225
|
public void widgetSelected(SelectionEvent e) {
|
226
|
abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
|
227
|
}
|
228
|
});
|
229
|
|
230
|
Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
|
231
|
checkBoxReuseExistingTaxa.setSelection(abcdImportConfigurator.isReuseExistingTaxaWhenPossible());
|
232
|
checkBoxReuseExistingTaxa.setText("Reuse existing taxa when possible");
|
233
|
checkBoxReuseExistingTaxa
|
234
|
.setToolTipText("Reuse existing taxa when the name matches the identified name of the specimen");
|
235
|
checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
|
236
|
@Override
|
237
|
public void widgetSelected(SelectionEvent e) {
|
238
|
abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
|
239
|
}
|
240
|
});
|
241
|
|
242
|
|
243
|
if (!isFileImport){
|
244
|
Composite dnaComposite = new Composite(composite, SWT.NULL);
|
245
|
GridLayout gridLayoutDna = new GridLayout();
|
246
|
gridLayoutDna.numColumns=2;
|
247
|
dnaComposite.setLayout(gridLayoutDna);
|
248
|
Label labelRef = new Label(dnaComposite, SWT.NONE);
|
249
|
labelRef.setText("Biocase provider for associated DNA");
|
250
|
new Label(dnaComposite, SWT.NONE);
|
251
|
textDNAProviderString = new Combo(dnaComposite, SWT.BORDER);
|
252
|
GridDataFactory.fillDefaults().applyTo(textDNAProviderString);
|
253
|
textDNAProviderString.add("Do not search for DNA");
|
254
|
|
255
|
String allProviderString = PreferencesUtil.getStringValue(PreferencePredicate.BioCaseProvider.getKey(), false);
|
256
|
if (StringUtils.isNotBlank(allProviderString)){
|
257
|
String[] providerArray = allProviderString.split(";"); //$NON-NLS-1$
|
258
|
for (String providerString : providerArray){
|
259
|
if (!StringUtils.isBlank(providerString)){
|
260
|
textDNAProviderString.add(providerString);
|
261
|
|
262
|
}
|
263
|
}
|
264
|
}
|
265
|
textDNAProviderString.setEnabled(true);
|
266
|
|
267
|
textDNAProviderString.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
|
268
|
if (abcdImportConfigurator.getDnaSoure() != null){
|
269
|
textDNAProviderString.select(0);
|
270
|
}
|
271
|
textDNAProviderString.addSelectionListener(this);
|
272
|
}else{
|
273
|
abcdImportConfigurator.setDnaSoure(null);
|
274
|
}
|
275
|
// GridData gridData = new GridData();
|
276
|
// gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
|
277
|
// gridData.horizontalIndent = 5;
|
278
|
// classificationSelection.setLayoutData(gridData);
|
279
|
Composite codeComposite = new Composite(composite, SWT.NULL);
|
280
|
|
281
|
codeComposite.setLayout(gridLayoutUnitId);
|
282
|
Label labelCode = new Label(codeComposite, SWT.NONE);
|
283
|
labelCode.setText("Nomenclatural Code");
|
284
|
GridDataFactory.fillDefaults().applyTo(labelCode);
|
285
|
nomenclaturalCodeSelectionCombo = new Combo(codeComposite, SWT.BORDER| SWT.READ_ONLY);
|
286
|
GridDataFactory.fillDefaults().applyTo(nomenclaturalCodeSelectionCombo);
|
287
|
for(NomenclaturalCode code: NomenclaturalCode.values()){
|
288
|
nomenclaturalCodeSelectionCombo.add(code.getKey());
|
289
|
}
|
290
|
|
291
|
|
292
|
|
293
|
// TODO remember last selection
|
294
|
nomenclaturalCodeSelectionCombo.addSelectionListener(this);
|
295
|
int index = 0;
|
296
|
if (abcdImportConfigurator.getNomenclaturalCode() != null){
|
297
|
for (String label : nomenclaturalCodeSelectionCombo.getItems()){
|
298
|
if (label.equals(abcdImportConfigurator.getNomenclaturalCode().getKey())){
|
299
|
nomenclaturalCodeSelectionCombo.select(index);
|
300
|
}
|
301
|
index++;
|
302
|
}
|
303
|
}
|
304
|
|
305
|
setControl(composite);
|
306
|
}
|
307
|
|
308
|
@Override
|
309
|
public void widgetSelected(SelectionEvent e) {
|
310
|
if (e.getSource().equals(nomenclaturalCodeSelectionCombo)){
|
311
|
this.abcdImportConfigurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
|
312
|
}
|
313
|
if (e.getSource().equals(checkBoxMapUnitId)){
|
314
|
String text = checkBoxMapUnitId.getText();
|
315
|
if (text.equals(ACCESSION_NUMBER)){
|
316
|
abcdImportConfigurator.setMapUnitIdToAccessionNumber(true);
|
317
|
abcdImportConfigurator.setMapUnitIdToBarcode(false);
|
318
|
abcdImportConfigurator.setMapUnitIdToCatalogNumber(false);
|
319
|
}else if (text.equals(BARCODE)){
|
320
|
abcdImportConfigurator.setMapUnitIdToAccessionNumber(false);
|
321
|
abcdImportConfigurator.setMapUnitIdToBarcode(true);
|
322
|
abcdImportConfigurator.setMapUnitIdToCatalogNumber(false);
|
323
|
}else{
|
324
|
abcdImportConfigurator.setMapUnitIdToAccessionNumber(false);
|
325
|
abcdImportConfigurator.setMapUnitIdToBarcode(false);
|
326
|
abcdImportConfigurator.setMapUnitIdToCatalogNumber(true);
|
327
|
}
|
328
|
}
|
329
|
if (e.getSource().equals(textDNAProviderString)){
|
330
|
String text = textDNAProviderString.getText();
|
331
|
try{
|
332
|
abcdImportConfigurator.setDnaSoure(URI.create(text));
|
333
|
}catch(IllegalArgumentException illegalArgument){
|
334
|
abcdImportConfigurator.setDnaSoure(null);
|
335
|
}
|
336
|
}
|
337
|
|
338
|
|
339
|
}
|
340
|
|
341
|
public void saveConfigToPrefernceStore() {
|
342
|
try{
|
343
|
abcdImportConfigurator.setDnaSoure(URI.create(textDNAProviderString.getText()));
|
344
|
}catch(IllegalArgumentException e){
|
345
|
//TODO: check prior or message
|
346
|
abcdImportConfigurator.setDnaSoure(null);
|
347
|
}
|
348
|
PreferencesUtil.setStringValue(IPreferenceKeys.LAST_USED_ABCD_CONFIG, abcdImportConfigurator.toString());
|
349
|
|
350
|
|
351
|
}
|
352
|
|
353
|
public String createConfigString(){
|
354
|
return abcdImportConfigurator.toString();
|
355
|
|
356
|
}
|
357
|
|
358
|
|
359
|
|
360
|
/* (non-Javadoc)
|
361
|
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
|
362
|
*/
|
363
|
@Override
|
364
|
public void widgetDefaultSelected(SelectionEvent e) {
|
365
|
// TODO Auto-generated method stub
|
366
|
|
367
|
}
|
368
|
|
369
|
public void createAbcdImportConfig() {
|
370
|
this.abcdImportConfigurator = PreferencesUtil.getLocalAbcdImportConfigurator(false);
|
371
|
|
372
|
}
|
373
|
}
|