Project

General

Profile

Download (2.82 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.element;
10

    
11
import org.apache.commons.lang3.StringUtils;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.Text;
19

    
20
import eu.etaxonomy.taxeditor.model.ImageResources;
21

    
22
/**
23
 * @author k.luther
24
 * @since Apr 1, 2021
25
 */
26
public class RemovableTextElement extends AbstractCdmFormElement implements SelectionListener {
27

    
28
    private final Text text_cache;
29
    private final Button btnRemoveElement;
30
    private final Label label;
31
    private final Composite container;
32
    private boolean state;
33

    
34
    protected RemovableTextElement(CdmFormFactory formFactory, ICdmFormElement parentElement,
35
            String labelString, String initialText, int style) {
36
        super(formFactory, parentElement);
37

    
38
        label = formFactory.createLabel(getLayoutComposite(), labelString, style);
39
        addControl(label);
40

    
41
        container = formFactory.createComposite(getLayoutComposite(), SWT.WRAP);
42
        container.setLayout(LayoutConstants.LAYOUT(2, false));
43
        container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
44
        addControl(container);
45

    
46
        text_cache = formFactory.createText(container, initialText, SWT.WRAP | SWT.MULTI);
47
        addControl(text_cache);
48
        text_cache.setEnabled(false);
49
        text_cache.setLayoutData(LayoutConstants.FILL());
50

    
51
        btnRemoveElement = formFactory.createButton(container, "Edit", SWT.TOGGLE);
52
        btnRemoveElement.setText("");
53
        btnRemoveElement.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
54
        addControl(btnRemoveElement);
55
        btnRemoveElement.addSelectionListener(this);
56
        if (initialText != null){
57
            setState(true);
58
        }else {
59
            setState(false);
60
        }
61

    
62
    }
63

    
64

    
65
    @Override
66
    public void widgetSelected(SelectionEvent e) {
67
       setText(null);
68
       firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
69
    }
70

    
71
    @Override
72
    public void widgetDefaultSelected(SelectionEvent e) {
73
        // TODO Auto-generated method stub
74

    
75
    }
76

    
77
    public void setText(String text){
78
        if (text == null){
79
            this.text_cache.setText("");
80
        }
81
        if (StringUtils.isBlank(text)){
82
            setState(false);
83
        }else{
84
            setState(true);
85
        }
86
    }
87

    
88

    
89
    public boolean isState() {
90
        return state;
91
    }
92

    
93

    
94
    public void setState(boolean state) {
95
        this.state = state;
96
    }
97

    
98
}
(45-45/57)