3 * Copyright (C) 2014 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
.mvc
;
12 import java
.util
.List
;
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
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
36 public class OriginalLabelDataField
extends Composite
{
38 private DataBindingContext m_bindingContext
;
39 private eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit derivedUnit
= null;
40 private final Text originalLabelInfoText
;
41 private CdmFormFactory formFactory
;
43 public OriginalLabelDataField(Composite parent
, int style
, eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit newDerivedUnit
, CdmFormFactory formFactory
) {
45 setDerivedUnit(newDerivedUnit
);
46 this.formFactory
= formFactory
;
49 public OriginalLabelDataField(Composite parent
, int style
) {
51 setLayout(new GridLayout(2, false));
53 new Label(this, SWT
.NONE
).setText("Original Label Data");
55 originalLabelInfoText
= new Text(this, SWT
.BORDER
| SWT
.WRAP
| SWT
.MULTI
);
56 originalLabelInfoText
.addModifyListener(new ModifyListener() {
58 public void modifyText(ModifyEvent e
) {
59 if(formFactory
!=null){
60 List
<IPropertyChangeListener
> propertyChangeListeners
= formFactory
.getPropertyChangeListeners();
61 for (IPropertyChangeListener iPropertyChangeListener
: propertyChangeListeners
) {
62 iPropertyChangeListener
.propertyChange(new CdmPropertyChangeEvent(OriginalLabelDataField
.this, e
));
67 originalLabelInfoText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
69 if (derivedUnit
!= null) {
70 m_bindingContext
= initDataBindings();
75 protected void checkSubclass() {
76 // Disable the check that prevents subclassing of SWT components
79 private DataBindingContext
initDataBindings() {
80 IObservableValue originalLabelInfoObserveWidget
= SWTObservables
.observeText(originalLabelInfoText
, SWT
.Modify
);
81 IObservableValue originalLabelInfoObserveValue
= BeansObservables
82 .observeValue(derivedUnit
, "originalLabelInfo");
84 DataBindingContext bindingContext
= new DataBindingContext();
86 bindingContext
.bindValue(originalLabelInfoObserveWidget
, originalLabelInfoObserveValue
, null, null);
88 return bindingContext
;
91 public eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
getDerivedUnit() {
95 public void setDerivedUnit(eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit newDerivedUnit
) {
96 setDerivedUnit(newDerivedUnit
, true);
99 public void setDerivedUnit(eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit newDerivedUnit
, boolean update
) {
100 derivedUnit
= newDerivedUnit
;
102 if (m_bindingContext
!= null) {
103 m_bindingContext
.dispose();
104 m_bindingContext
= null;
106 if (derivedUnit
!= null) {
107 m_bindingContext
= initDataBindings();