2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
;
11 import java
.util
.List
;
13 import org
.eclipse
.core
.databinding
.DataBindingContext
;
14 import org
.eclipse
.core
.databinding
.beans
.PojoProperties
;
15 import org
.eclipse
.core
.databinding
.observable
.value
.IObservableValue
;
16 import org
.eclipse
.jface
.databinding
.swt
.WidgetProperties
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.DisposeEvent
;
19 import org
.eclipse
.swt
.events
.DisposeListener
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.events
.SelectionListener
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Combo
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.Event
;
29 import org
.eclipse
.swt
.widgets
.Listener
;
30 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
32 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
33 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonBaseDeletionConfigurator
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
42 public class DeleteTaxonBaseConfiguratorComposite
extends Composite
implements SelectionListener
{
44 protected DataBindingContext m_bindingContext
;
46 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
47 protected final TaxonBaseDeletionConfigurator configurator
;
48 private final Button btnDeleteTaxonName
;
52 private final Button btnRemoveAllNameRelationships
;
53 private final Button btnIgnoreIsBasionym
;
54 private final Button btnIgnoreIsReplacedSynonymFor
;
55 private final Button btnIgnoreHasBasionym
;
56 private final Button btnIgnoreHasReplacedSynonym
;
57 private final Button btnRemoveAllTypeDesignations
;
59 private Combo classificationSelectionCombo
;
62 Classification selectedClassification
;
63 private List
<Classification
> classifications
;
67 * Create the composite.
71 public DeleteTaxonBaseConfiguratorComposite(TaxonBaseDeletionConfigurator configurator
, Composite parent
, int style
) {
73 this.configurator
= configurator
;
74 addDisposeListener(new DisposeListener() {
76 public void widgetDisposed(DisposeEvent e
) {
80 toolkit
.paintBordersFor(this);
81 setLayout(new GridLayout());
82 setBackground(getBackground());
84 btnDeleteTaxonName
= new Button(this, SWT
.CHECK
);
85 btnDeleteTaxonName
.setText("Delete name if possible");
86 btnDeleteTaxonName
.setSelection(true);
87 btnDeleteTaxonName
.addListener(SWT
.Selection
, new Listener() {
89 public void handleEvent(Event e
) {
90 Button b
= (Button
) e
.widget
;
91 GridData data
= (GridData
) btnRemoveAllNameRelationships
.getLayoutData();
92 data
.exclude
= b
.getSelection();
93 btnRemoveAllNameRelationships
.setVisible(data
.exclude
);
94 btnIgnoreIsBasionym
.setVisible(data
.exclude
);
95 btnIgnoreIsReplacedSynonymFor
.setVisible(data
.exclude
);
96 btnIgnoreHasBasionym
.setVisible(data
.exclude
);
97 btnIgnoreHasReplacedSynonym
.setVisible(data
.exclude
);
98 btnRemoveAllTypeDesignations
.setVisible(data
.exclude
);
103 //DeleteConfigurator for the name
106 btnRemoveAllNameRelationships
= new Button(this, SWT
.CHECK
);
107 btnRemoveAllNameRelationships
.setText("Remove all name relations");
108 btnRemoveAllNameRelationships
.setSelection(true);
110 btnIgnoreIsBasionym
= new Button(this, SWT
.CHECK
);
111 btnIgnoreIsBasionym
.setText("Ignore if it is basionym");
112 btnIgnoreIsBasionym
.setSelection(true);
114 btnIgnoreIsReplacedSynonymFor
= new Button(this, SWT
.CHECK
);
115 btnIgnoreIsReplacedSynonymFor
.setText("Ignore if it is replaced synonym");
116 btnIgnoreIsReplacedSynonymFor
.setSelection(true);
118 btnIgnoreHasBasionym
= new Button(this, SWT
.CHECK
);
119 btnIgnoreHasBasionym
.setText("Ignore if it has basionym");
120 btnIgnoreHasBasionym
.setSelection(true);
122 btnIgnoreHasReplacedSynonym
= new Button(this, SWT
.CHECK
);
123 btnIgnoreHasReplacedSynonym
.setText("Ignore if it has replaced synonym");
124 btnIgnoreHasReplacedSynonym
.setSelection(true);
126 btnRemoveAllTypeDesignations
= new Button(this, SWT
.CHECK
);
127 btnRemoveAllTypeDesignations
.setText("Remove all type designations");
128 btnRemoveAllTypeDesignations
.setSelection(true);
132 // createClassificationSelectionCombo(this);
138 protected void initDataBindings() {
139 m_bindingContext
= new DataBindingContext();
141 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget
= WidgetProperties
.selection().observe(btnDeleteTaxonName
);
142 IObservableValue deleteNameIfPossibleConfiguratorObserveValue
= PojoProperties
.value("deleteNameIfPossible").observe(configurator
);
143 m_bindingContext
.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget
, deleteNameIfPossibleConfiguratorObserveValue
, null, null);
145 NameDeletionConfigurator nameConfig
= configurator
.getNameDeletionConfig();
146 IObservableValue observeSelectionbtnRemoveAllNameRelationshipsObserveWidget
= WidgetProperties
.selection().observe(btnRemoveAllNameRelationships
);
147 IObservableValue deleteRemoveAllNameRelationshipsConfiguratorObserveValue
= PojoProperties
.value("removeAllNameRelationships").observe(nameConfig
);
148 m_bindingContext
.bindValue(observeSelectionbtnRemoveAllNameRelationshipsObserveWidget
, deleteRemoveAllNameRelationshipsConfiguratorObserveValue
, null, null);
150 IObservableValue observeSelectionbtnIgnoreIsBasionymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreIsBasionym
);
151 IObservableValue deleteIgnoreIsBasionymConfiguratorObserveValue
= PojoProperties
.value("ignoreIsBasionymFor").observe(nameConfig
);
152 m_bindingContext
.bindValue(observeSelectionbtnIgnoreIsBasionymObserveWidget
, deleteIgnoreIsBasionymConfiguratorObserveValue
, null, null);
154 IObservableValue observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreIsReplacedSynonymFor
);
155 IObservableValue deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue
= PojoProperties
.value("ignoreIsReplacedSynonymFor").observe(nameConfig
);
156 m_bindingContext
.bindValue(observeSelectionbtnIgnoreIsReplacedSynonymForObserveWidget
, deleteIgnoreIsReplacedSynonymForConfiguratorObserveValue
, null, null);
158 IObservableValue observeSelectionbtnIgnoreHasBasionymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreHasBasionym
);
159 IObservableValue deleteIgnoreHasBasionymConfiguratorObserveValue
= PojoProperties
.value("ignoreHasBasionym").observe(nameConfig
);
160 m_bindingContext
.bindValue(observeSelectionbtnIgnoreHasBasionymObserveWidget
, deleteIgnoreHasBasionymConfiguratorObserveValue
, null, null);
162 IObservableValue observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget
= WidgetProperties
.selection().observe(btnIgnoreHasReplacedSynonym
);
163 IObservableValue deleteIgnoreHasReplacedSynonymConfiguratorObserveValue
= PojoProperties
.value("ignoreHasReplacedSynonym").observe(nameConfig
);
164 m_bindingContext
.bindValue(observeSelectionbtnIgnoreHasReplacedSynonymObserveWidget
, deleteIgnoreHasReplacedSynonymConfiguratorObserveValue
, null, null);
166 IObservableValue observeSelectionbtnRemoveAllTypeDesignationsObserveWidget
= WidgetProperties
.selection().observe(btnRemoveAllTypeDesignations
);
167 IObservableValue deleteRemoveAllTypeDesignationsConfiguratorObserveValue
= PojoProperties
.value("removeAllTypeDesignations").observe(nameConfig
);
168 m_bindingContext
.bindValue(observeSelectionbtnRemoveAllTypeDesignationsObserveWidget
, deleteRemoveAllTypeDesignationsConfiguratorObserveValue
, null, null);
173 /* private Control createClassificationSelectionCombo(Composite parent){
174 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
176 Composite classificationSelection = new Composite(parent, SWT.NULL);
177 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
179 GridLayout layout = new GridLayout();
180 classificationSelection.setLayout(layout);
182 Label label = new Label(classificationSelection, SWT.NULL);
183 // TODO not working is not really true but leave it here to remind everyone that this is under construction
184 label.setText("Select Classification");
185 classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
186 classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
187 classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
189 for(Classification tree : classifications){
190 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
194 classificationSelectionCombo.select(0);
195 classificationSelectionCombo.addSelectionListener(this);
197 return classificationSelection;
201 public void widgetSelected(SelectionEvent e
) {
202 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
206 public void widgetDefaultSelected(SelectionEvent e
) {
207 // TODO Auto-generated method stub