3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
;
12 import java
.util
.List
;
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
;
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
;
43 public class DeleteTaxonBaseConfiguratorComposite
extends Composite
implements SelectionListener
{
45 protected DataBindingContext m_bindingContext
;
47 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
48 protected final TaxonBaseDeletionConfigurator configurator
;
49 private final Button btnDeleteTaxonName
;
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
;
60 private Combo classificationSelectionCombo
;
63 Classification selectedClassification
;
64 private List
<Classification
> classifications
;
68 * Create the composite.
72 public DeleteTaxonBaseConfiguratorComposite(TaxonBaseDeletionConfigurator configurator
, Composite parent
, int style
) {
74 this.configurator
= configurator
;
75 addDisposeListener(new DisposeListener() {
77 public void widgetDisposed(DisposeEvent e
) {
81 toolkit
.paintBordersFor(this);
82 setLayout(new GridLayout());
83 setBackground(getBackground());
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() {
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
);
104 //DeleteConfigurator for the name
107 btnRemoveAllNameRelationships
= new Button(this, SWT
.CHECK
);
108 btnRemoveAllNameRelationships
.setText("Remove all name relations");
109 btnRemoveAllNameRelationships
.setSelection(true);
111 btnIgnoreIsBasionym
= new Button(this, SWT
.CHECK
);
112 btnIgnoreIsBasionym
.setText("Ignore if it is basionym");
113 btnIgnoreIsBasionym
.setSelection(true);
115 btnIgnoreIsReplacedSynonymFor
= new Button(this, SWT
.CHECK
);
116 btnIgnoreIsReplacedSynonymFor
.setText("Ignore if it is replaced synonym");
117 btnIgnoreIsReplacedSynonymFor
.setSelection(true);
119 btnIgnoreHasBasionym
= new Button(this, SWT
.CHECK
);
120 btnIgnoreHasBasionym
.setText("Ignore if it has basionym");
121 btnIgnoreHasBasionym
.setSelection(true);
123 btnIgnoreHasReplacedSynonym
= new Button(this, SWT
.CHECK
);
124 btnIgnoreHasReplacedSynonym
.setText("Ignore if it has replaced synonym");
125 btnIgnoreHasReplacedSynonym
.setSelection(true);
127 btnRemoveAllTypeDesignations
= new Button(this, SWT
.CHECK
);
128 btnRemoveAllTypeDesignations
.setText("Remove all type designations");
129 btnRemoveAllTypeDesignations
.setSelection(true);
133 // createClassificationSelectionCombo(this);
139 protected void initDataBindings() {
140 m_bindingContext
= new DataBindingContext();
142 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget
= WidgetProperties
.selection().observe(btnDeleteTaxonName
);
143 IObservableValue deleteNameIfPossibleConfiguratorObserveValue
= PojoProperties
.value("deleteNameIfPossible").observe(configurator
);
144 m_bindingContext
.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget
, deleteNameIfPossibleConfiguratorObserveValue
, null, null);
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);
151 IObservableValue observeSelectionbtnIgnoreIsBasionymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreIsBasionym
);
152 IObservableValue deleteIgnoreIsBasionymConfiguratorObserveValue
= PojoProperties
.value("ignoreIsBasionymFor").observe(nameConfig
);
153 m_bindingContext
.bindValue(observeSelectionbtnIgnoreIsBasionymObserveWidget
, deleteIgnoreIsBasionymConfiguratorObserveValue
, null, null);
155 IObservableValue observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreIsReplacedSynonymFor
);
156 IObservableValue deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue
= PojoProperties
.value("ignoreIsReplacedSynonymFor").observe(nameConfig
);
157 m_bindingContext
.bindValue(observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget
, deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue
, null, null);
159 IObservableValue observeSelectionbtnIgnoreHasBasionymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreHasBasionym
);
160 IObservableValue deleteIgnoreHasBasionymConfiguratorObserveValue
= PojoProperties
.value("ignoreHasBasionym").observe(nameConfig
);
161 m_bindingContext
.bindValue(observeSelectionbtnIgnoreHasBasionymObserveWidget
, deleteIgnoreHasBasionymConfiguratorObserveValue
, null, null);
163 IObservableValue observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreHasReplacedSynonym
);
164 IObservableValue deleteIgnoreHasReplacedSynonymConfiguratorObserveValue
= PojoProperties
.value("ignoreHasReplacedSynonym").observe(nameConfig
);
165 m_bindingContext
.bindValue(observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget
, deleteIgnoreHasReplacedSynonymConfiguratorObserveValue
, null, null);
167 IObservableValue observeSelectionbtnRemoveAllTypeDesignationsObserveWidget
= WidgetProperties
.selection().observe(btnRemoveAllTypeDesignations
);
168 IObservableValue deleteRemoveAllTypeDesignationsConfiguratorObserveValue
= PojoProperties
.value("removeAllTypeDesignations").observe(nameConfig
);
169 m_bindingContext
.bindValue(observeSelectionbtnRemoveAllTypeDesignationsObserveWidget
, deleteRemoveAllTypeDesignationsConfiguratorObserveValue
, null, null);
174 /* private Control createClassificationSelectionCombo(Composite parent){
175 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
177 Composite classificationSelection = new Composite(parent, SWT.NULL);
178 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
180 GridLayout layout = new GridLayout();
181 classificationSelection.setLayout(layout);
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);
190 for(Classification tree : classifications){
191 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
195 classificationSelectionCombo.select(0);
196 classificationSelectionCombo.addSelectionListener(this);
198 return classificationSelection;
202 public void widgetSelected(SelectionEvent e
) {
203 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
207 public void widgetDefaultSelected(SelectionEvent e
) {
208 // TODO Auto-generated method stub