|
@@ -1,159 +1,159 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
6 |
|
- |
import org.litesoft.commonfoundation.html.*; |
7 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
8 |
|
- |
import org.litesoft.core.*; |
9 |
|
- |
import org.litesoft.uispecification.*; |
10 |
|
- |
|
11 |
|
- |
import com.google.gwt.event.dom.client.*; |
12 |
|
- |
import com.google.gwt.user.client.*; |
13 |
|
- |
import com.google.gwt.user.client.ui.*; |
14 |
|
- |
|
15 |
|
- |
public abstract class AbstractFocusWidgetFormElement extends AbstractFormElement implements FocusHandler, |
16 |
|
- |
BlurHandler { |
17 |
|
- |
protected final Widget mInputWidget; |
18 |
|
- |
protected IndicatorTd mIndicatorTd = null; |
19 |
|
- |
protected Label mLabel = null; |
20 |
|
- |
|
21 |
|
- |
protected AbstractFocusWidgetFormElement( IFocusWidget pInputWidget, String pWidgetStyle, boolean pAddStyle ) { |
22 |
|
- |
super( DOM.createDiv() ); |
23 |
|
- |
mInputWidget = (Widget) pInputWidget; |
24 |
|
- |
if ( pAddStyle ) { |
25 |
|
- |
mInputWidget.addStyleName( pWidgetStyle ); |
26 |
|
- |
} else { |
27 |
|
- |
mInputWidget.setStyleName( pWidgetStyle ); |
28 |
|
- |
} |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) { |
32 |
|
- |
mFieldLabel = pFieldLabel; |
33 |
|
- |
mTooltip = pTooltip; |
34 |
|
- |
|
35 |
|
- |
buildComponentPanel( (pFieldLabel != null) ? HTMLize.escapeNoWrap( pFieldLabel ) : null, pLabelFont ); |
36 |
|
- |
|
37 |
|
- |
IFocusWidget zWidget = (IFocusWidget) mInputWidget; |
38 |
|
- |
zWidget.addFocusHandler( this ); |
39 |
|
- |
zWidget.addBlurHandler( this ); |
40 |
|
- |
|
41 |
|
- |
if ( mIndicatorTd != null ) { |
42 |
|
- |
mIndicatorTd.setTitle( pTooltip ); |
43 |
|
- |
} |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) { |
47 |
|
- |
int zUniqueID = StaticSimpleIdSource.getNext(); |
48 |
|
- |
String trId = "tr_" + zUniqueID; |
49 |
|
- |
String inputId = "input_" + zUniqueID; |
50 |
|
- |
String labelId = "label_" + zUniqueID; |
51 |
|
- |
String html = "<table cellpadding='0' cellspacing='0'>" + // |
52 |
|
- |
buildInputRow( trId, inputId, zUniqueID ) + // |
53 |
|
- |
"</table>"; |
54 |
|
- |
|
55 |
|
- |
if ( pLabel != null ) { |
56 |
|
- |
ApplyFont.to( pLabelFont, mLabel = new Label() ); |
57 |
|
- |
mLabel.addStyleName( FORM_COMPONENT_LABEL_STYLE ); |
58 |
|
- |
DOM.setInnerHTML( mLabel.getElement(), pLabel ); |
59 |
|
- |
html = "<table cellpadding='0' cellspacing='0'>" + // |
60 |
|
- |
"<tr><td id='" + labelId + "'></td></tr>" + // |
61 |
|
- |
"<tr><td>" + html + "</td></tr></table>"; |
62 |
|
- |
} |
63 |
|
- |
|
64 |
|
- |
initializeHTML( html ); |
65 |
|
- |
|
66 |
|
- |
mInnerHTMLpanel.add( getInjectedInputWidget(), inputId ); |
67 |
|
- |
addIndicator( trId ); |
68 |
|
- |
if ( mLabel != null ) { |
69 |
|
- |
mInnerHTMLpanel.add( mLabel, labelId ); |
70 |
|
- |
} |
71 |
|
- |
return zUniqueID; |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) { |
75 |
|
- |
return buildInputRowWithOptionalCell( pTrId, pInputId, "" ); |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
protected void addIndicator( String pTrId ) { |
79 |
|
- |
mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId ); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) { |
83 |
|
- |
return "<tr id='" + pTrId + "' class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + pAdditionalInputCell + "</tr>"; |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
protected Widget getInjectedInputWidget() { |
87 |
|
- |
return mInputWidget; |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
// IFormComponent |
91 |
|
- |
|
92 |
|
- |
@Override |
93 |
|
- |
public boolean setFocus() { |
94 |
|
- |
if ( mInputWidget instanceof Focusable ) { |
95 |
|
- |
pullFocusTo( (Focusable) mInputWidget ); |
96 |
|
- |
return true; |
97 |
|
- |
} |
98 |
|
- |
return false; |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
@Override |
102 |
|
- |
public void setEnabled( boolean pEnabled ) { |
103 |
|
- |
mEnabled = pEnabled; |
104 |
|
- |
((IFocusWidget) mInputWidget).setEnabled( pEnabled ); |
105 |
|
- |
stateChanged(); |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
// Focus & Blur Handlers |
109 |
|
- |
|
110 |
|
- |
@Override |
111 |
|
- |
public void onFocus( FocusEvent event ) { |
112 |
|
- |
fireFocusListeners(); |
113 |
|
- |
} |
114 |
|
- |
|
115 |
|
- |
@Override |
116 |
|
- |
public void onBlur( BlurEvent event ) { |
117 |
|
- |
fireBlurListeners(); |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
// Support... |
121 |
|
- |
|
122 |
|
- |
public static class IndicatorTd extends Widget { |
123 |
|
- |
public IndicatorTd() { |
124 |
|
- |
Element td = DOM.createTD(); |
125 |
|
- |
CommonElementHelper.setStyleClass( td, "litesoft-FormComponentIndicatorContainer" ); |
126 |
|
- |
DOM.setElementProperty( td, "align", "center" ); |
127 |
|
- |
|
128 |
|
- |
setElement( td ); |
129 |
|
- |
|
130 |
|
- |
Element icon = DOM.createDiv(); |
131 |
|
- |
CommonElementHelper.setStyleClass( icon, "litesoft-FormComponentIndicator" ); |
132 |
|
- |
DOM.setStyleAttribute( icon, "fontSize", "0" ); |
133 |
|
- |
|
134 |
|
- |
DOM.appendChild( td, icon ); |
135 |
|
- |
|
136 |
|
- |
setVisible( false ); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
@Override |
140 |
|
- |
public void setTitle( String title ) { |
141 |
|
- |
title = Strings.noEmpty( title ); |
142 |
|
- |
if ( title == null ) { |
143 |
|
- |
super.setTitle( "" ); |
144 |
|
- |
setVisible( false ); |
145 |
|
- |
} else { |
146 |
|
- |
super.setTitle( title ); |
147 |
|
- |
setVisible( true ); |
148 |
|
- |
} |
149 |
|
- |
} |
150 |
|
- |
|
151 |
|
- |
/** |
152 |
|
- |
* Overrides super impl to allow TD to take up space while not showing. |
153 |
|
- |
*/ |
154 |
|
- |
@Override |
155 |
|
- |
public void setVisible( boolean visible ) { |
156 |
|
- |
CommonElementHelper.setHidden( getElement(), !visible ); |
157 |
|
- |
} |
158 |
|
- |
} |
159 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
7 |
+ |
import org.litesoft.commonfoundation.html.*; |
|
8 |
+ |
import org.litesoft.core.*; |
|
9 |
+ |
import org.litesoft.uispecification.*; |
|
10 |
+ |
|
|
11 |
+ |
import com.google.gwt.event.dom.client.*; |
|
12 |
+ |
import com.google.gwt.user.client.*; |
|
13 |
+ |
import com.google.gwt.user.client.ui.*; |
|
14 |
+ |
|
|
15 |
+ |
public abstract class AbstractFocusWidgetFormElement extends AbstractFormElement implements FocusHandler, |
|
16 |
+ |
BlurHandler { |
|
17 |
+ |
protected final Widget mInputWidget; |
|
18 |
+ |
protected IndicatorTd mIndicatorTd = null; |
|
19 |
+ |
protected Label mLabel = null; |
|
20 |
+ |
|
|
21 |
+ |
protected AbstractFocusWidgetFormElement( IFocusWidget pInputWidget, String pWidgetStyle, boolean pAddStyle ) { |
|
22 |
+ |
super( DOM.createDiv() ); |
|
23 |
+ |
mInputWidget = (Widget) pInputWidget; |
|
24 |
+ |
if ( pAddStyle ) { |
|
25 |
+ |
mInputWidget.addStyleName( pWidgetStyle ); |
|
26 |
+ |
} else { |
|
27 |
+ |
mInputWidget.setStyleName( pWidgetStyle ); |
|
28 |
+ |
} |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) { |
|
32 |
+ |
mFieldLabel = pFieldLabel; |
|
33 |
+ |
mTooltip = pTooltip; |
|
34 |
+ |
|
|
35 |
+ |
buildComponentPanel( (pFieldLabel != null) ? HTMLize.escapeNoWrap( pFieldLabel ) : null, pLabelFont ); |
|
36 |
+ |
|
|
37 |
+ |
IFocusWidget zWidget = (IFocusWidget) mInputWidget; |
|
38 |
+ |
zWidget.addFocusHandler( this ); |
|
39 |
+ |
zWidget.addBlurHandler( this ); |
|
40 |
+ |
|
|
41 |
+ |
if ( mIndicatorTd != null ) { |
|
42 |
+ |
mIndicatorTd.setTitle( pTooltip ); |
|
43 |
+ |
} |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) { |
|
47 |
+ |
int zUniqueID = StaticSimpleIdSource.getNext(); |
|
48 |
+ |
String trId = "tr_" + zUniqueID; |
|
49 |
+ |
String inputId = "input_" + zUniqueID; |
|
50 |
+ |
String labelId = "label_" + zUniqueID; |
|
51 |
+ |
String html = "<table cellpadding='0' cellspacing='0'>" + // |
|
52 |
+ |
buildInputRow( trId, inputId, zUniqueID ) + // |
|
53 |
+ |
"</table>"; |
|
54 |
+ |
|
|
55 |
+ |
if ( pLabel != null ) { |
|
56 |
+ |
ApplyFont.to( pLabelFont, mLabel = new Label() ); |
|
57 |
+ |
mLabel.addStyleName( FORM_COMPONENT_LABEL_STYLE ); |
|
58 |
+ |
DOM.setInnerHTML( mLabel.getElement(), pLabel ); |
|
59 |
+ |
html = "<table cellpadding='0' cellspacing='0'>" + // |
|
60 |
+ |
"<tr><td id='" + labelId + "'></td></tr>" + // |
|
61 |
+ |
"<tr><td>" + html + "</td></tr></table>"; |
|
62 |
+ |
} |
|
63 |
+ |
|
|
64 |
+ |
initializeHTML( html ); |
|
65 |
+ |
|
|
66 |
+ |
mInnerHTMLpanel.add( getInjectedInputWidget(), inputId ); |
|
67 |
+ |
addIndicator( trId ); |
|
68 |
+ |
if ( mLabel != null ) { |
|
69 |
+ |
mInnerHTMLpanel.add( mLabel, labelId ); |
|
70 |
+ |
} |
|
71 |
+ |
return zUniqueID; |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) { |
|
75 |
+ |
return buildInputRowWithOptionalCell( pTrId, pInputId, "" ); |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
protected void addIndicator( String pTrId ) { |
|
79 |
+ |
mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId ); |
|
80 |
+ |
} |
|
81 |
+ |
|
|
82 |
+ |
protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) { |
|
83 |
+ |
return "<tr id='" + pTrId + "' class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + pAdditionalInputCell + "</tr>"; |
|
84 |
+ |
} |
|
85 |
+ |
|
|
86 |
+ |
protected Widget getInjectedInputWidget() { |
|
87 |
+ |
return mInputWidget; |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
// IFormComponent |
|
91 |
+ |
|
|
92 |
+ |
@Override |
|
93 |
+ |
public boolean setFocus() { |
|
94 |
+ |
if ( mInputWidget instanceof Focusable ) { |
|
95 |
+ |
pullFocusTo( (Focusable) mInputWidget ); |
|
96 |
+ |
return true; |
|
97 |
+ |
} |
|
98 |
+ |
return false; |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
@Override |
|
102 |
+ |
public void setEnabled( boolean pEnabled ) { |
|
103 |
+ |
mEnabled = pEnabled; |
|
104 |
+ |
((IFocusWidget) mInputWidget).setEnabled( pEnabled ); |
|
105 |
+ |
stateChanged(); |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
// Focus & Blur Handlers |
|
109 |
+ |
|
|
110 |
+ |
@Override |
|
111 |
+ |
public void onFocus( FocusEvent event ) { |
|
112 |
+ |
fireFocusListeners(); |
|
113 |
+ |
} |
|
114 |
+ |
|
|
115 |
+ |
@Override |
|
116 |
+ |
public void onBlur( BlurEvent event ) { |
|
117 |
+ |
fireBlurListeners(); |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
// Support... |
|
121 |
+ |
|
|
122 |
+ |
public static class IndicatorTd extends Widget { |
|
123 |
+ |
public IndicatorTd() { |
|
124 |
+ |
Element td = DOM.createTD(); |
|
125 |
+ |
CommonElementHelper.setStyleClass( td, "litesoft-FormComponentIndicatorContainer" ); |
|
126 |
+ |
DOM.setElementProperty( td, "align", "center" ); |
|
127 |
+ |
|
|
128 |
+ |
setElement( td ); |
|
129 |
+ |
|
|
130 |
+ |
Element icon = DOM.createDiv(); |
|
131 |
+ |
CommonElementHelper.setStyleClass( icon, "litesoft-FormComponentIndicator" ); |
|
132 |
+ |
DOM.setStyleAttribute( icon, "fontSize", "0" ); |
|
133 |
+ |
|
|
134 |
+ |
DOM.appendChild( td, icon ); |
|
135 |
+ |
|
|
136 |
+ |
setVisible( false ); |
|
137 |
+ |
} |
|
138 |
+ |
|
|
139 |
+ |
@Override |
|
140 |
+ |
public void setTitle( String title ) { |
|
141 |
+ |
title = ConstrainTo.significantOrNull( title ); |
|
142 |
+ |
if ( title == null ) { |
|
143 |
+ |
super.setTitle( "" ); |
|
144 |
+ |
setVisible( false ); |
|
145 |
+ |
} else { |
|
146 |
+ |
super.setTitle( title ); |
|
147 |
+ |
setVisible( true ); |
|
148 |
+ |
} |
|
149 |
+ |
} |
|
150 |
+ |
|
|
151 |
+ |
/** |
|
152 |
+ |
* Overrides super impl to allow TD to take up space while not showing. |
|
153 |
+ |
*/ |
|
154 |
+ |
@Override |
|
155 |
+ |
public void setVisible( boolean visible ) { |
|
156 |
+ |
CommonElementHelper.setHidden( getElement(), !visible ); |
|
157 |
+ |
} |
|
158 |
+ |
} |
|
159 |
+ |
} |