summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java
blob: 6a869893f7089d90864d720bdf79bcfd057b43b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
@VaadinApache2LicenseForJavaFiles@
 */
package com.vaadin.terminal.gwt.client;

import com.vaadin.terminal.gwt.client.ui.TabIndexState;
import com.vaadin.ui.AbstractField;

/**
 * Shared state for {@link AbstractField}.
 * 
 * @author Vaadin Ltd
 * @version @VERSION@
 * @since 7.0.0
 * 
 */
public class AbstractFieldState extends ComponentState implements TabIndexState {
    private boolean propertyReadOnly = false;
    private boolean hideErrors = false;
    private boolean required = false;
    private boolean modified = false;

    /**
     * The tab order number of this field.
     */
    private int tabIndex = 0;

    /**
     * Checks if the property data source for the Field is in read only mode.
     * This affects the read only state of the field itself.
     * 
     * @return true if there is a property data source and it is set to read
     *         only, false otherwise
     */
    public boolean isPropertyReadOnly() {
        return propertyReadOnly;
    }

    /**
     * Sets the read only state of the property data source.
     * 
     * @param propertyReadOnly
     *            true if the property data source if read only, false otherwise
     */
    public void setPropertyReadOnly(boolean propertyReadOnly) {
        this.propertyReadOnly = propertyReadOnly;
    }

    /**
     * Returns true if the component will hide any errors even if the error
     * message is set.
     * 
     * @return true if error messages are disabled
     */
    public boolean isHideErrors() {
        return hideErrors;
    }

    /**
     * Sets whether the component should hide any errors even if the error
     * message is set.
     * 
     * This is used e.g. on forms to hide error messages for invalid fields
     * before the first user actions.
     * 
     * @param hideErrors
     *            true if error messages should be hidden
     */
    public void setHideErrors(boolean hideErrors) {
        this.hideErrors = hideErrors;
    }

    /**
     * Is the field required. Required fields must filled by the user.
     * 
     * See AbstractField#isRequired() for more information.
     * 
     * @return <code>true</code> if the field is required, otherwise
     *         <code>false</code>.
     */
    public boolean isRequired() {
        return required;
    }

    /**
     * Sets the field required. Required fields must filled by the user.
     * 
     * See AbstractField#setRequired(boolean) for more information.
     * 
     * @param required
     *            Is the field required.
     */
    public void setRequired(boolean required) {
        this.required = required;
    }

    /**
     * Has the contents of the field been modified, i.e. has the value been
     * updated after it was read from the data source.
     * 
     * @return true if the field has been modified, false otherwise
     */
    public boolean isModified() {
        return modified;
    }

    /**
     * Setter for the modified flag, toggled when the contents of the field is
     * modified by the user.
     * 
     * @param modified
     *            the new modified state
     * 
     */
    public void setModified(boolean modified) {
        this.modified = modified;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.vaadin.terminal.gwt.client.ComponentState#getTabIndex()
     */
    @Override
    public int getTabIndex() {
        return tabIndex;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#setTabIndex(int)
     */
    @Override
    public void setTabIndex(int tabIndex) {
        this.tabIndex = tabIndex;
    }

}