Merge branch 'develop' of https://dev.e-taxonomy.eu/git/taxeditor into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / deleteConfigurator / DeleteTaxonConfiguratorComposite.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 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;
29
30 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
31 import eu.etaxonomy.cdm.common.CdmUtils;
32 import eu.etaxonomy.cdm.model.taxon.Classification;
33
34
35 /**
36 * @author pplitzner
37 * @date Feb 18, 2015
38 *
39 */
40 public class DeleteTaxonConfiguratorComposite extends Composite {
41 private final DataBindingContext m_bindingContext;
42
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;
48
49
50
51 /**
52 * Create the composite.
53 * @param parent
54 * @param style
55 */
56 public DeleteTaxonConfiguratorComposite(TaxonDeletionConfigurator configurator, Composite parent, int style) {
57 super(parent, style);
58 this.configurator = configurator;
59 addDisposeListener(new DisposeListener() {
60 @Override
61 public void widgetDisposed(DisposeEvent e) {
62 toolkit.dispose();
63 }
64 });
65 toolkit.paintBordersFor(this);
66 setLayout(new RowLayout(SWT.VERTICAL));
67 setBackground(getBackground());
68
69 btnDeleteTaxonName = new Button(this, SWT.CHECK);
70 btnDeleteTaxonName.setText("Delete taxon name if possible");
71 btnDeleteTaxonName.setSelection(true);
72
73 btnDeleteInAllClassifications = new Button(this, SWT.CHECK);
74 btnDeleteInAllClassifications.setText("Delete taxon in all classifications");
75 btnDeleteInAllClassifications.setSelection(true);
76
77 m_bindingContext = initDataBindings();
78
79 }
80
81 protected DataBindingContext initDataBindings() {
82 DataBindingContext bindingContext = new DataBindingContext();
83 //
84 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
85 IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
86
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);
91 //
92 return bindingContext;
93 }
94
95 /* private Control createClassificationSelectionCombo(Composite parent){
96 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
97
98 Composite classificationSelection = new Composite(parent, SWT.NULL);
99 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
100
101 GridLayout layout = new GridLayout();
102 classificationSelection.setLayout(layout);
103
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 =
110
111 for(Classification tree : classifications){
112 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
113
114 }
115
116 classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
117
118 // TODO remember last selection
119 classificationSelectionCombo.addSelectionListener(this);
120
121
122
123 return classificationSelection;
124 }*/
125 }