summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java
blob: 4be0f02c2ae99945ecdec8f20691d22a38f3abed (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
/* 
@VaadinApache2LicenseForJavaFiles@
 */
package com.vaadin.terminal.gwt.client.ui;

import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ApplicationConnection;

public abstract class AbstractFieldConnector extends AbstractComponentConnector {

    @Override
    public AbstractFieldState getState() {
        return (AbstractFieldState) super.getState();
    }

    @Override
    public boolean isReadOnly() {
        return super.isReadOnly() || getState().isPropertyReadOnly();
    }

    public boolean isModified() {
        return getState().isModified();
    }

    /**
     * Checks whether the required indicator should be shown for the field.
     * 
     * Required indicators are hidden if the field or its data source is
     * read-only.
     * 
     * @return true if required indicator should be shown
     */
    public boolean isRequired() {
        return getState().isRequired() && !isReadOnly();
    }

    @Override
    protected String getStyleNames(String primaryStyleName) {
        String styleNames = super.getStyleNames(primaryStyleName);

        if (isModified()) {
            // add modified classname to Fields
            styleNames += " " + ApplicationConnection.MODIFIED_CLASSNAME;
        }

        if (isRequired()) {
            // add required classname to Fields
            styleNames += " " + primaryStyleName
                    + ApplicationConnection.REQUIRED_CLASSNAME_EXT;
        }

        return styleNames;
    }
}