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
;
26 import org
.eclipse
.swt
.layout
.RowLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Combo
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Control
;
31 import org
.eclipse
.swt
.widgets
.Display
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
47 public class DeleteTaxonConfiguratorComposite
extends Composite
implements SelectionListener
{
48 private final DataBindingContext m_bindingContext
;
50 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
51 private final TaxonDeletionConfigurator configurator
;
52 private final Button btnDeleteTaxonName
;
53 private final Button btnDeleteInAllClassifications
;
54 private Combo classificationSelectionCombo
;
57 Classification selectedClassification
;
58 private List
<Classification
> classifications
;
62 * Create the composite.
66 public DeleteTaxonConfiguratorComposite(TaxonDeletionConfigurator configurator
, Composite parent
, int style
) {
68 this.configurator
= configurator
;
69 addDisposeListener(new DisposeListener() {
71 public void widgetDisposed(DisposeEvent e
) {
75 toolkit
.paintBordersFor(this);
76 setLayout(new GridLayout());
77 setBackground(getBackground());
79 btnDeleteTaxonName
= new Button(this, SWT
.CHECK
);
80 btnDeleteTaxonName
.setText("Delete taxon name if possible");
81 btnDeleteTaxonName
.setSelection(true);
83 btnDeleteInAllClassifications
= new Button(this, SWT
.CHECK
);
84 btnDeleteInAllClassifications
.setText("Delete taxon in all classifications");
85 btnDeleteInAllClassifications
.setSelection(true);
87 // createClassificationSelectionCombo(this);
89 m_bindingContext
= initDataBindings();
93 protected DataBindingContext
initDataBindings() {
94 DataBindingContext bindingContext
= new DataBindingContext();
96 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget
= WidgetProperties
.selection().observe(btnDeleteTaxonName
);
97 IObservableValue deleteNameIfPossibleConfiguratorObserveValue
= PojoProperties
.value("deleteNameIfPossible").observe(configurator
);
99 IObservableValue observeSelectionBtnDeleteInAllClassificationObserveWidget
= WidgetProperties
.selection().observe(btnDeleteInAllClassifications
);
100 IObservableValue deleteInAllClassificationsConfiguratorObserveValue
= PojoProperties
.value("deleteInAllClassifications").observe(configurator
);
101 bindingContext
.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget
, deleteNameIfPossibleConfiguratorObserveValue
, null, null);
102 bindingContext
.bindValue(observeSelectionBtnDeleteInAllClassificationObserveWidget
, deleteInAllClassificationsConfiguratorObserveValue
, null, null);
107 return bindingContext
;
110 /* private Control createClassificationSelectionCombo(Composite parent){
111 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
113 Composite classificationSelection = new Composite(parent, SWT.NULL);
114 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
116 GridLayout layout = new GridLayout();
117 classificationSelection.setLayout(layout);
119 Label label = new Label(classificationSelection, SWT.NULL);
120 // TODO not working is not really true but leave it here to remind everyone that this is under construction
121 label.setText("Select Classification");
122 classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
123 classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
124 classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
126 for(Classification tree : classifications){
127 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
131 classificationSelectionCombo.select(0);
132 classificationSelectionCombo.addSelectionListener(this);
134 return classificationSelection;
138 public void widgetSelected(SelectionEvent e
) {
139 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
143 public void widgetDefaultSelected(SelectionEvent e
) {
144 // TODO Auto-generated method stub