Project

General

Profile

Download (2.76 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.cdm.vaadin.component;
10

    
11
import com.vaadin.data.Property;
12
import com.vaadin.ui.AbstractTextField;
13
import com.vaadin.ui.TextField;
14

    
15
/**
16
 * TextField which has "" as null represnetation, fixed the ugly "null"s in the
17
 * default  TextField implementation in vaadin 7. TODO: this might no longer be
18
 * required in vaadin 8 since it is supposed to have a mechanism to configure
19
 * the null representations.
20
 * <p>
21
 * Additional features:
22
 * <ul>
23
 *    <li>entered text is trimmed</li>
24
 * </ul>
25
 *
26
 *
27
 * @author a.kohlbecker
28
 * @since Dec 21, 2017
29
 *
30
 */
31
public class TextFieldNFix extends TextField {
32

    
33
    private static final long serialVersionUID = -7582619519894748364L;
34

    
35
    /**
36
     * @param format
37
     */
38
    public TextFieldNFix(String format) {
39
        super(format);
40
        init();
41
    }
42

    
43

    
44

    
45
    /**
46
     *
47
     */
48
    public TextFieldNFix() {
49
        super();
50
        init();
51
    }
52

    
53

    
54

    
55
    /**
56
     * @param dataSource
57
     */
58
    public TextFieldNFix(Property dataSource) {
59
        super(dataSource);
60
        init();
61
    }
62

    
63

    
64

    
65
    /**
66
     * @param caption
67
     * @param dataSource
68
     */
69
    public TextFieldNFix(String caption, Property dataSource) {
70
        super(caption, dataSource);
71
        init();
72
    }
73

    
74

    
75

    
76
    /**
77
     * @param caption
78
     * @param value
79
     */
80
    public TextFieldNFix(String caption, String value) {
81
        super(caption, value);
82
        init();
83
    }
84

    
85

    
86
    protected void init() {
87
        setNullSettingAllowed(true);
88
        addBlurListener(e -> {
89
            AbstractTextField c = ((AbstractTextField) e.getComponent());
90
            if (c.getValue() != null) {
91
                c.setValue(c.getValue().trim());
92
            }
93
        });
94
    }
95

    
96

    
97
    @Override
98
    public String getNullRepresentation() {
99
        return "";
100
    }
101

    
102
//    @Override
103
//    protected void setValue(String newFieldValue, boolean repaintIsNotNeeded,
104
//            boolean ignoreReadOnly) {
105
//        newFieldValue = trimValue(newFieldValue);
106
//        super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
107
//    }
108
//
109
//    @Override
110
//    protected void setInternalValue(String newValue) {
111
//        newValue = trimValue(newValue);
112
//        super.setInternalValue(newValue);
113
//    }
114
//
115
//
116
//
117
//    /**
118
//     * @param newValue
119
//     * @return
120
//     */
121
//    protected String trimValue(String newValue) {
122
//        if(newValue != null){
123
//            newValue = newValue.trim();
124
//            if(newValue.isEmpty()){
125
//                newValue = null;
126
//            }
127
//        }
128
//        return newValue;
129
//    }
130

    
131

    
132

    
133

    
134

    
135
}
(8-8/8)