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
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.forms.client.components.nonpublic;

import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.commonfoundation.html.*;
import org.litesoft.core.*;
import org.litesoft.uispecification.*;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public abstract class AbstractFocusWidgetFormElement extends AbstractFormElement implements FocusHandler,
                                                                                            BlurHandler {
    protected final Widget mInputWidget;
    protected IndicatorTd mIndicatorTd = null;
    protected Label mLabel = null;

    protected AbstractFocusWidgetFormElement( IFocusWidget pInputWidget, String pWidgetStyle, boolean pAddStyle ) {
        super( DOM.createDiv() );
        mInputWidget = (Widget) pInputWidget;
        if ( pAddStyle ) {
            mInputWidget.addStyleName( pWidgetStyle );
        } else {
            mInputWidget.setStyleName( pWidgetStyle );
        }
    }

    protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) {
        mFieldLabel = pFieldLabel;
        mTooltip = pTooltip;

        buildComponentPanel( (pFieldLabel != null) ? HTMLize.escapeNoWrap( pFieldLabel ) : null, pLabelFont );

        IFocusWidget zWidget = (IFocusWidget) mInputWidget;
        zWidget.addFocusHandler( this );
        zWidget.addBlurHandler( this );

        if ( mIndicatorTd != null ) {
            mIndicatorTd.setTitle( pTooltip );
        }
    }

    protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
        int zUniqueID = StaticSimpleIdSource.getNext();
        String trId = "tr_" + zUniqueID;
        String inputId = "input_" + zUniqueID;
        String labelId = "label_" + zUniqueID;
        String html = "<table cellpadding='0' cellspacing='0'>" + //
                      buildInputRow( trId, inputId, zUniqueID ) + //
                      "</table>";

        if ( pLabel != null ) {
            ApplyFont.to( pLabelFont, mLabel = new Label() );
            mLabel.addStyleName( FORM_COMPONENT_LABEL_STYLE );
            DOM.setInnerHTML( mLabel.getElement(), pLabel );
            html = "<table cellpadding='0' cellspacing='0'>" + //
                   "<tr><td id='" + labelId + "'></td></tr>" + //
                   "<tr><td>" + html + "</td></tr></table>";
        }

        initializeHTML( html );

        mInnerHTMLpanel.add( getInjectedInputWidget(), inputId );
        addIndicator( trId );
        if ( mLabel != null ) {
            mInnerHTMLpanel.add( mLabel, labelId );
        }
        return zUniqueID;
    }

    protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
        return buildInputRowWithOptionalCell( pTrId, pInputId, "" );
    }

    protected void addIndicator( String pTrId ) {
        mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId );
    }

    protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) {
        return "<tr id='" + pTrId + "' class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + pAdditionalInputCell + "</tr>";
    }

    protected Widget getInjectedInputWidget() {
        return mInputWidget;
    }

    // IFormComponent

    @Override
    public boolean setFocus() {
        if ( mInputWidget instanceof Focusable ) {
            pullFocusTo( (Focusable) mInputWidget );
            return true;
        }
        return false;
    }

    @Override
    public void setEnabled( boolean pEnabled ) {
        mEnabled = pEnabled;
        ((IFocusWidget) mInputWidget).setEnabled( pEnabled );
        stateChanged();
    }

    // Focus & Blur Handlers

    @Override
    public void onFocus( FocusEvent event ) {
        fireFocusListeners();
    }

    @Override
    public void onBlur( BlurEvent event ) {
        fireBlurListeners();
    }

    // Support...

    public static class IndicatorTd extends Widget {
        public IndicatorTd() {
            Element td = DOM.createTD();
            CommonElementHelper.setStyleClass( td, "litesoft-FormComponentIndicatorContainer" );
            DOM.setElementProperty( td, "align", "center" );

            setElement( td );

            Element icon = DOM.createDiv();
            CommonElementHelper.setStyleClass( icon, "litesoft-FormComponentIndicator" );
            DOM.setStyleAttribute( icon, "fontSize", "0" );

            DOM.appendChild( td, icon );

            setVisible( false );
        }

        @Override
        public void setTitle( String title ) {
            title = ConstrainTo.significantOrNull( title );
            if ( title == null ) {
                super.setTitle( "" );
                setVisible( false );
            } else {
                super.setTitle( title );
                setVisible( true );
            }
        }

        /**
         * Overrides super impl to allow TD to take up space while not showing.
         */
        @Override
        public void setVisible( boolean visible ) {
            CommonElementHelper.setHidden( getElement(), !visible );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractFocusWidgetFormElement.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

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000