cd481441dd679b667ca8b041e669bf77ed29101b
[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.RowLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.ui.forms.widgets.FormToolkit;
24
25 import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
26
27 /**
28 * @author pplitzner
29 * @date Feb 18, 2015
30 *
31 */
32 public class DeleteTaxonConfiguratorComposite extends Composite {
33 private final DataBindingContext m_bindingContext;
34
35 private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
36 private final TaxonBaseDeletionConfigurator configurator;
37 private final Button btnDeleteTaxonName;
38
39 /**
40 * Create the composite.
41 * @param parent
42 * @param style
43 */
44 public DeleteTaxonConfiguratorComposite(TaxonBaseDeletionConfigurator configurator, Composite parent, int style) {
45 super(parent, style);
46 this.configurator = configurator;
47 addDisposeListener(new DisposeListener() {
48 @Override
49 public void widgetDisposed(DisposeEvent e) {
50 toolkit.dispose();
51 }
52 });
53 toolkit.paintBordersFor(this);
54 setLayout(new RowLayout(SWT.VERTICAL));
55 setBackground(getBackground());
56
57 btnDeleteTaxonName = new Button(this, SWT.CHECK);
58 btnDeleteTaxonName.setText("Delete taxon name if possible");
59 m_bindingContext = initDataBindings();
60
61 }
62
63 protected DataBindingContext initDataBindings() {
64 DataBindingContext bindingContext = new DataBindingContext();
65 //
66 IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
67 IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
68 bindingContext.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget, deleteNameIfPossibleConfiguratorObserveValue, null, null);
69 //
70 return bindingContext;
71 }
72 }