Project

General

Profile

Revision e458e14a

IDe458e14ab4ac1ae8e7a276970f5b35aa4b784b58
Parent 27ef27c0
Child b71d3062

Added by Patrick Plitzner over 6 years ago

  • changed "Original Label Data Field" to use data binding
    • added property change listener support for the field

View differences:

.gitattributes
1380 1380
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java -text
1381 1381
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MultilanguageTextElement.java -text
1382 1382
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/NumberWithLabelElement.java -text
1383
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OriginalLabelDataElement.java -text
1383 1384
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PartialElement.java -text
1384 1385
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PointElement.java -text
1385 1386
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/RootElement.java -text
......
1397 1398
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/AbstractCdmComposite.java -text
1398 1399
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/DerivedUnitGeneralDetailElementMVC.java -text
1399 1400
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/GeographicPointElement.java -text
1400
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataController.java -text
1401
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataElement.java -text
1401
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataField.java -text
1402 1402
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermCombo.java -text
1403 1403
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermComboController.java -text
1404 1404
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElement.java -text
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
58 58
 org.eclipse.jface.text,
59 59
 org.eclipse.ui.forms,
60 60
 eu.etaxonomy.taxeditor.cdmlib,
61
 org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0"
61
 org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0",
62
 org.eclipse.core.databinding,
63
 org.eclipse.core.databinding.beans,
64
 org.eclipse.core.databinding.observable,
65
 org.eclipse.core.databinding.property,
66
 org.eclipse.jface.databinding
62 67
Import-Package: org.eclipse.core.commands,
63 68
 org.eclipse.core.commands.operations,
64 69
 org.eclipse.core.expressions,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
99 99
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
100 100
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
101 101
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
102
import eu.etaxonomy.taxeditor.ui.mvc.OriginalLabelDataController;
103
import eu.etaxonomy.taxeditor.ui.mvc.OriginalLabelDataElement;
104 102
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
105 103
import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
106 104
import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
......
2152 2150
        return element;
2153 2151
    }
2154 2152

  
2153
    public OriginalLabelDataElement createOriginalLabelDataElement(ICdmFormElement parentElement) {
2154
        OriginalLabelDataElement element = new OriginalLabelDataElement(this, parentElement);
2155
        addAndAdaptElement(parentElement, element);
2156
        return element;
2157
    }
2158

  
2155 2159
    public PreservedSpecimenDetailElement createPreservedSpecimenDetailElement(ICdmFormElement parentElement) {
2156 2160
        PreservedSpecimenDetailElement element = new PreservedSpecimenDetailElement(this, parentElement);
2157 2161
        addAndAdaptElement(parentElement, element);
......
2722 2726
        return section;
2723 2727
    }
2724 2728

  
2725
    /**
2726
     * @param parentElement
2727
     * @return
2728
     */
2729
    public OriginalLabelDataController createOriginalLabelDataController(AbstractCdmDetailSection<DerivedUnitFacade> parentElement) {
2730
        OriginalLabelDataElement originalLabelDataElement = new OriginalLabelDataElement(parentElement.getLayoutComposite(), SWT.NONE);
2731
        originalLabelDataElement.initController(this, parentElement);
2732
        OriginalLabelDataController controller = originalLabelDataElement.getController();
2733
        addAndAdaptElement(parentElement, controller);
2734
        return controller;
2735
    }
2736

  
2737 2729
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OriginalLabelDataElement.java
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.element;
11

  
12
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
13
import eu.etaxonomy.taxeditor.ui.mvc.OriginalLabelDataField;
14
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
15

  
16
/**
17
 * @author pplitzner
18
 * @date 17.06.2014
19
 *
20
 */
21
public class OriginalLabelDataElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
22

  
23
    private TextWithLabelElement textOriginalLabelData;
24

  
25
    /**
26
     * @param formFactory
27
     * @param formElement
28
     */
29
    public OriginalLabelDataElement(CdmFormFactory formFactory,
30
            ICdmFormElement formElement) {
31
        super(formFactory, formElement);
32
    }
33

  
34
    /*
35
     * (non-Javadoc)
36
     *
37
     * @see
38
     * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
39
     * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
40
     */
41
    @Override
42
    protected void createControls(ICdmFormElement formElement,
43
            DerivedUnitFacade entity, int style) {
44
        new OriginalLabelDataField(formElement.getLayoutComposite(), style, entity.innerDerivedUnit(), getFormFactory());
45
//        textOriginalLabelData = formFactory.createTextWithLabelElement(formElement,
46
//                "Original Label Data", entity.innerDerivedUnit().getOriginalLabelInfo(), SWT.MULTI);
47
    }
48

  
49
    /*
50
     * (non-Javadoc)
51
     *
52
     * @see
53
     * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
54
     * .lang.Object)
55
     */
56
    @Override
57
    public void handleEvent(Object eventSource) {
58
        if (eventSource == textOriginalLabelData) {
59
            getEntity().innerDerivedUnit().setOriginalLabelInfo(textOriginalLabelData.getText());
60
        }
61
    }
62

  
63
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataController.java
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 org.eclipse.swt.events.ModifyEvent;
13
import org.eclipse.swt.events.ModifyListener;
14

  
15
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
18
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
19
import eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmCompositeController;
20
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
21

  
22
/**
23
 * @author pplitzner
24
 * @date 17.06.2014
25
 *
26
 */
27
public class OriginalLabelDataController extends AbstractCdmDetailElement<DerivedUnitFacade> implements CdmCompositeController, ModifyListener{
28

  
29
    private final OriginalLabelDataElement originalLabelDataElement;
30

  
31
    /**
32
     * @param dateTimeElement
33
     * @param formFactory
34
     * @param parentElement
35
     * @param initialDateTime
36
     * @param none
37
     */
38
    public OriginalLabelDataController(CdmFormFactory formFactory, ICdmFormElement parentElement, OriginalLabelDataElement originalLabelDataElement, int style) {
39
        super(formFactory, parentElement);
40
        this.originalLabelDataElement = originalLabelDataElement;
41
        this.originalLabelDataElement.getText().addModifyListener(this);
42
    }
43

  
44
    /* (non-Javadoc)
45
     * @see eu.etaxonomy.taxeditor.ui.element.IRelevantFormElement#setIrrelevant(boolean)
46
     */
47
    @Override
48
    public void setIrrelevant(boolean irrelevant) {
49
        // TODO Auto-generated method stub
50

  
51
    }
52

  
53
    /* (non-Javadoc)
54
     * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#setEnabled(boolean)
55
     */
56
    @Override
57
    public void setEnabled(boolean enabled) {
58
        originalLabelDataElement.setEnabled(enabled);
59
    }
60

  
61
    /* (non-Javadoc)
62
     * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
63
     */
64
    @Override
65
    public boolean isEnabled() {
66
        return originalLabelDataElement.isEnabled();
67
    }
68

  
69
    /* (non-Javadoc)
70
     * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.ui.element.ICdmFormElement, java.lang.Object, int)
71
     */
72
    @Override
73
    protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
74
        String originalLabelInfo = entity.innerDerivedUnit().getOriginalLabelInfo();
75
        if(originalLabelInfo!=null){
76
//            originalLabelDataElement.getText().setText(originalLabelInfo);
77
        }
78
    }
79

  
80
    /* (non-Javadoc)
81
     * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
82
     */
83
    @Override
84
    public void modifyText(ModifyEvent e) {
85
        getEntity().innerDerivedUnit().setOriginalLabelInfo(originalLabelDataElement.getText().getText());
86
        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
87
    }
88

  
89
    /* (non-Javadoc)
90
     * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
91
     */
92
    @Override
93
    public void handleEvent(Object eventSource) {
94
    }
95

  
96
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataElement.java
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 org.eclipse.swt.SWT;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Label;
15
import org.eclipse.swt.widgets.Text;
16
import org.eclipse.ui.forms.widgets.TableWrapData;
17
import org.eclipse.ui.forms.widgets.TableWrapLayout;
18

  
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21

  
22
/**
23
 * @author pplitzner
24
 * @date 17.06.2014
25
 *
26
 */
27
public class OriginalLabelDataElement extends AbstractCdmComposite<OriginalLabelDataController>{
28
    private final Text text;
29

  
30
    /**
31
     * @param parent
32
     * @param style
33
     */
34
    public OriginalLabelDataElement(Composite parent, int style) {
35
        super(parent, style);
36
        {
37
            TableWrapLayout tableWrapLayout = new TableWrapLayout();
38
            tableWrapLayout.verticalSpacing = 0;
39
            tableWrapLayout.topMargin = 0;
40
            tableWrapLayout.rightMargin = 0;
41
            tableWrapLayout.leftMargin = 0;
42
            tableWrapLayout.horizontalSpacing = 0;
43
            tableWrapLayout.bottomMargin = 0;
44
            tableWrapLayout.numColumns = 2;
45
            setLayout(tableWrapLayout);
46
        }
47

  
48
        Label lblOriginalLabelData = new Label(this, SWT.NONE);
49
        lblOriginalLabelData.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP, 1, 1));
50
        lblOriginalLabelData.setText("Original Label Data");
51

  
52
        text = new Text(this, SWT.BORDER | SWT.WRAP | SWT.MULTI);
53
        text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
54
        new Label(this, SWT.NONE);
55

  
56
        // TODO Auto-generated constructor stub
57
    }
58

  
59
    /* (non-Javadoc)
60
     * @see eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite#initInternalController(eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
61
     */
62
    @Override
63
    protected void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
64
        controller = new OriginalLabelDataController(formFactory, parentElement, this, SWT.NONE);
65
    }
66

  
67
    public Text getText() {
68
        return text;
69
    }
70
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/OriginalLabelDataField.java
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.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
30

  
31
/**
32
 * @author pplitzner
33
 * @date 23.06.2014
34
 *
35
 */
36
public class OriginalLabelDataField extends Composite {
37

  
38
    private DataBindingContext m_bindingContext;
39
    private eu.etaxonomy.cdm.model.occurrence.DerivedUnit derivedUnit = null;
40
    private final Text originalLabelInfoText;
41
    private CdmFormFactory formFactory;
42

  
43
    public OriginalLabelDataField(Composite parent, int style, eu.etaxonomy.cdm.model.occurrence.DerivedUnit newDerivedUnit, CdmFormFactory formFactory) {
44
        this(parent, style);
45
        setDerivedUnit(newDerivedUnit);
46
        this.formFactory = formFactory;
47
    }
48

  
49
    public OriginalLabelDataField(Composite parent, int style) {
50
        super(parent, style);
51
        setLayout(new GridLayout(2, false));
52

  
53
        new Label(this, SWT.NONE).setText("Original Label Data");
54

  
55
        originalLabelInfoText = new Text(this, SWT.BORDER | SWT.WRAP | SWT.MULTI);
56
        originalLabelInfoText.addModifyListener(new ModifyListener() {
57
            @Override
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));
63
                    }
64
                }
65
            }
66
        });
67
        originalLabelInfoText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
68

  
69
        if (derivedUnit != null) {
70
            m_bindingContext = initDataBindings();
71
        }
72
    }
73

  
74
    @Override
75
    protected void checkSubclass() {
76
        // Disable the check that prevents subclassing of SWT components
77
    }
78

  
79
    private DataBindingContext initDataBindings() {
80
        IObservableValue originalLabelInfoObserveWidget = SWTObservables.observeText(originalLabelInfoText, SWT.Modify);
81
        IObservableValue originalLabelInfoObserveValue = BeansObservables
82
                .observeValue(derivedUnit, "originalLabelInfo");
83
        //
84
        DataBindingContext bindingContext = new DataBindingContext();
85
        //
86
        bindingContext.bindValue(originalLabelInfoObserveWidget, originalLabelInfoObserveValue, null, null);
87
        //
88
        return bindingContext;
89
    }
90

  
91
    public eu.etaxonomy.cdm.model.occurrence.DerivedUnit getDerivedUnit() {
92
        return derivedUnit;
93
    }
94

  
95
    public void setDerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit newDerivedUnit) {
96
        setDerivedUnit(newDerivedUnit, true);
97
    }
98

  
99
    public void setDerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit newDerivedUnit, boolean update) {
100
        derivedUnit = newDerivedUnit;
101
        if (update) {
102
            if (m_bindingContext != null) {
103
                m_bindingContext.dispose();
104
                m_bindingContext = null;
105
            }
106
            if (derivedUnit != null) {
107
                m_bindingContext = initDataBindings();
108
            }
109
        }
110
    }
111

  
112
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/OriginalLabelDataSection.java
51 51
     */
52 52
    @Override
53 53
    protected AbstractCdmDetailElement<DerivedUnitFacade> createCdmDetailElement(AbstractCdmDetailSection<DerivedUnitFacade> parentElement, int style) {
54
        return formFactory.createOriginalLabelDataController(parentElement);
54
        return formFactory.createOriginalLabelDataElement(parentElement);
55 55
    }
56 56

  
57 57
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/CdmSectionPart.java
12 12

  
13 13
import org.eclipse.jface.util.IPropertyChangeListener;
14 14
import org.eclipse.jface.util.PropertyChangeEvent;
15
import org.eclipse.swt.widgets.Control;
15 16
import org.eclipse.ui.forms.SectionPart;
16 17

  
17 18
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
......
120 121
		if (event != null) {
121 122

  
122 123
			Object eventSource = event.getSource();
124
			Control[] children = formSection.getLayoutComposite().getChildren();
125
			boolean containsElement = false;
126
			for (Control control : children) {
127
			    if(eventSource.equals(control)){
128
			        containsElement = true;
129
			        break;
130
			    }
131
            }
132
			if(containsElement){
133
			    markDirty();
134
			}
123 135

  
124
			if (formSection.equals(eventSource)){
136
			else if (formSection.equals(eventSource)){
125 137
				markDirty();
126 138
			}
127
			if((
128
						(eventSource instanceof ICdmFormElement)
129
						&& formSection.containsFormElement((ICdmFormElement) eventSource))
130
						) {
131
				markDirty();
139
			else if(((eventSource instanceof ICdmFormElement)&& formSection.containsFormElement((ICdmFormElement) eventSource))) {
140
			    markDirty();
132 141
			}
133 142
		}
134 143
	}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)