Merge branch 'release/3.12.0'
[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 java.util.List;
13
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
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;
34
35 import eu.etaxonomy.cdm.api.service.IClassificationService;
36 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
37
38 import eu.etaxonomy.cdm.model.taxon.Classification;
39 import eu.etaxonomy.taxeditor.store.CdmStore;
40
41
42 /**
43 * @author pplitzner
44 * @date Feb 18, 2015
45 *
46 */
47 public class DeleteTaxonConfiguratorComposite extends Composite implements SelectionListener{
48 private final DataBindingContext m_bindingContext;
49
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;
55 private
56
57 Classification selectedClassification;
58 private List<Classification> classifications;
59
60
61 /**
62 * Create the composite.
63 * @param parent
64 * @param style
65 */
66 public DeleteTaxonConfiguratorComposite(TaxonDeletionConfigurator configurator, Composite parent, int style) {
67 super(parent, style);
68 this.configurator = configurator;
69 addDisposeListener(new DisposeListener() {
70 @Override
71 public void widgetDisposed(DisposeEvent e) {
72 toolkit.dispose();
73 }
74 });
75 toolkit.paintBordersFor(this);
76 setLayout(new GridLayout());
77 setBackground(getBackground());
78
79 btnDeleteTaxonName = new Button(this, SWT.CHECK);
80 btnDeleteTaxonName.setText("Delete taxon name if possible");
81 btnDeleteTaxonName.setSelection(true);
82
83 btnDeleteInAllClassifications = new Button(this, SWT.CHECK);
84 btnDeleteInAllClassifications.setText("Delete taxon in all classifications");
85 btnDeleteInAllClassifications.setSelection(true);
86
87 // createClassificationSelectionCombo(this);
88
89 m_bindingContext = initDataBindings();
90
91 }
92
93 protected DataBindingContext initDataBindings() {
94 DataBindingContext bindingContext = new DataBindingContext();
95 //
96 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
97 IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
98
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);
103
104
105
106 //
107 return bindingContext;
108 }
109
110 /* private Control createClassificationSelectionCombo(Composite parent){
111 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
112
113 Composite classificationSelection = new Composite(parent, SWT.NULL);
114 classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
115
116 GridLayout layout = new GridLayout();
117 classificationSelection.setLayout(layout);
118
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);
125
126 for(Classification tree : classifications){
127 classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
128
129 }
130
131 classificationSelectionCombo.select(0);
132 classificationSelectionCombo.addSelectionListener(this);
133
134 return classificationSelection;
135 }*/
136
137 @Override
138 public void widgetSelected(SelectionEvent e) {
139 selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
140 }
141
142 @Override
143 public void widgetDefaultSelected(SelectionEvent e) {
144 // TODO Auto-generated method stub
145
146 }
147 }