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
package com.temp.client.foundation.widget.input.fieldsupport;

import org.litesoft.core.util.externalization.*;

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

@SuppressWarnings("deprecation")
public class CompleteInputFieldAccessor<T> extends InputFieldAccessor<T> {
    private final E13nResolver e13nResolver;
    private final Widget labelLabel;
    private final Widget extendedLabel;
    private final Widget exampleLabel;
    private final Widget errorLabel;
    private final HelpWidget helpWidget;
    private final Boolean[] focusableFocused;
    private final Focusable focusable;
    private final boolean anyFocusTracking;
    private FocusChangedListener focusChangedListener;

    public CompleteInputFieldAccessor( E13nResolver e13nResolver, TextLabel labelLabel, TextLabel extendedLabel, InputFieldAccessor<T> inputFieldAccessor,
                                       HelpWidget helpWidget, TextLabel exampleLabel, TextLabel errorLabel, Focusable... additionalFocusables ) {
        super( inputFieldAccessor.getInput(), inputFieldAccessor.getValidator(), inputFieldAccessor.getValueAdapter(), inputFieldAccessor.getInputWidget(),
               append( inputFieldAccessor.getFocusables(), additionalFocusables ) );
        this.e13nResolver = e13nResolver;
        this.labelLabel = labelLabel;
        this.extendedLabel = extendedLabel;
        this.exampleLabel = exampleLabel;
        this.errorLabel = errorLabel;
        this.helpWidget = helpWidget;
        focusableFocused = new Boolean[focusables.length];
        Focusable firstFocusable = null;
        boolean anyFocusTracking = false;
        for ( int i = 0; i < focusables.length; i++ ) {
            Focusable focusable = focusables[i];
            if ( focusable != null ) {
                if ( firstFocusable == null ) {
                    firstFocusable = focusable;
                }
                if ( registerFocusTracking( i, focusable ) ) {
                    focusableFocused[i] = false; // Not currently Focused!
                    anyFocusTracking = true;
                }
            }
        }
        this.focusable = firstFocusable;
        this.anyFocusTracking = anyFocusTracking;
    }

    private boolean registerFocusTracking( int index, Focusable focusable ) {
        if ( focusable instanceof HasAllFocusHandlers ) {
            createFocusHandler( index, (HasAllFocusHandlers) focusable );
            return true;
        }
        if ( focusable instanceof SourcesFocusEvents ) {
            createFocusListener( index, (SourcesFocusEvents) focusable );
            return true;
        }
        return false;
    }

    public E13nResolver getE13nResolver() {
        return e13nResolver;
    }

    public Widget getLabelLabel() {
        return labelLabel;
    }

    public Widget getExtendedLabel() {
        return extendedLabel;
    }

    public Widget getExampleLabel() {
        return exampleLabel;
    }

    public Widget getErrorLabel() {
        return errorLabel;
    }

    public HelpWidget getHelpWidget() {
        return helpWidget;
    }

    public void init( boolean enabled, FocusChangedListener focusChangedListener ) {
        setEnabled( enabled );
        this.focusChangedListener = focusChangedListener;
    }

    /**
     * Return if the Field has Focus (or null indicating that the Focus state is not tracked)
     */
    public Boolean isFocused() {
        if ( !anyFocusTracking ) {
            return null;
        }
        if ( isEnabled() ) {
            for ( Boolean focused : focusableFocused ) {
                if ( Boolean.TRUE.equals( focused ) ) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Pull the Focus to this Field (return false if the field is "thought" to be currently un-focusable, e.g. has no Focusable components or disabled)
     */
    public boolean setFocused() {
        if ( isEnabled() && (focusable != null) ) {
            focusable.setFocus( true );
            // We "should" get the appropriate events...
            return true;
        }
        return false;
    }

    private void focusChange( int index, boolean focused ) {
        if ( focusableFocused[index] != focused ) {
            focusableFocused[index] = focused;
            if ( focusChangedListener != null ) {
                focusChangedListener.focusChanged();
            }
        }
    }

    private void createFocusListener( final int index, SourcesFocusEvents focusable ) {
        focusable.addFocusListener( new FocusListener() {
            @Override
            public void onFocus( Widget sender ) {
                focusChange( index, true );
            }

            @Override
            public void onLostFocus( Widget sender ) {
                focusChange( index, false );
            }
        } );
    }

    private void createFocusHandler( int index, HasAllFocusHandlers focusable ) {
        FocusBlurHandler handler = new FocusBlurHandler( index );
        focusable.addFocusHandler( handler );
        focusable.addBlurHandler( handler );
    }

    private class FocusBlurHandler implements FocusHandler,
                                              BlurHandler {
        private final int index;

        public FocusBlurHandler( int index ) {
            this.index = index;
        }

        @Override
        public void onFocus( FocusEvent event ) {
            focusChange( index, true );
        }

        @Override
        public void onBlur( BlurEvent event ) {
            focusChange( index, false );
        }
    }

    private static Focusable[] append( Focusable[] focusables1, Focusable[] focusables2 ) {
        if ( CollectionsUtils.isEmpty( focusables2 ) ) {
            return focusables1;
        }
        if ( CollectionsUtils.isEmpty( focusables1 ) ) {
            return focusables2;
        }
        Focusable[] merged = new Focusable[focusables1.length + focusables2.length];
        System.arraycopy( focusables1, 0, merged, 0, focusables1.length );
        System.arraycopy( focusables2, 0, merged, focusables1.length, focusables2.length );
        return merged;
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

724 Diff Diff GeorgeS picture GeorgeS Mon 11 Jun, 2012 00:47:26 +0000
629 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 05:47:55 +0000
628 Diff Diff GeorgeS picture GeorgeS Fri 13 Apr, 2012 03:53:33 +0000
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000