smaller changes for specimen import and others
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / deleteConfigurator / DeleteTaxonBaseConfiguratorComposite.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator;
11
12 import java.util.List;
13
14 import org.eclipse.core.databinding.DataBindingContext;
15 import org.eclipse.core.databinding.beans.PojoProperties;
16 import org.eclipse.core.databinding.observable.value.IObservableValue;
17 import org.eclipse.jface.databinding.swt.WidgetProperties;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.DisposeEvent;
20 import org.eclipse.swt.events.DisposeListener;
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.Display;
29 import org.eclipse.swt.widgets.Event;
30 import org.eclipse.swt.widgets.Listener;
31 import org.eclipse.ui.forms.widgets.FormToolkit;
32
33 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
34 import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
35 import eu.etaxonomy.cdm.model.taxon.Classification;
36
37
38 /**
39 * @author pplitzner
40 * @date Feb 18, 2015
41 *
42 */
43 public class DeleteTaxonBaseConfiguratorComposite extends Composite implements SelectionListener{
44
45 protected DataBindingContext m_bindingContext;
46
47 private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
48 protected final TaxonBaseDeletionConfigurator configurator;
49 private final Button btnDeleteTaxonName;
50
51
52 //name related
53 private final Button btnRemoveAllNameRelationships;
54 private final Button btnIgnoreIsBasionym;
55 private final Button btnIgnoreIsReplacedSynonymFor;
56 private final Button btnIgnoreHasBasionym;
57 private final Button btnIgnoreHasReplacedSynonym;
58 private final Button btnRemoveAllTypeDesignations;
59
60 private Combo classificationSelectionCombo;
61
62
63 Classification selectedClassification;
64 private List<Classification> classifications;
65
66
67 /**
68 * Create the composite.
69 * @param parent
70 * @param style
71 */
72 public DeleteTaxonBaseConfiguratorComposite(TaxonBaseDeletionConfigurator configurator, Composite parent, int style) {
73 super(parent, style);
74 this.configurator = configurator;
75 addDisposeListener(new DisposeListener() {
76 @Override
77 public void widgetDisposed(DisposeEvent e) {
78 toolkit.dispose();
79 }
80 });
81 toolkit.paintBordersFor(this);
82 setLayout(new GridLayout());
83 setBackground(getBackground());
84
85 btnDeleteTaxonName = new Button(this, SWT.CHECK);
86 btnDeleteTaxonName.setText("Delete name if possible");
87 btnDeleteTaxonName.setSelection(true);
88 btnDeleteTaxonName.addListener(SWT.Selection, new Listener() {
89 @Override
90 public void handleEvent(Event e) {
91 Button b = (Button) e.widget;
92 GridData data = (GridData) btnRemoveAllNameRelationships.getLayoutData();
93 data.exclude = b.getSelection();
94 btnRemoveAllNameRelationships.setVisible(data.exclude);
95 btnIgnoreIsBasionym.setVisible(data.exclude);
96 btnIgnoreIsReplacedSynonymFor.setVisible(data.exclude);
97 btnIgnoreHasBasionym.setVisible(data.exclude);
98 btnIgnoreHasReplacedSynonym.setVisible(data.exclude);
99 btnRemoveAllTypeDesignations.setVisible(data.exclude);
100 }
101 });
102
103
104 //DeleteConfigurator for the name
105
106
107 btnRemoveAllNameRelationships = new Button(this, SWT.CHECK);
108 btnRemoveAllNameRelationships.setText("Remove all name relations");
109 btnRemoveAllNameRelationships.setSelection(true);
110
111 btnIgnoreIsBasionym = new Button(this, SWT.CHECK);
112 btnIgnoreIsBasionym.setText("Ignore if it is basionym");
113 btnIgnoreIsBasionym.setSelection(true);
114
115 btnIgnoreIsReplacedSynonymFor = new Button(this, SWT.CHECK);
116 btnIgnoreIsReplacedSynonymFor.setText("Ignore if it is replaced synonym");
117 btnIgnoreIsReplacedSynonymFor.setSelection(true);
118
119 btnIgnoreHasBasionym = new Button(this, SWT.CHECK);
120 btnIgnoreHasBasionym.setText("Ignore if it has basionym");
121 btnIgnoreHasBasionym.setSelection(true);
122
123 btnIgnoreHasReplacedSynonym = new Button(this, SWT.CHECK);
124 btnIgnoreHasReplacedSynonym.setText("Ignore if it has replaced synonym");
125 btnIgnoreHasReplacedSynonym.setSelection(true);
126
127 btnRemoveAllTypeDesignations = new Button(this, SWT.CHECK);
128 btnRemoveAllTypeDesignations.setText("Remove all type designations");
129 btnRemoveAllTypeDesignations.setSelection(true);
130
131
132
133 // createClassificationSelectionCombo(this);
134 initDataBindings();
135
136
137 }
138
139 protected void initDataBindings() {
140 m_bindingContext = new DataBindingContext();
141 //
142 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
143 IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
144 m_bindingContext.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget, deleteNameIfPossibleConfiguratorObserveValue, null, null);
145
146 NameDeletionConfigurator nameConfig = configurator.getNameDeletionConfig();
147 IObservableValue observeSelectionbtnRemoveAllNameRelationshipsObserveWidget = WidgetProperties.selection().observe(btnRemoveAllNameRelationships);
148 IObservableValue deleteRemoveAllNameRelationshipsConfiguratorObserveValue = PojoProperties.value("removeAllNameRelationships").observe(nameConfig);
149 m_bindingContext.bindValue(observeSelectionbtnRemoveAllNameRelationshipsObserveWidget, deleteRemoveAllNameRelationshipsConfiguratorObserveValue, null, null);
150
151 IObservableValue observeSelectionbtnIgnoreIsBasionymObserveWidget = WidgetProperties.selection().observe(btnIgnoreIsBasionym);
152 IObservableValue deleteIgnoreIsBasionymConfiguratorObserveValue = PojoProperties.value("ignoreIsBasionymFor").observe(nameConfig);
153 m_bindingContext.bindValue(observeSelectionbtnIgnoreIsBasionymObserveWidget, deleteIgnoreIsBasionymConfiguratorObserveValue, null, null);
154
155 IObservableValue observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget = WidgetProperties.selection().observe(btnIgnoreIsReplacedSynonymFor);
156 IObservableValue deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue = PojoProperties.value("ignoreIsReplacedSynonymFor").observe(nameConfig);
157 m_bindingContext.bindValue(observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget, deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue, null, null);
158
159 IObservableValue observeSelectionbtnIgnoreHasBasionymObserveWidget = WidgetProperties.selection().observe(btnIgnoreHasBasionym);
160 IObservableValue deleteIgnoreHasBasionymConfiguratorObserveValue = PojoProperties.value("ignoreHasBasionym").observe(nameConfig);
161 m_bindingContext.bindValue(observeSelectionbtnIgnoreHasBasionymObserveWidget, deleteIgnoreHasBasionymConfiguratorObserveValue, null, null);
162
163 IObservableValue observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget = WidgetProperties.selection().observe(btnIgnoreHasReplacedSynonym);
164 IObservableValue deleteIgnoreHasReplacedSynonymConfiguratorObserveValue = PojoProperties.value("ignoreHasReplacedSynonym").observe(nameConfig);
165 m_bindingContext.bindValue(observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget, deleteIgnoreHasReplacedSynonymConfiguratorObserveValue, null, null);
166
167 IObservableValue observeSelectionbtnRemoveAllTypeDesignationsObserveWidget = WidgetProperties.selection().observe(btnRemoveAllTypeDesignations);
168 IObservableValue deleteRemoveAllTypeDesignationsConfiguratorObserveValue = PojoProperties.value("removeAllTypeDesignations").observe(nameConfig);
169 m_bindingContext.bindValue(observeSelectionbtnRemoveAllTypeDesignationsObserveWidget, deleteRemoveAllTypeDesignationsConfiguratorObserveValue, null, null);
170
171
172 }
173
174 /* private Control createClassificationSelectionCombo(Composite parent){
175 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
176
177 Composite classificationSelection = new Composite(parent, SWT.NULL);
178 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
179
180 GridLayout layout = new GridLayout();
181 classificationSelection.setLayout(layout);
182
183 Label label = new Label(classificationSelection, SWT.NULL);
184 // TODO not working is not really true but leave it here to remind everyone that this is under construction
185 label.setText("Select Classification");
186 classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
187 classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
188 classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
189
190 for(Classification tree : classifications){
191 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
192
193 }
194
195 classificationSelectionCombo.select(0);
196 classificationSelectionCombo.addSelectionListener(this);
197
198 return classificationSelection;
199 }*/
200
201 @Override
202 public void widgetSelected(SelectionEvent e) {
203 selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
204 }
205
206 @Override
207 public void widgetDefaultSelected(SelectionEvent e) {
208 // TODO Auto-generated method stub
209
210 }
211 }