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 org
.eclipse
.core
.databinding
.DataBindingContext
;
13 import org
.eclipse
.core
.databinding
.beans
.PojoProperties
;
14 import org
.eclipse
.core
.databinding
.observable
.value
.IObservableValue
;
15 import org
.eclipse
.jface
.databinding
.swt
.WidgetProperties
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.events
.DisposeEvent
;
18 import org
.eclipse
.swt
.events
.DisposeListener
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.layout
.RowLayout
;
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
.Control
;
26 import org
.eclipse
.swt
.widgets
.Display
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
30 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
31 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
40 public class DeleteTaxonConfiguratorComposite
extends Composite
{
41 private final DataBindingContext m_bindingContext
;
43 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
44 private final TaxonDeletionConfigurator configurator
;
45 private final Button btnDeleteTaxonName
;
46 private final Button btnDeleteInAllClassifications
;
47 private Combo classificationSelectionCombo
;
52 * Create the composite.
56 public DeleteTaxonConfiguratorComposite(TaxonDeletionConfigurator configurator
, Composite parent
, int style
) {
58 this.configurator
= configurator
;
59 addDisposeListener(new DisposeListener() {
61 public void widgetDisposed(DisposeEvent e
) {
65 toolkit
.paintBordersFor(this);
66 setLayout(new RowLayout(SWT
.VERTICAL
));
67 setBackground(getBackground());
69 btnDeleteTaxonName
= new Button(this, SWT
.CHECK
);
70 btnDeleteTaxonName
.setText("Delete taxon name if possible");
71 btnDeleteTaxonName
.setSelection(true);
73 btnDeleteInAllClassifications
= new Button(this, SWT
.CHECK
);
74 btnDeleteInAllClassifications
.setText("Delete taxon in all classifications");
75 btnDeleteInAllClassifications
.setSelection(true);
77 m_bindingContext
= initDataBindings();
81 protected DataBindingContext
initDataBindings() {
82 DataBindingContext bindingContext
= new DataBindingContext();
84 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget
= WidgetProperties
.selection().observe(btnDeleteTaxonName
);
85 IObservableValue deleteNameIfPossibleConfiguratorObserveValue
= PojoProperties
.value("deleteNameIfPossible").observe(configurator
);
87 IObservableValue observeSelectionBtnDeleteInAllClassificationObserveWidget
= WidgetProperties
.selection().observe(btnDeleteInAllClassifications
);
88 IObservableValue deleteInAllClassificationsConfiguratorObserveValue
= PojoProperties
.value("deleteInAllClassifications").observe(configurator
);
89 bindingContext
.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget
, deleteNameIfPossibleConfiguratorObserveValue
, null, null);
90 bindingContext
.bindValue(observeSelectionBtnDeleteInAllClassificationObserveWidget
, deleteInAllClassificationsConfiguratorObserveValue
, null, null);
92 return bindingContext
;
95 /* private Control createClassificationSelectionCombo(Composite parent){
96 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
98 Composite classificationSelection = new Composite(parent, SWT.NULL);
99 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
101 GridLayout layout = new GridLayout();
102 classificationSelection.setLayout(layout);
104 Label label = new Label(classificationSelection, SWT.NULL);
105 // TODO not working is not really true but leave it here to remind everyone that this is under construction
106 label.setText("Select Classification");
107 classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
108 classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
109 List<Classification> classifications =
111 for(Classification tree : classifications){
112 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
116 classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
118 // TODO remember last selection
119 classificationSelectionCombo.addSelectionListener(this);
123 return classificationSelection;