Project

General

Profile

« Previous | Next » 

Revision 50a05434

Added by Patrick Plitzner about 10 years ago

  • added interfaces and classes for MVC pattern
    • implemented/adapted MVC pattern for TextWithLabelElement and EnumTermCombo element

View differences:

.gitattributes
1386 1386
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java -text
1387 1387
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java -text
1388 1388
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java -text
1389
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/AbstractCdmComposite.java -text
1390
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/DerivedUnitGeneralDetailElementMVC.java -text
1391
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/GeographicPointElement.java -text
1389 1392
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermCombo.java -text
1390 1393
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermComboController.java -text
1394
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/TextWithLabelElement.java -text
1395
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/TextWithLabelElementController.java -text
1396
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/interfaces/CdmCompositeController.java -text
1397
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/interfaces/ICdmComposite.java -text
1391 1398
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/IOpenUrlEnabled.java -text
1392 1399
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlContentProvider.java -text
1393 1400
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlLabelProvider.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
454 454
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
455 455
     *            object.
456 456
     */
457
    public void adapt(AbstractCdmFormElement formElement) {
457
    public void adapt(ICdmFormElement formElement) {
458 458
        formElement.setPropertyChangeListeners(propertyChangeListeners);
459 459
    }
460 460

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/AbstractCdmComposite.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.widgets.Composite;
13
import org.eclipse.swt.widgets.Control;
14

  
15
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
16
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
17
import eu.etaxonomy.taxeditor.ui.mvc.interfaces.ICdmComposite;
18
import eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmCompositeController;
19

  
20
/**
21
 * @author pplitzner
22
 * @date 11.02.2014
23
 *
24
 */
25
public abstract class AbstractCdmComposite extends Composite implements ICdmComposite {
26

  
27
    protected CdmCompositeController controller;
28

  
29
    /**
30
     * @param parent
31
     * @param style
32
     */
33
    public AbstractCdmComposite(Composite parent, int style) {
34
        super(parent, style);
35
    }
36

  
37
    protected void initChildController(CdmFormFactory formFactory, ICdmFormElement parentElement){
38
        Control[] children = this.getChildren();
39
        for (int i = 0; i < children.length; i++) {
40
            if(children[i] instanceof ICdmComposite){
41
                ICdmComposite cdmComposite = (ICdmComposite)children[i];
42
                cdmComposite.initController(formFactory, parentElement);
43
                formFactory.adapt(cdmComposite.getController());
44
                parentElement.addElement(cdmComposite.getController());
45
            }
46
        }
47
    }
48

  
49
    /* (non-Javadoc)
50
     * @see eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmComposite#initController(eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
51
     */
52
    @Override
53
    public void initController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
54
        initInternalController(formFactory, parentElement);
55
        initChildController(formFactory, parentElement);
56
    }
57

  
58
    /**
59
     * @param formFactory
60
     * @param parentElement
61
     * @return
62
     */
63
    protected abstract void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement);
64

  
65
    @Override
66
    public CdmCompositeController getController(){
67
        return controller;
68
    }
69

  
70
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/DerivedUnitGeneralDetailElementMVC.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.events.DisposeEvent;
14
import org.eclipse.swt.events.DisposeListener;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.ui.forms.widgets.FormToolkit;
19
import org.eclipse.ui.forms.widgets.TableWrapData;
20
import org.eclipse.ui.forms.widgets.TableWrapLayout;
21

  
22
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermCombo;
26
import eu.etaxonomy.taxeditor.ui.mvc.element.TextWithLabelElement;
27

  
28
/**
29
 * @author pplitzner
30
 * @date 14.04.2014
31
 *
32
 */
33
public class DerivedUnitGeneralDetailElementMVC extends AbstractCdmComposite {
34

  
35
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
36
    private final TextWithLabelElement textWithLabelElement;
37
    private final EnumTermCombo enumTermCombo;
38

  
39
    /**
40
     * Create the composite.
41
     * @param parent
42
     * @param style
43
     */
44
    public DerivedUnitGeneralDetailElementMVC(Composite parent, int style) {
45
        super(parent, style);
46
        addDisposeListener(new DisposeListener() {
47
            @Override
48
            public void widgetDisposed(DisposeEvent e) {
49
                toolkit.dispose();
50
            }
51
        });
52
        toolkit.adapt(this);
53
        toolkit.paintBordersFor(this);
54
        {
55
            TableWrapLayout tableWrapLayout = new TableWrapLayout();
56
            tableWrapLayout.numColumns = 2;
57
            setLayout(tableWrapLayout);
58
        }
59

  
60
                Label lblTitleCache = toolkit.createLabel(this, "Title Cache", SWT.NONE);
61
                new Label(this, SWT.NONE);
62

  
63
                Label lblSpecorobstype = toolkit.createLabel(this, "Spec./Obs. Type", SWT.NONE);
64

  
65
                enumTermCombo = new EnumTermCombo(this, SWT.NONE, SpecimenOrObservationType.class);
66
                TableWrapData twd_enumTermCombo = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
67
                twd_enumTermCombo.grabHorizontal = true;
68
                enumTermCombo.setLayoutData(twd_enumTermCombo);
69
                toolkit.adapt(enumTermCombo);
70
                toolkit.paintBordersFor(enumTermCombo);
71

  
72
        Label lblCountry = toolkit.createLabel(this, "Country", SWT.NONE);
73
        new Label(this, SWT.NONE);
74

  
75
        Label lblLocality = toolkit.createLabel(this, "Locality", SWT.NONE);
76
        new Label(this, SWT.NONE);
77

  
78
        GeographicPointElement geographicPointElement = new GeographicPointElement(this, SWT.NONE);
79
        geographicPointElement.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 2));
80
        toolkit.adapt(geographicPointElement);
81
        toolkit.paintBordersFor(geographicPointElement);
82

  
83
        Label lblElevation = toolkit.createLabel(this, "Elevation", SWT.NONE);
84
        new Label(this, SWT.NONE);
85

  
86
        Label lblDate = toolkit.createLabel(this, "Date", SWT.NONE);
87
        new Label(this, SWT.NONE);
88

  
89
        Label lblCollector = toolkit.createLabel(this, "Collector", SWT.NONE);
90
        new Label(this, SWT.NONE);
91

  
92
        Label lblCollectingNumber = toolkit.createLabel(this, "Collecting Number", SWT.NONE);
93

  
94
        TextWithLabelElement textWithLabelElement_1 = new TextWithLabelElement(this, (String) null, (Integer) null, 0);
95
        toolkit.adapt(textWithLabelElement_1);
96
        toolkit.paintBordersFor(textWithLabelElement_1);
97

  
98
        Label lblCollection = toolkit.createLabel(this, "Collection", SWT.NONE);
99
        new Label(this, SWT.NONE);
100

  
101
        Label lblAccessionNumber = toolkit.createLabel(this, "Accession Number", SWT.NONE);
102

  
103
        textWithLabelElement = new TextWithLabelElement(this, (String) null, (Integer) null, 0);
104
        TableWrapLayout tableWrapLayout = (TableWrapLayout) textWithLabelElement.getLayout();
105
        tableWrapLayout.verticalSpacing = 0;
106
        tableWrapLayout.topMargin = 0;
107
        tableWrapLayout.horizontalSpacing = 0;
108
        tableWrapLayout.bottomMargin = 0;
109
        TableWrapData twd_textWithLabelElement = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
110
        twd_textWithLabelElement.align = TableWrapData.FILL;
111
        twd_textWithLabelElement.grabHorizontal = true;
112
        textWithLabelElement.setLayoutData(twd_textWithLabelElement);
113
        toolkit.adapt(textWithLabelElement);
114
        toolkit.paintBordersFor(textWithLabelElement);
115

  
116
    }
117

  
118
    public TextWithLabelElement getTextWithLabelElement() {
119
        return textWithLabelElement;
120
    }
121
    public EnumTermCombo getEnumTermCombo() {
122
        return enumTermCombo;
123
    }
124

  
125
    /* (non-Javadoc)
126
     * @see eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmComposite#initController(java.lang.Object, eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
127
     */
128
    @Override
129
    public void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
130
        // empty on purpose
131
    }
132
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/GeographicPointElement.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.events.DisposeEvent;
14
import org.eclipse.swt.events.DisposeListener;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.ui.forms.widgets.FormToolkit;
19
import org.eclipse.ui.forms.widgets.TableWrapData;
20
import org.eclipse.ui.forms.widgets.TableWrapLayout;
21

  
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24
import eu.etaxonomy.taxeditor.ui.mvc.element.TextWithLabelElement;
25

  
26
/**
27
 * @author pplitzner
28
 * @date 15.04.2014
29
 *
30
 */
31
public class GeographicPointElement extends AbstractCdmComposite {
32

  
33
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
34

  
35
    /**
36
     * Create the composite.
37
     * @param parent
38
     * @param style
39
     */
40
    public GeographicPointElement(Composite parent, int style) {
41
        super(parent, style);
42
        addDisposeListener(new DisposeListener() {
43
            @Override
44
            public void widgetDisposed(DisposeEvent e) {
45
                toolkit.dispose();
46
            }
47
        });
48
        toolkit.adapt(this);
49
        toolkit.paintBordersFor(this);
50
        {
51
            TableWrapLayout tableWrapLayout = new TableWrapLayout();
52
            tableWrapLayout.verticalSpacing = 0;
53
            tableWrapLayout.topMargin = 0;
54
            tableWrapLayout.rightMargin = 0;
55
            tableWrapLayout.leftMargin = 0;
56
            tableWrapLayout.bottomMargin = 0;
57
            tableWrapLayout.horizontalSpacing = 0;
58
            tableWrapLayout.numColumns = 2;
59
            setLayout(tableWrapLayout);
60
        }
61

  
62
        Label lblLatitude = toolkit.createLabel(this, "Latitude", SWT.NONE);
63
        new Label(this, SWT.NONE);
64

  
65
        Label lblLongitude = toolkit.createLabel(this, "Longitude", SWT.NONE);
66
        new Label(this, SWT.NONE);
67

  
68
        Label lblErrorRadius = toolkit.createLabel(this, "Error Radius", SWT.NONE);
69

  
70
        TextWithLabelElement textWithLabelElement = new TextWithLabelElement(this, (String) null, (Integer) null, 0);
71
        TableWrapData twd_textWithLabelElement = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
72
        twd_textWithLabelElement.grabHorizontal = true;
73
        textWithLabelElement.setLayoutData(twd_textWithLabelElement);
74
        toolkit.adapt(textWithLabelElement);
75
        toolkit.paintBordersFor(textWithLabelElement);
76

  
77
        Label lblReferenceSystem = toolkit.createLabel(this, "Reference System", SWT.NONE);
78

  
79
    }
80

  
81
    /* (non-Javadoc)
82
     * @see eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite#initInternalController(eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
83
     */
84
    @Override
85
    protected void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
86

  
87
    }
88

  
89
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermCombo.java
22 22
import eu.etaxonomy.cdm.model.common.IEnumTerm;
23 23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite;
25 26

  
26 27
/**
27 28
 * @author pplitzner
28 29
 * @date 29.01.2014
29 30
 *
30 31
 */
31
public class EnumTermCombo extends Combo{
32
public class EnumTermCombo extends AbstractCdmComposite {
32 33

  
33 34
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
34 35
    private final Combo combo;
35
//    private final Label label;
36

  
37
    private final Class<? extends IEnumTerm<?>> enumType;
36 38

  
37 39
    /**
38 40
     * Create the composite.
39 41
     * @param parent
40 42
     * @param style
41 43
     */
42
    public EnumTermCombo(Composite parent, int style) {
44
    public EnumTermCombo(Composite parent, int style, Class<? extends IEnumTerm<?>> enumType) {
43 45
        super(parent, style);
46
        this.enumType = enumType;
44 47
        addDisposeListener(new DisposeListener() {
45 48
            @Override
46 49
            public void widgetDisposed(DisposeEvent e) {
......
51 54
        toolkit.paintBordersFor(this);
52 55
        {
53 56
            TableWrapLayout tableWrapLayout = new TableWrapLayout();
57
            tableWrapLayout.verticalSpacing = 0;
58
            tableWrapLayout.topMargin = 0;
59
            tableWrapLayout.horizontalSpacing = 0;
60
            tableWrapLayout.bottomMargin = 0;
54 61
            tableWrapLayout.rightMargin = 0;
55 62
            tableWrapLayout.leftMargin = 0;
56
            tableWrapLayout.numColumns = 2;
57 63
            setLayout(tableWrapLayout);
58 64
        }
59 65

  
60
//        label = toolkit.createLabel(this, "New Label", SWT.NONE);
61
//        TableWrapData twd_label = new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP, 1, 1);
62
//        twd_label.align = TableWrapData.LEFT;
63
//        label.setLayoutData(twd_label);
64

  
65 66
        combo = new Combo(this, SWT.READ_ONLY);
66 67
        combo.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
67 68
        toolkit.adapt(combo);
......
71 72
    public Combo getCombo() {
72 73
        return combo;
73 74
    }
74
//    public Label getLabel() {
75
//        return label;
76
//    }
77

  
78
    public <T extends IEnumTerm<T>> EnumTermComboController<T> initController(Class<T> enumType, CdmFormFactory formFactory, ICdmFormElement parentElement){
79
        return new EnumTermComboController<T>(this, formFactory, parentElement, enumType, 0);
80
//        CdmCompositeControllerFactory.createController(this, entity, formFactory, parentElement);
81
//        Control[] children = this.getChildren();
82
//        for (int i = 0; i < children.length; i++) {
83
//            if(children[i] instanceof CdmComposite){
84
//                return ((CdmComposite)children[i]).initController(entity, formFactory, parentElement);
85
//            }
86
//        }
87
//        return null;
75
    /* (non-Javadoc)
76
     * @see eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmComposite#initController(java.lang.Object, eu.etaxonomy.taxeditor.ui.element.CdmFormFactory, eu.etaxonomy.taxeditor.ui.element.ICdmFormElement)
77
     */
78
    @Override
79
    protected void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement) {
80
        controller = new EnumTermComboController(combo, formFactory, parentElement, enumType, SWT.NONE);
88 81
    }
82

  
89 83
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/combo/EnumTermComboController.java
35 35
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
36 36
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
37 37
import eu.etaxonomy.taxeditor.ui.element.ISelectable;
38
import eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmCompositeController;
38 39

  
39 40
/**
40 41
 * @author pplitzner
......
42 43
 *
43 44
 */
44 45
public class EnumTermComboController<T extends IEnumTerm<T>> extends AbstractCdmFormElement implements SelectionListener,
45
IEnableableFormElement, ISelectable {
46
IEnableableFormElement, ISelectable, CdmCompositeController {
46 47

  
47 48
    private static CdmEnumDataHolder[] cdmEnumDataHolders = {
48 49
        new CdmEnumDataHolder<NomenclaturalCode>(){
......
152 153
        this.enumType = enumType;
153 154
        // create combo
154 155
        this.combo = combo;
155
//        combo.setParent(getLayoutComposite());
156
//        combo = new Combo(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY);
157 156
        addControl(combo);
158
//        combo.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
159 157
        setVisibleItemCount(DEFAULT_VISIBLE_ITEMS);
160 158

  
161 159
        populateTypes();
162 160

  
163 161
        combo.addSelectionListener(this);
164 162

  
165
//        formFactory.adapt(this);
166
//        parentElement.addElement(this);
167 163
    }
168 164

  
169 165
    private String getDefaultLabelString() {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/TextWithLabelElement.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.element;
11

  
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.DisposeEvent;
14
import org.eclipse.swt.events.DisposeListener;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Text;
18
import org.eclipse.ui.forms.widgets.FormToolkit;
19
import org.eclipse.ui.forms.widgets.TableWrapData;
20
import org.eclipse.ui.forms.widgets.TableWrapLayout;
21

  
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24
import eu.etaxonomy.taxeditor.ui.mvc.AbstractCdmComposite;
25

  
26
/**
27
 * @author pplitzner
28
 * @date 11.02.2014
29
 *
30
 */
31
public class TextWithLabelElement extends AbstractCdmComposite {
32

  
33
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
34
    private final Text text;
35
    private final String initialText;
36
    private final Integer textHeight;
37

  
38
    /**
39
     * Create the composite.
40
     * @param parent
41
     * @param style
42
     */
43
    public TextWithLabelElement(Composite parent, String initialText, Integer textHeight, int style) {
44
        super(parent, SWT.BORDER);
45
        this.initialText = initialText;
46
        this.textHeight = textHeight;
47
        addDisposeListener(new DisposeListener() {
48
            @Override
49
            public void widgetDisposed(DisposeEvent e) {
50
                toolkit.dispose();
51
            }
52
        });
53
        toolkit.adapt(this);
54
        toolkit.paintBordersFor(this);
55
        {
56
            TableWrapLayout tableWrapLayout = new TableWrapLayout();
57
            tableWrapLayout.verticalSpacing = 0;
58
            tableWrapLayout.topMargin = 0;
59
            tableWrapLayout.horizontalSpacing = 0;
60
            tableWrapLayout.bottomMargin = 0;
61
            tableWrapLayout.rightMargin = 0;
62
            tableWrapLayout.leftMargin = 0;
63
            setLayout(tableWrapLayout);
64
        }
65

  
66
        text = new Text(this, SWT.WRAP);
67
        text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
68
        toolkit.adapt(text, true, true);
69

  
70
    }
71

  
72
    public Text getText() {
73
        return text;
74
    }
75

  
76
    @Override
77
    protected void initInternalController(CdmFormFactory formFactory, ICdmFormElement parentElement){
78
        controller = new TextWithLabelElementController(this, formFactory, parentElement, this.initialText, this.textHeight, SWT.NONE);
79
    }
80
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/TextWithLabelElementController.java
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.ui.mvc.element;
5

  
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.KeyAdapter;
8
import org.eclipse.swt.events.KeyEvent;
9
import org.eclipse.swt.events.ModifyEvent;
10
import org.eclipse.swt.events.ModifyListener;
11
import org.eclipse.swt.graphics.Color;
12
import org.eclipse.swt.widgets.Control;
13
import org.eclipse.swt.widgets.Listener;
14
import org.eclipse.swt.widgets.Text;
15

  
16
import eu.etaxonomy.cdm.common.CdmUtils;
17
import eu.etaxonomy.taxeditor.preference.Resources;
18
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
21
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
23
import eu.etaxonomy.taxeditor.ui.element.ISelectable;
24
import eu.etaxonomy.taxeditor.ui.mvc.interfaces.CdmCompositeController;
25

  
26
/**
27
 * <p>
28
 * TextWithLabelElement class.
29
 * </p>
30
 *
31
 * @author n.hoffmann
32
 * @version $Id: $
33
 */
34
public class TextWithLabelElementController extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
35
        ISelectable, CdmCompositeController {
36

  
37
    protected Text text;
38
//    private Label label;
39

  
40
    /** Constant <code>MAX_HEIGHT=0</code> */
41
    public static final int MAX_HEIGHT = 0;
42
    /** Constant <code>SINGLE=-1</code> */
43
    public static final int SINGLE = -1;
44

  
45
    /**
46
     * <p>
47
     * Constructor for TextWithLabelElement.
48
     * </p>
49
     *
50
     * @param formFactory
51
     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
52
     *            object.
53
     * @param parentElement
54
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55
     *            object.
56
     * @param labelString
57
     *            a {@link java.lang.String} object.
58
     * @param initialText
59
     *            a {@link java.lang.String} object.
60
     * @param textHeight
61
     *            a {@link java.lang.Integer} object.
62
     * @param style
63
     *            a int.
64
     * @wbp.parser.entryPoint
65
     */
66
    public TextWithLabelElementController(TextWithLabelElement textWithLabelElement, CdmFormFactory formFactory, ICdmFormElement parentElement,
67
            String initialText, Integer textHeight, int style) {
68
        super(formFactory, parentElement);
69

  
70
        int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
71

  
72
        int combinedStyle = style | SWT.BORDER | scrollStyle;
73

  
74
        // SWT.PASSWORD does not work when SWT.WRAP is set.
75
        if (style != SWT.PASSWORD) {
76
            combinedStyle = combinedStyle | SWT.WRAP;
77
        }
78

  
79
        text = textWithLabelElement.getText();
80

  
81
        addControl(text);
82

  
83
        if (textHeight == null) {
84
            text.addKeyListener(new KeyAdapter() {
85
                @Override
86
                public void keyPressed(KeyEvent e) {
87
                    if (e.character == SWT.CR) {
88
                        // Don't accept carriage returns as input when in single
89
                        // line mode
90
                        e.doit = false;
91
                    } else if (e.character == SWT.TAB) {
92
                        // traverse is not working for wrapped text widgets so
93
                        // we reintroduce it here
94
                        e.doit = false;
95
                        TextWithLabelElementController.this.text.traverse(SWT.TRAVERSE_TAB_NEXT);
96
                    }
97
                }
98
            });
99
        }
100

  
101
        text.addModifyListener(this);
102
    }
103

  
104
    /**
105
     * Get the text of this composites text composite
106
     *
107
     * @return a {@link java.lang.String} object.
108
     */
109
    public String getText() {
110
        return text.getText();
111
    }
112

  
113
    /**
114
     * Set the text of this composites text composite
115
     *
116
     * @param string
117
     *            a {@link java.lang.String} object.
118
     */
119
    public void setText(String string) {
120
        Listener[] listeners = text.getListeners(SWT.Modify);
121

  
122
        for (Listener listener : listeners) {
123
            text.removeListener(SWT.Modify, listener);
124
        }
125

  
126
        text.setText(CdmUtils.Nz(string));
127

  
128
        for (Listener listener : listeners) {
129
            text.addListener(SWT.Modify, listener);
130
        }
131
    }
132

  
133
    /*
134
     * (non-Javadoc)
135
     *
136
     * @see
137
     * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
138
     * .ModifyEvent)
139
     */
140
    /** {@inheritDoc} */
141
    @Override
142
    public void modifyText(ModifyEvent e) {
143
        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
144
    }
145

  
146
    /** {@inheritDoc} */
147
    @Override
148
    public void setEnabled(boolean enabled) {
149
        text.setEnabled(enabled);
150
        String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT : Resources.COLOR_TEXT_DISABLED;
151
        text.setForeground(getColor(symbolicName));
152
    }
153

  
154
    /* (non-Javadoc)
155
     * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
156
     */
157
    @Override
158
    public boolean isEnabled() {
159
        return text.isEnabled();
160
    }
161

  
162
    /** {@inheritDoc} */
163
    @Override
164
    public void setIrrelevant(boolean irrelevant) {
165
        String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
166

  
167
        Color color = getColor(colorId);
168
        text.setBackground(color);
169
    }
170

  
171
    /** {@inheritDoc} */
172
    @Override
173
    public void setBackground(Color color) {
174
//        if (label != null) {
175
//            label.setBackground(color);
176
//        }
177
    }
178

  
179
    @Override
180
    public void setSelected(boolean selected) {
181
        setBackground(selected ? SELECTED : getPersistentBackground());
182
    }
183

  
184
    /*
185
     * (non-Javadoc)
186
     *
187
     * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
188
     */
189
    /** {@inheritDoc} */
190
    @Override
191
    public void setFocus() {
192
        text.setFocus();
193
    }
194

  
195
    /**
196
     * <p>
197
     * getMainControl
198
     * </p>
199
     *
200
     * @return a {@link org.eclipse.swt.widgets.Control} object.
201
     */
202
    public Control getMainControl() {
203
        return text;
204
    }
205

  
206
    /**
207
     * <p>
208
     * setTextLimit
209
     * </p>
210
     *
211
     * @param limit
212
     *            a int.
213
     */
214
    public void setTextLimit(int limit) {
215
        text.setTextLimit(limit);
216
    }
217
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/interfaces/CdmCompositeController.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.interfaces;
11

  
12
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
13

  
14
/**
15
 * CdmCompositeController implement the interaction logic for CdmComposites.
16
 * They also serve as a compatibility bridge between the current GUI structure
17
 * based on {@link ICdmFormElement} and a refactored structure using the MVC pattern.
18
 * @author pplitzner
19
 * @date 11.02.2014
20
 *
21
 */
22
public interface CdmCompositeController extends ICdmFormElement{
23

  
24
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/interfaces/ICdmComposite.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.interfaces;
11

  
12
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
13
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
14

  
15
/**
16
 * A composite for visualizing CDM objects. ICdmComposites are mere GUI composites but
17
 * they initialize a controller which contains the interaction logic.
18
 * @author pplitzner
19
 * @date 11.02.2014
20
 *
21
 */
22
public interface ICdmComposite {
23

  
24
    /**
25
     * Initializes the {@link CdmCompositeController} of this composite.
26
     * @param formFactory the factory used for the GUI element
27
     * @param parentElement the parent {@link ICdmFormElement}
28
     */
29
    public void initController(CdmFormFactory formFactory, ICdmFormElement parentElement);
30

  
31
    /**
32
     * Returns the {@link CdmCompositeController} of this composite.
33
     * @return
34
     */
35
    public CdmCompositeController getController();
36

  
37
}

Also available in: Unified diff