Comment unused method
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / AbcdImportPreference.java
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.databaseAdmin.preferencePage;
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
23 import eu.etaxonomy.cdm.api.application.ICdmRepository;
24 import eu.etaxonomy.cdm.api.service.IPreferenceService;
25 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
26 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
27 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
28 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
29 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
30 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
31 import eu.etaxonomy.taxeditor.l10n.Messages;
32 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
33 import eu.etaxonomy.taxeditor.store.CdmStore;
34
35 /**
36 * @author k.luther
37 * @since 23.03.2018
38 *
39 */
40 public class AbcdImportPreference extends CdmPreferencePage implements IE4AdminPreferencePage, SelectionListener {
41
42 private Abcd206ImportConfigurator configurator;
43
44 private Combo nomenclaturalCodeSelectionCombo;
45
46 private boolean allowOverride = true;
47 CdmPreference preference = null;
48
49 /**
50 * {@inheritDoc}
51 */
52 @Override
53 protected Control createContents(Composite parent) {
54 final Composite composite = new Composite(parent, SWT.NULL);
55
56 GridLayout gridLayout = new GridLayout();
57 composite.setLayout(gridLayout);
58 configurator = Abcd206ImportConfigurator.NewInstance(null,null);
59 ICdmRepository controller;
60 controller = CdmStore.getCurrentApplicationConfiguration();
61 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.AbcdImportConfig);
62
63 if (controller == null){
64 return null;
65 }
66 preference = controller.getPreferenceService().find(key);
67
68 if (preference != null ){
69 allowOverride = preference.isAllowOverride();
70 }else{
71 preference = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configurator.toString());
72 }
73
74 if (preference != null){
75
76 String configString = preference.getValue();
77 String[] configArray = configString.split(";");
78
79 for (String configItem: configArray){
80 String[] keyValue = configItem.split(":");
81 if(keyValue.length==2){
82 String keyString = keyValue[0];
83 String valueString = keyValue[1];
84 if (keyString.equals("ignoreImportOfExistingSpecimen")){
85 configurator.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
86 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
87 configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
88 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
89 configurator.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
90 }else if (keyString.equals("ignoreAuthorship")){
91 configurator.setIgnoreAuthorship(Boolean.valueOf(valueString));
92 }else if (keyString.equals("addMediaAsMediaSpecimen")){
93 configurator.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
94 }else if (keyString.equals("reuseExistingMetaData")){
95 configurator.setReuseExistingMetaData(Boolean.valueOf(valueString));
96 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
97 configurator.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
98 }else if (keyString.equals("allowReuseOtherClassifications")){
99 configurator.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
100 }else if (keyString.equals("deduplicateReferences")){
101 configurator.setDeduplicateReferences(Boolean.valueOf(valueString));
102 }else if (keyString.equals("deduplicateClassifications")){
103 configurator.setDeduplicateClassifications(Boolean.valueOf(valueString));
104 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
105 configurator.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
106 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
107 configurator.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
108 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
109 configurator.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
110 }else if (keyString.equals("mapUnitIdToBarcode")){
111 configurator.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
112 }else if (keyString.equals("overwriteExistingSpecimens")){
113 configurator.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
114 }else if (keyString.equals("nomenclaturalCode")){
115 configurator.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
116 }
117 }
118
119 }
120 }
121
122
123 //configurator = PreferencesUtil.getAbcdImportConfigurationPreference();
124 final CLabel description = new CLabel(composite, SWT.NULL);
125 description.setText(Messages.AbcdImportPreference_description);
126 Button checkBoxMediaSpecimen = new Button(composite, SWT.CHECK);
127 checkBoxMediaSpecimen.setSelection(configurator.isAddMediaAsMediaSpecimen());
128 checkBoxMediaSpecimen.setText(Messages.AbcdImportPreference_media_as_mediaSpecimen);
129 checkBoxMediaSpecimen
130 .setToolTipText(Messages.AbcdImportPreference_media_as_subUnit);
131 checkBoxMediaSpecimen.addSelectionListener(new SelectionAdapter() {
132 @Override
133 public void widgetSelected(SelectionEvent e) {
134 configurator.setAddMediaAsMediaSpecimen(!configurator.isAddMediaAsMediaSpecimen());
135 }
136 });
137
138 Button checkBoxIgnoreExisting = new Button(composite, SWT.CHECK);
139 checkBoxIgnoreExisting.setSelection(configurator.isIgnoreImportOfExistingSpecimen());
140 checkBoxIgnoreExisting.setText(Messages.AbcdImportPreference_not_import_existing_specimen);
141 checkBoxIgnoreExisting
142 .setToolTipText(Messages.AbcdImportPreference_not_import_existing_specimen_tooltip);
143 checkBoxIgnoreExisting.addSelectionListener(new SelectionAdapter() {
144 @Override
145 public void widgetSelected(SelectionEvent e) {
146 configurator.setIgnoreImportOfExistingSpecimen(!configurator.isIgnoreImportOfExistingSpecimen());
147 }
148 });
149
150 Button checkBoxIgnoreAuthorship = new Button(composite, SWT.CHECK);
151 checkBoxIgnoreAuthorship.setSelection(configurator.isIgnoreAuthorship());
152 checkBoxIgnoreAuthorship.setText(Messages.AbcdImportPreference_ignore_author);
153 checkBoxIgnoreAuthorship
154 .setToolTipText(Messages.AbcdImportPreference_ignore_author_tooltip);
155 checkBoxIgnoreAuthorship.addSelectionListener(new SelectionAdapter() {
156 @Override
157 public void widgetSelected(SelectionEvent e) {
158 configurator.setIgnoreAuthorship(!configurator.isIgnoreAuthorship());
159 }
160 });
161
162 Button checkBoxMapUnitIdToCatalogNumber = new Button(composite, SWT.CHECK);
163 checkBoxMapUnitIdToCatalogNumber.setSelection(configurator.isMapUnitIdToCatalogNumber());
164 checkBoxMapUnitIdToCatalogNumber.setText(Messages.AbcdImportPreference_map_unit_nr_catalog_number);
165 checkBoxMapUnitIdToCatalogNumber
166 .setToolTipText(Messages.AbcdImportPreference_map_unit_number_catalog_number_tooltip);
167 checkBoxMapUnitIdToCatalogNumber.addSelectionListener(new SelectionAdapter() {
168 @Override
169 public void widgetSelected(SelectionEvent e) {
170 configurator.setMapUnitIdToCatalogNumber(!configurator.isMapUnitIdToCatalogNumber());
171 }
172 });
173 //TODO: only one of the mappings can be checked!
174 Button checkBoxMapUnitIdToAccessionNumber = new Button(composite, SWT.CHECK);
175 checkBoxMapUnitIdToAccessionNumber.setSelection(configurator.isMapUnitIdToAccessionNumber());
176 checkBoxMapUnitIdToAccessionNumber.setText(Messages.AbcdImportPreference_map_unit_number_to_accession_number);
177 checkBoxMapUnitIdToAccessionNumber
178 .setToolTipText(Messages.AbcdImportPreference_map_unit_number_accession_number_tooltip);
179 checkBoxMapUnitIdToAccessionNumber.addSelectionListener(new SelectionAdapter() {
180 @Override
181 public void widgetSelected(SelectionEvent e) {
182 configurator.setMapUnitIdToAccessionNumber(!configurator.isMapUnitIdToAccessionNumber());
183 }
184 });
185
186 Button checkBoxMapUnitIdToBarcode = new Button(composite, SWT.CHECK);
187 checkBoxMapUnitIdToBarcode.setSelection(configurator.isMapUnitIdToBarcode());
188 checkBoxMapUnitIdToBarcode.setText(Messages.AbcdImportPreference_map_unit_number_barcode);
189 checkBoxMapUnitIdToBarcode
190 .setToolTipText(Messages.AbcdImportPreference_map_unit_number_barcode_tooltip);
191 checkBoxMapUnitIdToBarcode.addSelectionListener(new SelectionAdapter() {
192 @Override
193 public void widgetSelected(SelectionEvent e) {
194 configurator.setMapUnitIdToBarcode(!configurator.isMapUnitIdToBarcode());
195 }
196 });
197
198 Button checkBoxRemoveCountry = new Button(composite, SWT.CHECK);
199 checkBoxRemoveCountry.setSelection(configurator.isRemoveCountryFromLocalityText());
200 checkBoxRemoveCountry.setText(Messages.AbcdImportPreference_remove_country_from_locality);
201 checkBoxRemoveCountry
202 .setToolTipText(Messages.AbcdImportPreference_remove_country_from_locality_tooltip);
203 checkBoxRemoveCountry.addSelectionListener(new SelectionAdapter() {
204 @Override
205 public void widgetSelected(SelectionEvent e) {
206 configurator.setRemoveCountryFromLocalityText(!configurator.isRemoveCountryFromLocalityText());
207 }
208 });
209
210 Button checkBoxMoveToDefaultClassification = new Button(composite, SWT.CHECK);
211 checkBoxMoveToDefaultClassification.setSelection(configurator.isMoveNewTaxaToDefaultClassification());
212 checkBoxMoveToDefaultClassification.setText(Messages.AbcdImportPreference_create_new_classification_new_taxa);
213 checkBoxMoveToDefaultClassification
214 .setToolTipText(Messages.AbcdImportPreference_create_new_classification_new_taxa_tooltip);
215 checkBoxMoveToDefaultClassification.addSelectionListener(new SelectionAdapter() {
216 @Override
217 public void widgetSelected(SelectionEvent e) {
218 configurator.setMoveNewTaxaToDefaultClassification(!configurator.isMoveNewTaxaToDefaultClassification());
219 }
220 });
221
222 Button checkBoxImportSiblings = new Button(composite, SWT.CHECK);
223 checkBoxImportSiblings.setSelection(configurator.isGetSiblings());
224 checkBoxImportSiblings.setText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues);
225 checkBoxImportSiblings
226 .setToolTipText(Messages.AbcdImportPreference_import_all_children_for_cultures_or_tissues_tooltip);
227 checkBoxImportSiblings.addSelectionListener(new SelectionAdapter() {
228 @Override
229 public void widgetSelected(SelectionEvent e) {
230 configurator.setGetSiblings(checkBoxImportSiblings.getSelection());
231 }
232 });
233
234 Button checkBoxAddIndividualsAssociations = new Button(composite, SWT.CHECK);
235 checkBoxAddIndividualsAssociations.setSelection(configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
236 checkBoxAddIndividualsAssociations.setText(Messages.AbcdImportPreference_create_Individual_Association);
237 checkBoxAddIndividualsAssociations
238 .setToolTipText(Messages.AbcdImportPreference_create_Individual_Association_tooltip);
239 checkBoxAddIndividualsAssociations.addSelectionListener(new SelectionAdapter() {
240 @Override
241 public void widgetSelected(SelectionEvent e) {
242 configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(!configurator.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
243 }
244 });
245
246 Button checkBoxReuseDescriptiveGroups = new Button(composite, SWT.CHECK);
247 checkBoxReuseDescriptiveGroups.setSelection(configurator.isReuseExistingDescriptiveGroups());
248 checkBoxReuseDescriptiveGroups.setText(Messages.AbcdImportPreference_reuse_descriptive_group);
249 checkBoxReuseDescriptiveGroups
250 .setToolTipText(Messages.AbcdImportPreference_reuse_descriptive_group_tooltip);
251 checkBoxReuseDescriptiveGroups.addSelectionListener(new SelectionAdapter() {
252 @Override
253 public void widgetSelected(SelectionEvent e) {
254 configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
255 }
256 });
257
258 Button checkBoxReuseExistingTaxa = new Button(composite, SWT.CHECK);
259 checkBoxReuseExistingTaxa.setSelection(configurator.isReuseExistingTaxaWhenPossible());
260 checkBoxReuseExistingTaxa.setText(Messages.AbcdImportPreference_reuse_existing_taxa);
261 checkBoxReuseExistingTaxa
262 .setToolTipText(Messages.AbcdImportPreference_reuse_existing_taxa_tooltip);
263 checkBoxReuseExistingTaxa.addSelectionListener(new SelectionAdapter() {
264 @Override
265 public void widgetSelected(SelectionEvent e) {
266 configurator.setReuseExistingDescriptiveGroups(!configurator.isReuseExistingDescriptiveGroups());
267 }
268 });
269
270 GridData gridData = new GridData();
271 gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
272 gridData.horizontalIndent = 5;
273 // classificationSelection.setLayoutData(gridData);
274
275 nomenclaturalCodeSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
276 nomenclaturalCodeSelectionCombo.setLayoutData(gridData);
277 for(NomenclaturalCode code: NomenclaturalCode.values()){
278 nomenclaturalCodeSelectionCombo.add(code.getKey());
279 }
280 int index = 0;
281 if (configurator.getNomenclaturalCode() != null){
282 for (String label : nomenclaturalCodeSelectionCombo.getItems()){
283 if (label.equals(configurator.getNomenclaturalCode().getKey())){
284 nomenclaturalCodeSelectionCombo.select(index);
285 }
286 index++;
287 }
288 }
289
290 // TODO remember last selection
291 nomenclaturalCodeSelectionCombo.addSelectionListener(this);
292 if (preference != null){
293 allowOverride = preference.isAllowOverride();
294 }
295 Button checkAllowOverride = new Button(composite, SWT.CHECK);
296 checkAllowOverride.setSelection(allowOverride);
297 checkAllowOverride.setText(Messages.AbcdImportPreference_allow_override);
298 checkAllowOverride
299 .setToolTipText(Messages.AbcdImportPreference_allow_override_tooltip);
300 checkAllowOverride.addSelectionListener(new SelectionAdapter() {
301 @Override
302 public void widgetSelected(SelectionEvent e) {
303 allowOverride = !allowOverride;
304 }
305 });
306
307 return composite;
308 }
309
310 @Override
311 public void widgetSelected(SelectionEvent e) {
312 this.configurator.setNomenclaturalCode(NomenclaturalCode.getByKey(nomenclaturalCodeSelectionCombo.getText()));
313
314 }
315
316 @Override
317 public boolean performOk() {
318 if (preference == null){
319 return true;
320 }
321 if (configurator != null){
322 String configString = configurator.toString();
323
324 CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AbcdImportConfig, configString);
325 pref.setAllowOverride(allowOverride);
326
327 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
328 if (controller == null){
329 return false;
330 }
331 IPreferenceService service = controller.getPreferenceService();
332 service.set(pref);
333
334 }
335 return true;
336 }
337
338 /**
339 * {@inheritDoc}
340 */
341 @Override
342 public void widgetDefaultSelected(SelectionEvent e) {
343 // TODO Auto-generated method stub
344
345 }
346
347 // private void createAbcdImportConfig() {
348 // this.configurator.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
349 // this.configurator.setAddMediaAsMediaSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
350 // this.configurator.setAllowReuseOtherClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
351 // //this.abcdImportConfigurator.setClassificationUuid(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_CLASSIFICATION_UUID));
352 // this.configurator.setDeduplicateClassifications(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
353 // this.configurator.setDeduplicateReferences(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
354 // // this.abcdImportConfigurator.setDefaultAuthor(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEFAULT_AUTHOR));
355 // this.configurator.setGetSiblings(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
356 // this.configurator.setIgnoreAuthorship(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
357 // this.configurator.setIgnoreImportOfExistingSpecimen(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
358 // this.configurator.setMapUnitIdToAccessionNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
359 // this.configurator.setMapUnitIdToBarcode(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
360 // this.configurator.setMapUnitIdToCatalogNumber(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
361 // this.configurator.setMoveNewTaxaToDefaultClassification(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
362 // this.configurator.setReuseExistingDescriptiveGroups(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
363 // this.configurator.setReuseExistingTaxaWhenPossible(doGetPreferenceStore().getBoolean(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
364 // this.configurator.setNomenclaturalCode(PreferencesUtil.getPreferredNomenclaturalCode(doGetPreferenceStore().getString(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
365 //
366 // }
367
368 }