Project

General

Profile

Download (2.54 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 representation, 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
    public TextFieldNFix(String format) {
37
        super(format);
38
        init();
39
    }
40

    
41
    public TextFieldNFix() {
42
        super();
43
        init();
44
    }
45

    
46
    public TextFieldNFix(Property dataSource) {
47
        super(dataSource);
48
        init();
49
    }
50

    
51
    public TextFieldNFix(String caption, Property dataSource) {
52
        super(caption, dataSource);
53
        init();
54
    }
55

    
56
    public TextFieldNFix(String caption, String value) {
57
        super(caption, value);
58
        init();
59
    }
60

    
61
    protected void init() {
62
        setNullSettingAllowed(true);
63
        addBlurListener(e -> {
64
            AbstractTextField c = ((AbstractTextField) e.getComponent());
65
            if (c.getValue() != null) {
66
                c.setValue(c.getValue().trim());
67
            }
68
        });
69
    }
70

    
71
    @Override
72
    public String getNullRepresentation() {
73
        return "";
74
    }
75

    
76
//    @Override
77
//    protected void setValue(String newFieldValue, boolean repaintIsNotNeeded,
78
//            boolean ignoreReadOnly) {
79
//        newFieldValue = trimValue(newFieldValue);
80
//        super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
81
//    }
82
//
83
//    @Override
84
//    protected void setInternalValue(String newValue) {
85
//        newValue = trimValue(newValue);
86
//        super.setInternalValue(newValue);
87
//    }
88
//
89
//
90
//
91
//    /**
92
//     * @param newValue
93
//     * @return
94
//     */
95
//    protected String trimValue(String newValue) {
96
//        if(newValue != null){
97
//            newValue = newValue.trim();
98
//            if(newValue.isEmpty()){
99
//                newValue = null;
100
//            }
101
//        }
102
//        return newValue;
103
//    }
104

    
105

    
106

    
107
}
(12-12/12)