Subversion Repository Public Repository

litesoft

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.temp.client.foundation.widget.input.fieldsupport;

import com.google.gwt.user.client.ui.*;
import com.temp.client.foundation.util.*;
import com.temp.client.foundation.widget.input.*;
import com.temp.shared.utils.*;

import java.util.*;

/**
 * Common abstract helper for both the generated Widget and the Proxied versions of the InputField.
 */
public abstract class AbstractInputField<T, C extends AbstractInputField<T, C>> implements InputField<T> {
    // Optionally set
    private Set<ChangeListener<T>> changeListeners = new HashSet<ChangeListener<T>>();
    private Set<FocusChangedListener> focusChangeListeners = new HashSet<FocusChangedListener>();

    protected boolean enabled = true;

    private State visibility = State.Visible;
    private StateInputField currentStyleState;

    @Override
    public final State getVisibility() {
        return visibility;
    }

    @Override
    public final void setVisibility( State visibility ) {
        visibility = ObjectUtils.deNull( visibility, State.Visible );
        Panel container = getContainer();
        if ( container != null ) {
            this.visibility = visibility;
            container.setVisible( visibility != State.Invisible );
            UtilsGwt.setHidden( container, visibility == State.Cloaked );
        }
    }

    // Configuration Methods

    @Override
    public final InputField<T> add( FocusChangedListener focusChangedListener ) {

        if ( focusChangedListener != null ) {
            focusChangeListeners.add( focusChangedListener );
        }
        return this;
    }

    @Override
    public final boolean remove( FocusChangedListener focusChangedListener ) {
        return (focusChangedListener == null) ? false : focusChangeListeners.remove( focusChangedListener );
    }

    @Override
    public final void removeAllFocusChangeListeners() {
        focusChangeListeners.clear();
    }

    @Override
    public final InputField<T> add( ChangeListener<T> changeListener ) {
        if ( changeListener != null ) {
            changeListeners.add( changeListener );
        }
        return this;
    }

    @Override
    public final boolean remove( ChangeListener<T> changeListener ) {
        return (changeListener == null) ? false : changeListeners.remove( changeListener );
    }

    @Override
    public final void removeAllChangeListeners() {
        changeListeners.clear();
    }

    abstract protected HasEnabled getEnableable();

    // Anytime Methods

    // For Enableable

    @Override
    public final boolean isEnabled() {
        HasEnabled enableable = getEnableable();
        return (enableable != null) ? enableable.isEnabled() : enabled;
    }

    @Override
    public final void setEnabled( boolean enable ) {
        enabled = enable;
        HasEnabled enableable = getEnableable();
        if ( enableable != null ) {
            enableable.setEnabled( enable );
        }
    }

    @Override
    public final InputField<T> enable() {
        setEnabled( true );
        return this;
    }

    @Override
    public final InputField<T> disable() {
        setEnabled( false );
        return this;
    }

    // For Visible

    @Override
    public final boolean isVisible() {
        return State.Visible == getVisibility();
    }

    @Override
    public final boolean isCloaked() {
        return State.Cloaked == getVisibility();
    }

    @Override
    public final boolean isInvisible() {
        return State.Invisible == getVisibility();
    }

    @Override
    public final InputField<T> visible() {
        setVisibility( State.Visible );
        return this;
    }

    @Override
    public final InputField<T> cloak() {
        setVisibility( State.Visible );
        return this;
    }

    @Override
    public final InputField<T> invisible() {
        setVisibility( State.Invisible );
        return this;
    }

    // Only callable in Run Mode

    protected final void updateStyle( StateInputField state ) {
        state = ObjectUtils.deNull( state, StateInputField.BASE );
        if ( state != currentStyleState ) {
            Panel panel = getContainer();
            if ( panel != null ) {
                if ( currentStyleState != null ) {
                    panel.removeStyleName( currentStyleState.toCSS() );
                }
                panel.addStyleName( state.toCSS() );
            }
            currentStyleState = state;
        }
    }

    protected final void notifyFocusChangeListeners() {
        for ( FocusChangedListener zListener : focusChangeListeners ) {
            zListener.focusChanged();
        }
    }

    protected final void notifyChangeListeners() {
        for ( ChangeListener<T> zListener : changeListeners ) {
            zListener.changed( this );
        }
    }

    protected final void assertBuildMode( String method ) {
        assertMode( method, false );
    }

    protected final void assertRunMode( String method ) {
        assertMode( method, true );
    }

    private void assertMode( String method, boolean expectedRunMode ) {
        if ( isRunMode() != expectedRunMode ) {
            throw new IllegalStateException( "Unable to access component/method '" + method + "' of InputField Named '" + getName() + //
                                             (expectedRunMode ? "', because not in Run Mode (init NOT called)" :
                                              "', because no longer in Build Mode (init has already been called)") );
        }
    }

    protected final C inheritanceLeaf() {
        return ObjectUtils.cast( this );
    }

    abstract protected Panel getContainer();
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/input/fieldsupport/AbstractInputField.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

635 Diff Diff GeorgeS picture GeorgeS Thu 19 Apr, 2012 18:20:49 +0000
633 Diff Diff GeorgeS picture GeorgeS Thu 19 Apr, 2012 02:30:46 +0000
632 Diff Diff GeorgeS picture GeorgeS Wed 18 Apr, 2012 18:11:29 +0000
630 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 20:22:17 +0000
629 GeorgeS picture GeorgeS Tue 17 Apr, 2012 05:47:55 +0000