Project

General

Profile

Download (2.04 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.TextField;
13

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

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

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

    
41

    
42

    
43
    /**
44
     *
45
     */
46
    public TextFieldNFix() {
47
        super();
48
        setNullSettingAllowed(true);
49
    }
50

    
51

    
52

    
53
    /**
54
     * @param dataSource
55
     */
56
    public TextFieldNFix(Property dataSource) {
57
        super(dataSource);
58
    }
59

    
60

    
61

    
62
    /**
63
     * @param caption
64
     * @param dataSource
65
     */
66
    public TextFieldNFix(String caption, Property dataSource) {
67
        super(caption, dataSource);
68
    }
69

    
70

    
71

    
72
    /**
73
     * @param caption
74
     * @param value
75
     */
76
    public TextFieldNFix(String caption, String value) {
77
        super(caption, value);
78
        // TODO Auto-generated constructor stub
79
    }
80

    
81

    
82

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    public String getNullRepresentation() {
88
        return "";
89
    }
90

    
91

    
92

    
93
    /**
94
     * {@inheritDoc}
95
     */
96
    @Override
97
    protected void setInternalValue(String newValue) {
98
        if(newValue != null){
99
            newValue = newValue.trim();
100
            if(newValue.isEmpty()){
101
                newValue = null;
102
            }
103
        }
104
        super.setInternalValue(newValue);
105
    }
106

    
107

    
108

    
109

    
110

    
111
}
(8-8/8)