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
|
package org.litesoft.GWT.forms.client.components.nonpublic;
import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.core.*;
import org.litesoft.core.util.*;
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
public boolean setFocus()
{
if ( mInputWidget instanceof Focusable )
{
pullFocusTo( (Focusable) mInputWidget );
return true;
}
return false;
}
public void setEnabled( boolean pEnabled )
{
mEnabled = pEnabled;
((IFocusWidget) mInputWidget).setEnabled( pEnabled );
stateChanged();
}
// Focus & Blur Handlers
public void onFocus( FocusEvent event )
{
fireFocusListeners();
}
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 );
}
public void setTitle( String title )
{
title = UtilsGwt.noEmpty( 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.
*/
public void setVisible( boolean visible )
{
CommonElementHelper.setHidden( getElement(), !visible );
}
}
}
|