ref #8385: adapt local and db preference pages
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / AbcdImportConfiguratorWizardPage.java
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 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27
28 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
29 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
30 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
31 import eu.etaxonomy.taxeditor.databaseAdmin.wizard.AbstractPreferenceWizard;
32 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
33
34 /**
35 *
36 * @author pplitzner
37 *
38 */
39 public class AbcdImportConfiguratorWizardPage extends AbstractPreferenceWizard implements SelectionListener {
40
41 public static final String PAGE_NAME = "AbcdImportConfiguratorWizardPage";
42
43 private Abcd206ImportConfigurator abcdImportConfigurator;
44
45 private List<URI> biocaseProvider = new ArrayList<>();
46
47 private boolean isPreferencePage = false;
48
49 private Combo nomenclaturalCodeSelectionCombo;
50 private Text textDNAProviderString;
51
52 protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator) {
53 super(PAGE_NAME);
54 this.abcdImportConfigurator = configurator;
55 setTitle(title);
56 setDescription(description);
57 }
58
59 protected AbcdImportConfiguratorWizardPage(String title, String description, Abcd206ImportConfigurator configurator, boolean isPreferencePage) {
60 super(PAGE_NAME);
61 this.abcdImportConfigurator = configurator;
62 setTitle(title);
63 setDescription(description);
64 this.isPreferencePage = isPreferencePage;
65 }
66
67 public static AbcdImportConfiguratorWizardPage createPage(Abcd206ImportConfigurator configurator){
68 return new AbcdImportConfiguratorWizardPage("Configure import parameters",
69 "Tooltips will explain parameters in more detail", configurator);
70 }
71
72 public static AbcdImportConfiguratorWizardPage createPreferencePage(Abcd206ImportConfigurator configurator){
73 return new AbcdImportConfiguratorWizardPage("Configure import parameters",
74 "Tooltips will explain parameters in more detail", configurator, true);
75 }
76
77
78
79 /** {@inheritDoc} */
80 @Override
81 public void createControl(Composite parent) {
82 final Composite composite = new Composite(parent, SWT.NULL);
83 //composite = addTab(Messages.DatabasePreferencesPage_Define_Default_NomenclaturalCode);
84 GridLayout gridLayout = new GridLayout();
85 composite.setLayout(gridLayout);
86 // if (isPreferencePage){
87 // ListComponent list = new ListComponent(composite, composite.getStyle());
88 // }
89
90 Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
91 checkBoxMediaSpecimen.setSelection(abcdImportConfigurator.isAddMediaAsMediaSpecimen());
92 checkBoxMediaSpecimen.setText("Import media as media specimen");
93 checkBoxMediaSpecimen
94 .setToolTipText("Any media attached to a ABCD unit will be imported as a sub derivative of the specimen created from this unit");
95 checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
96 @Override
97 public void widgetSelected(SelectionEvent e) {
98 abcdImportConfigurator.setAddMediaAsMediaSpecimen(!abcdImportConfigurator.isAddMediaAsMediaSpecimen());
99 }
100 });
101
102 Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
103 checkBoxIgnoreExisting.setSelection(abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
104 checkBoxIgnoreExisting.setText("Do not import existing specimens");
105 checkBoxIgnoreExisting
106 .setToolTipText("Specimens that have previously been imported will be ignored in this import");
107 checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
108 @Override
109 public void widgetSelected(SelectionEvent e) {
110 abcdImportConfigurator.setIgnoreImportOfExistingSpecimen(!abcdImportConfigurator.isIgnoreImportOfExistingSpecimen());
111 }
112 });
113
114 Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
115 checkBoxIgnoreAuthorship.setSelection(abcdImportConfigurator.isIgnoreAuthorship());
116 checkBoxIgnoreAuthorship.setText("Ignore Authorship for name matching");
117 checkBoxIgnoreAuthorship
118 .setToolTipText("Name matching with existing names will be done without "
119 + "the authorship part of the name");
120 checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
121 @Override
122 public void widgetSelected(SelectionEvent e) {
123 abcdImportConfigurator.setIgnoreAuthorship(!abcdImportConfigurator.isIgnoreAuthorship());
124 }
125 });
126
127 Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
128 checkBoxMapUnitIdToCatalogNumber.setSelection(abcdImportConfigurator.isMapUnitIdToCatalogNumber());
129 checkBoxMapUnitIdToCatalogNumber.setText("Map UnitID to catalog number");
130 checkBoxMapUnitIdToCatalogNumber
131 .setToolTipText("The UnitID of every ABCD unit will be mapped the catalog number "
132 + "of the specimen");
133 checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
134 @Override
135 public void widgetSelected(SelectionEvent e) {
136 abcdImportConfigurator.setMapUnitIdToCatalogNumber(!abcdImportConfigurator.isMapUnitIdToCatalogNumber());
137 }
138 });
139 //TODO: only one of the mappings can be checked!
140 Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
141 checkBoxMapUnitIdToAccessionNumber.setSelection(abcdImportConfigurator.isMapUnitIdToAccessionNumber());
142 checkBoxMapUnitIdToAccessionNumber.setText("Map UnitID to accession number");
143 checkBoxMapUnitIdToAccessionNumber
144 .setToolTipText("The UnitID of every ABCD unit will be mapped the accession number "
145 + "of the specimen");
146 checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
147 @Override
148 public void widgetSelected(SelectionEvent e) {
149 abcdImportConfigurator.setMapUnitIdToAccessionNumber(!abcdImportConfigurator.isMapUnitIdToAccessionNumber());
150 }
151 });
152
153 Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
154 checkBoxMapUnitIdToBarcode.setSelection(abcdImportConfigurator.isMapUnitIdToBarcode());
155 checkBoxMapUnitIdToBarcode.setText("Map UnitID to barcode");
156 checkBoxMapUnitIdToBarcode
157 .setToolTipText("The UnitID of every ABCD unit will be mapped the barcode "
158 + "of the specimen");
159 checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
160 @Override
161 public void widgetSelected(SelectionEvent e) {
162 abcdImportConfigurator.setMapUnitIdToBarcode(!abcdImportConfigurator.isMapUnitIdToBarcode());
163 }
164 });
165
166 Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
167 checkBoxRemoveCountry.setSelection(abcdImportConfigurator.isRemoveCountryFromLocalityText());
168 checkBoxRemoveCountry.setText("Remove country from locality text");
169 checkBoxRemoveCountry
170 .setToolTipText("If the locality text contains information about the "
171 + "country which is additionally stored in other ABCD "
172 + "elements then it is removed from the locality text");
173 checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
174 @Override
175 public void widgetSelected(SelectionEvent e) {
176 abcdImportConfigurator.setRemoveCountryFromLocalityText(!abcdImportConfigurator.isRemoveCountryFromLocalityText());
177 }
178 });
179
180 Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
181 checkBoxMoveToDefaultClassification.setSelection(abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
182 checkBoxMoveToDefaultClassification.setText("Create new classification for new taxa");
183 checkBoxMoveToDefaultClassification
184 .setToolTipText("For taxa that do not exist in the data base "
185 + "a new classification will be created");
186 checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
187 @Override
188 public void widgetSelected(SelectionEvent e) {
189 abcdImportConfigurator.setMoveNewTaxaToDefaultClassification(!abcdImportConfigurator.isMoveNewTaxaToDefaultClassification());
190 }
191 });
192
193 Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
194 checkBoxImportSiblings.setSelection(abcdImportConfigurator.isGetSiblings());
195 checkBoxImportSiblings.setText("Import all children of cultures or tissue samples");
196 checkBoxImportSiblings
197 .setToolTipText("For a tissue sample or culture all children will be searched and imported");
198 checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
199 @Override
200 public void widgetSelected(SelectionEvent e) {
201 abcdImportConfigurator.setGetSiblings(checkBoxImportSiblings.getSelection());
202 }
203 });
204
205 Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
206 checkBoxAddIndividualsAssociations.setSelection(abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
207 checkBoxAddIndividualsAssociations.setText("Create an Individual Association for each Specimen");
208 checkBoxAddIndividualsAssociations
209 .setToolTipText("For each specimen associated to a taxon an indiviadual association to this taxon is created");
210 checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
211 @Override
212 public void widgetSelected(SelectionEvent e) {
213 abcdImportConfigurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!abcdImportConfigurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
214 }
215 });
216
217 Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
218 checkBoxReuseDescriptiveGroups.setSelection(abcdImportConfigurator.isReuseExistingDescriptiveGroups());
219 checkBoxReuseDescriptiveGroups.setText("Reuse existing descriptive group");
220 checkBoxReuseDescriptiveGroups
221 .setToolTipText("Reuse one of the existing descriptive groups or create a new one for every import");
222 checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
223 @Override
224 public void widgetSelected(SelectionEvent e) {
225 abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
226 }
227 });
228
229 Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
230 checkBoxReuseExistingTaxa.setSelection(abcdImportConfigurator.isReuseExistingTaxaWhenPossible());
231 checkBoxReuseExistingTaxa.setText("Reuse existing taxa when possible");
232 checkBoxReuseExistingTaxa
233 .setToolTipText("Reuse existing taxa when the name matches the identified name of the specimen");
234 checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
235 @Override
236 public void widgetSelected(SelectionEvent e) {
237 abcdImportConfigurator.setReuseExistingDescriptiveGroups(!abcdImportConfigurator.isReuseExistingDescriptiveGroups());
238 }
239 });
240
241 Label labelRef = new Label(composite, SWT.NONE);
242 labelRef.setText("Biocase provider for associated DNA");
243 new Label(composite, SWT.NONE);
244 textDNAProviderString = new Text(composite, SWT.NONE);
245 textDNAProviderString.setEnabled(true);
246 textDNAProviderString.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
247 if (abcdImportConfigurator.getDnaSoure() != null){
248 textDNAProviderString.setText(abcdImportConfigurator.getDnaSoure().toString());
249 }
250
251 GridData gridData = new GridData();
252 gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
253 gridData.horizontalIndent = 5;
254 // classificationSelection.setLayoutData(gridData);
255
256 nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
257 nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
258 for(NomenclaturalCode code: NomenclaturalCode.values()){
259 nomenclaturalCodeSelectionCombo.add(code.getKey());
260 }
261
262
263
264 // TODO remember last selection
265 nomenclaturalCodeSelectionCombo.addSelectionListener(this);
266 int index = 0;
267 if (abcdImportConfigurator.getNomenclaturalCode() != null){
268 for (String label : nomenclaturalCodeSelectionCombo.getItems()){
269 if (label.equals(abcdImportConfigurator.getNomenclaturalCode().getKey())){
270 nomenclaturalCodeSelectionCombo.select(index);
271 }
272 index++;
273 }
274 }
275
276 setControl(composite);
277 }
278
279 @Override
280 public void widgetSelected(SelectionEvent e) {
281 this.abcdImportConfigurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
282
283 }
284
285 public void saveConfigToPrefernceStore() {
286 PreferencesUtil.setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), abcdImportConfigurator.toString());
287
288
289 }
290
291 public String createConfigString(){
292 return abcdImportConfigurator.toString();
293
294 }
295
296
297
298 /* (non-Javadoc)
299 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
300 */
301 @Override
302 public void widgetDefaultSelected(SelectionEvent e) {
303 // TODO Auto-generated method stub
304
305 }
306
307 public void createAbcdImportConfig() {
308 this.abcdImportConfigurator = PreferencesUtil.getLocalAbcdImportConfigurator();
309
310 }
311 }