1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 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.mvc;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.core.databinding.DataBindingContext;
|
15
|
import org.eclipse.core.databinding.beans.BeansObservables;
|
16
|
import org.eclipse.core.databinding.observable.value.IObservableValue;
|
17
|
import org.eclipse.jface.databinding.swt.SWTObservables;
|
18
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
19
|
import org.eclipse.swt.SWT;
|
20
|
import org.eclipse.swt.events.ModifyEvent;
|
21
|
import org.eclipse.swt.events.ModifyListener;
|
22
|
import org.eclipse.swt.layout.GridData;
|
23
|
import org.eclipse.swt.layout.GridLayout;
|
24
|
import org.eclipse.swt.widgets.Composite;
|
25
|
import org.eclipse.swt.widgets.Label;
|
26
|
import org.eclipse.swt.widgets.Text;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
31
|
|
32
|
/**
|
33
|
* @author pplitzner
|
34
|
* @date 23.06.2014
|
35
|
*
|
36
|
*/
|
37
|
public class OriginalLabelDataField extends Composite {
|
38
|
|
39
|
private DataBindingContext m_bindingContext;
|
40
|
private DerivedUnit derivedUnit = null;
|
41
|
private final Text originalLabelInfoText;
|
42
|
private CdmFormFactory formFactory;
|
43
|
|
44
|
public OriginalLabelDataField(Composite parent, int style, DerivedUnit newDerivedUnit, CdmFormFactory formFactory) {
|
45
|
this(parent, style);
|
46
|
setDerivedUnit(newDerivedUnit);
|
47
|
this.formFactory = formFactory;
|
48
|
}
|
49
|
|
50
|
public OriginalLabelDataField(Composite parent, int style) {
|
51
|
super(parent, style);
|
52
|
setLayout(new GridLayout(2, false));
|
53
|
|
54
|
new Label(this, SWT.NONE).setText("Original Label Data");
|
55
|
|
56
|
originalLabelInfoText = new Text(this, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
57
|
originalLabelInfoText.addModifyListener(new ModifyListener() {
|
58
|
@Override
|
59
|
public void modifyText(ModifyEvent e) {
|
60
|
if(formFactory!=null){
|
61
|
List<IPropertyChangeListener> propertyChangeListeners = formFactory.getPropertyChangeListeners();
|
62
|
for (IPropertyChangeListener iPropertyChangeListener : propertyChangeListeners) {
|
63
|
iPropertyChangeListener.propertyChange(new CdmPropertyChangeEvent(OriginalLabelDataField.this, e));
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
});
|
68
|
originalLabelInfoText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
69
|
|
70
|
if (derivedUnit != null) {
|
71
|
m_bindingContext = initDataBindings();
|
72
|
}
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
protected void checkSubclass() {
|
77
|
// Disable the check that prevents subclassing of SWT components
|
78
|
}
|
79
|
|
80
|
private DataBindingContext initDataBindings() {
|
81
|
IObservableValue originalLabelInfoObserveWidget = SWTObservables.observeText(originalLabelInfoText, SWT.Modify);
|
82
|
IObservableValue originalLabelInfoObserveValue = BeansObservables
|
83
|
.observeValue(derivedUnit, "originalLabelInfo");
|
84
|
//
|
85
|
DataBindingContext bindingContext = new DataBindingContext();
|
86
|
//
|
87
|
bindingContext.bindValue(originalLabelInfoObserveWidget, originalLabelInfoObserveValue, null, null);
|
88
|
//
|
89
|
return bindingContext;
|
90
|
}
|
91
|
|
92
|
public DerivedUnit getDerivedUnit() {
|
93
|
return derivedUnit;
|
94
|
}
|
95
|
|
96
|
public void setDerivedUnit(DerivedUnit newDerivedUnit) {
|
97
|
setDerivedUnit(newDerivedUnit, true);
|
98
|
}
|
99
|
|
100
|
public void setDerivedUnit(DerivedUnit newDerivedUnit, boolean update) {
|
101
|
derivedUnit = newDerivedUnit;
|
102
|
if (update) {
|
103
|
if (m_bindingContext != null) {
|
104
|
m_bindingContext.dispose();
|
105
|
m_bindingContext = null;
|
106
|
}
|
107
|
if (derivedUnit != null) {
|
108
|
m_bindingContext = initDataBindings();
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
|
113
|
}
|