Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractTextFieldWithPicker.java

Diff revisions: vs.
  @@ -1,233 +1,233 @@
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.Button;
5 - import org.litesoft.GWT.client.widgets.*;
6 - import org.litesoft.GWT.forms.client.components.*;
7 - import org.litesoft.uispecification.*;
8 -
9 - import com.google.gwt.core.client.*;
10 - import com.google.gwt.event.dom.client.*;
11 - import com.google.gwt.event.logical.shared.*;
12 - import com.google.gwt.user.client.*;
13 - import com.google.gwt.user.client.ui.*;
14 -
15 - public abstract class AbstractTextFieldWithPicker extends AbstractTextField {
16 - protected DialogBox mPicker;
17 - private boolean mBlurring = false;
18 - private boolean mPicking = false;
19 - private Button mPickerButton = null;
20 - private String mPickerButtonName;
21 -
22 - public AbstractTextFieldWithPicker( String pTooltip, boolean pMixedSizeChars, int pWidth, //
23 - String pPickerButtonName, DialogBox pPicker ) {
24 - super( pTooltip, pMixedSizeChars, pWidth, pWidth + 1 );
25 - mPickerButtonName = pPickerButtonName;
26 - (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() {
27 - @Override
28 - public void onClose( CloseEvent<PopupPanel> event ) {
29 - pickerClosed( event.isAutoClosed() );
30 - }
31 - } );
32 - }
33 -
34 - @Override
35 - protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
36 - int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont );
37 - mInnerHTMLpanel.add( (mPickerButton = createPickerButton()), "cal_" + zUniqueID );
38 - return zUniqueID;
39 - }
40 -
41 - @Override
42 - protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
43 - return buildInputRowWithOptionalCell( pTrId, pInputId, "<td><div class='litesoft-PickerButtonContainer' id='cal_" + pUniqueID + "'></div></td>" );
44 - }
45 -
46 - protected Button createPickerButton() {
47 - final Button button = PickerButton.factory( mPickerButtonName ).create();
48 -
49 - button.addClickHandler( new ClickHandler() {
50 - @Override
51 - public void onClick( ClickEvent event ) {
52 - int absoluteLeft = button.getAbsoluteLeft();
53 - int absoluteTop = button.getAbsoluteTop();
54 -
55 - Object currentValue = getCurrentValue();
56 - showPicker( absoluteLeft, absoluteTop, currentValue, mLastValidInternalFormValue );
57 - }
58 - } );
59 -
60 - button.setTabIndex( -1 );
61 -
62 - button.addFocusHandler( this );
63 - button.addBlurHandler( this );
64 -
65 - return button;
66 - }
67 -
68 - @Override
69 - public void setEnabled( boolean pEnabled ) {
70 - if ( mPickerButton != null ) {
71 - mPickerButton.setEnabled( pEnabled );
72 - }
73 - super.setEnabled( pEnabled );
74 - }
75 -
76 - protected void setCursor() {
77 - TextBox textfield = getTextBox();
78 - textfield.setFocus( true );
79 - int length = textfield.getText().length();
80 - textfield.setCursorPos( length );
81 - }
82 -
83 - protected void setTextValueFromPicker( String pFromPicker ) {
84 - if ( !getCurrentText().equals( pFromPicker ) ) {
85 - setCurrentText( pFromPicker );
86 - fireChangeListeners();
87 - }
88 - }
89 -
90 - @Override
91 - protected void fireChangeListeners() {
92 - mInternalFormValid = false;
93 - super.fireChangeListeners();
94 - }
95 -
96 - private boolean mInternalFormValid = false;
97 - private Object mInternalFormValue = null;
98 - private Object mLastValidInternalFormValue = null;
99 -
100 - abstract protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue )
101 - throws IllegalArgumentException;
102 -
103 - @Override
104 - public Object getCurrentValue() {
105 - if ( !mInternalFormValid ) {
106 - Object zInternalFormValue = null;
107 - String currentText = getCurrentText();
108 - if ( currentText.length() != 0 ) {
109 - try {
110 - zInternalFormValue = parseNotEmptyTextFieldToInternalForm( currentText, mLastValidInternalFormValue );
111 - }
112 - catch ( IllegalArgumentException e ) {
113 - return new FormTextInputErrorValue( currentText, e.getMessage() );
114 - }
115 - }
116 - mLastValidInternalFormValue = mInternalFormValue = zInternalFormValue;
117 - mInternalFormValid = true;
118 - }
119 - return mInternalFormValue;
120 - }
121 -
122 - @Override
123 - public void setCurrentValue( Object pNewValue ) {
124 - if ( pNewValue instanceof String ) {
125 - mInternalFormValid = false;
126 - setCurrentText( pNewValue.toString() ); // this line and
127 - getCurrentValue(); // .................... this one are are doing reformatting/validation!
128 - return;
129 - }
130 - mLastValidInternalFormValue = mInternalFormValue = pNewValue;
131 - mInternalFormValid = true;
132 - setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() );
133 - }
134 -
135 - private void show( String pMsg, Object pSender ) {
136 - if ( LOGGER.trace.isEnabled() ) {
137 - LLshow( pMsg + "(" + simpleClassname( pSender ) + ")" );
138 - }
139 - }
140 -
141 - protected void show( String pMsg, boolean pParam1 ) {
142 - if ( LOGGER.trace.isEnabled() ) {
143 - LLshow( pMsg + "(" + pParam1 + ")" );
144 - }
145 - }
146 -
147 - protected void show( String pMsg ) {
148 - if ( LOGGER.trace.isEnabled() ) {
149 - LLshow( pMsg );
150 - }
151 - }
152 -
153 - private void LLshow( String pMsg ) {
154 - LOGGER.trace.log( simpleClassname( this ) + " - " + pMsg + " [" + mBlurring + ":Blurring-Picking:" + mPicking + "]" );
155 - }
156 -
157 - @Override
158 - public void publishAnyPendingChanges() {
159 - show( "publishAnyPendingChanges" );
160 - if ( hidePicker() || mBlurring ) {
161 - mPicking = false;
162 - processDefferredBlur();
163 - }
164 - super.publishAnyPendingChanges();
165 - }
166 -
167 - @Override
168 - public void onFocus( FocusEvent event ) // TextBox / Button
169 - {
170 - show( "onFocus", event.getSource() );
171 - if ( mBlurring ) {
172 - mBlurring = false;
173 - } else {
174 - super.onFocus( event );
175 - }
176 - }
177 -
178 - @Override
179 - public void onBlur( BlurEvent event ) // TextBox / Button
180 - {
181 - show( "onLostFocus", event.getSource() );
182 - mBlurring = true;
183 - deferBlur();
184 - }
185 -
186 - protected void processDefferredBlur() {
187 - show( "defferredBlur" );
188 - if ( mBlurring && !mPicking ) {
189 - mBlurring = false;
190 - // Attempt to reformat
191 - Object value = getCurrentValue();
192 - if ( !(value instanceof String) && !(value instanceof FormTextInputErrorValue) ) {
193 - setCurrentValue( value );
194 - }
195 - super.onBlur( null );
196 - }
197 - }
198 -
199 - protected void deferBlur() {
200 - Scheduler.get().scheduleDeferred( new Command() {
201 - @Override
202 - public void execute() {
203 - processDefferredBlur();
204 - }
205 - } );
206 - }
207 -
208 - protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) {
209 - show( "showPicker" );
210 - mBlurring = mPicking = true;
211 - setFocus();
212 - mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, //
213 - pAbsoluteLeft, pAbsoluteTop ) );
214 - }
215 -
216 - protected boolean hidePicker() {
217 - show( "hidePicker" );
218 - boolean rv = mPicking;
219 - if ( mPicking ) {
220 - mPicker.hide();
221 - }
222 - return rv;
223 - }
224 -
225 - protected void pickerClosed( boolean autoClosed ) {
226 - show( "pickerClosed", autoClosed );
227 - mPicking = false;
228 - deferBlur();
229 - if ( !autoClosed ) {
230 - setCursor();
231 - }
232 - }
233 - }
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.Button;
5 + import org.litesoft.GWT.client.widgets.*;
6 + import org.litesoft.GWT.forms.client.components.*;
7 + import org.litesoft.uispecification.*;
8 +
9 + import com.google.gwt.core.client.*;
10 + import com.google.gwt.event.dom.client.*;
11 + import com.google.gwt.event.logical.shared.*;
12 + import com.google.gwt.user.client.*;
13 + import com.google.gwt.user.client.ui.*;
14 +
15 + public abstract class AbstractTextFieldWithPicker extends AbstractTextField {
16 + protected DialogBox mPicker;
17 + private boolean mBlurring = false;
18 + private boolean mPicking = false;
19 + private Button mPickerButton = null;
20 + private String mPickerButtonName;
21 +
22 + public AbstractTextFieldWithPicker( String pTooltip, boolean pMixedSizeChars, int pWidth, //
23 + String pPickerButtonName, DialogBox pPicker ) {
24 + super( pTooltip, pMixedSizeChars, pWidth, pWidth + 1 );
25 + mPickerButtonName = pPickerButtonName;
26 + (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() {
27 + @Override
28 + public void onClose( CloseEvent<PopupPanel> event ) {
29 + pickerClosed( event.isAutoClosed() );
30 + }
31 + } );
32 + }
33 +
34 + @Override
35 + protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
36 + int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont );
37 + mInnerHTMLpanel.add( (mPickerButton = createPickerButton()), "cal_" + zUniqueID );
38 + return zUniqueID;
39 + }
40 +
41 + @Override
42 + protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
43 + return buildInputRowWithOptionalCell( pTrId, pInputId, "<td><div class='litesoft-PickerButtonContainer' id='cal_" + pUniqueID + "'></div></td>" );
44 + }
45 +
46 + protected Button createPickerButton() {
47 + final Button button = PickerButton.factory( mPickerButtonName ).create();
48 +
49 + button.addClickHandler( new ClickHandler() {
50 + @Override
51 + public void onClick( ClickEvent event ) {
52 + int absoluteLeft = button.getAbsoluteLeft();
53 + int absoluteTop = button.getAbsoluteTop();
54 +
55 + Object currentValue = getCurrentValue();
56 + showPicker( absoluteLeft, absoluteTop, currentValue, mLastValidInternalFormValue );
57 + }
58 + } );
59 +
60 + button.setTabIndex( -1 );
61 +
62 + button.addFocusHandler( this );
63 + button.addBlurHandler( this );
64 +
65 + return button;
66 + }
67 +
68 + @Override
69 + public void setEnabled( boolean pEnabled ) {
70 + if ( mPickerButton != null ) {
71 + mPickerButton.setEnabled( pEnabled );
72 + }
73 + super.setEnabled( pEnabled );
74 + }
75 +
76 + protected void setCursor() {
77 + TextBox textfield = getTextBox();
78 + textfield.setFocus( true );
79 + int length = textfield.getText().length();
80 + textfield.setCursorPos( length );
81 + }
82 +
83 + protected void setTextValueFromPicker( String pFromPicker ) {
84 + if ( !getCurrentText().equals( pFromPicker ) ) {
85 + setCurrentText( pFromPicker );
86 + fireChangeListeners();
87 + }
88 + }
89 +
90 + @Override
91 + protected void fireChangeListeners() {
92 + mInternalFormValid = false;
93 + super.fireChangeListeners();
94 + }
95 +
96 + private boolean mInternalFormValid = false;
97 + private Object mInternalFormValue = null;
98 + private Object mLastValidInternalFormValue = null;
99 +
100 + abstract protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue )
101 + throws IllegalArgumentException;
102 +
103 + @Override
104 + public Object getCurrentValue() {
105 + if ( !mInternalFormValid ) {
106 + Object zInternalFormValue = null;
107 + String currentText = getCurrentText();
108 + if ( currentText.length() != 0 ) {
109 + try {
110 + zInternalFormValue = parseNotEmptyTextFieldToInternalForm( currentText, mLastValidInternalFormValue );
111 + }
112 + catch ( IllegalArgumentException e ) {
113 + return new FormTextInputErrorValue( currentText, e.getMessage() );
114 + }
115 + }
116 + mLastValidInternalFormValue = mInternalFormValue = zInternalFormValue;
117 + mInternalFormValid = true;
118 + }
119 + return mInternalFormValue;
120 + }
121 +
122 + @Override
123 + public void setCurrentValue( Object pNewValue ) {
124 + if ( pNewValue instanceof String ) {
125 + mInternalFormValid = false;
126 + setCurrentText( pNewValue.toString() ); // this line and
127 + getCurrentValue(); // .................... this one are are doing reformatting/validation!
128 + return;
129 + }
130 + mLastValidInternalFormValue = mInternalFormValue = pNewValue;
131 + mInternalFormValid = true;
132 + setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() );
133 + }
134 +
135 + private void show( String pMsg, Object pSender ) {
136 + if ( LOGGER.trace.isEnabled() ) {
137 + LLshow( pMsg + "(" + simpleClassname( pSender ) + ")" );
138 + }
139 + }
140 +
141 + protected void show( String pMsg, boolean pParam1 ) {
142 + if ( LOGGER.trace.isEnabled() ) {
143 + LLshow( pMsg + "(" + pParam1 + ")" );
144 + }
145 + }
146 +
147 + protected void show( String pMsg ) {
148 + if ( LOGGER.trace.isEnabled() ) {
149 + LLshow( pMsg );
150 + }
151 + }
152 +
153 + private void LLshow( String pMsg ) {
154 + LOGGER.trace.log( simpleClassname( this ) + " - " + pMsg + " [" + mBlurring + ":Blurring-Picking:" + mPicking + "]" );
155 + }
156 +
157 + @Override
158 + public void publishAnyPendingChanges() {
159 + show( "publishAnyPendingChanges" );
160 + if ( hidePicker() || mBlurring ) {
161 + mPicking = false;
162 + processDefferredBlur();
163 + }
164 + super.publishAnyPendingChanges();
165 + }
166 +
167 + @Override
168 + public void onFocus( FocusEvent event ) // TextBox / Button
169 + {
170 + show( "onFocus", event.getSource() );
171 + if ( mBlurring ) {
172 + mBlurring = false;
173 + } else {
174 + super.onFocus( event );
175 + }
176 + }
177 +
178 + @Override
179 + public void onBlur( BlurEvent event ) // TextBox / Button
180 + {
181 + show( "onLostFocus", event.getSource() );
182 + mBlurring = true;
183 + deferBlur();
184 + }
185 +
186 + protected void processDefferredBlur() {
187 + show( "defferredBlur" );
188 + if ( mBlurring && !mPicking ) {
189 + mBlurring = false;
190 + // Attempt to reformat
191 + Object value = getCurrentValue();
192 + if ( !(value instanceof String) && !(value instanceof FormTextInputErrorValue) ) {
193 + setCurrentValue( value );
194 + }
195 + super.onBlur( null );
196 + }
197 + }
198 +
199 + protected void deferBlur() {
200 + Scheduler.get().scheduleDeferred( new Command() {
201 + @Override
202 + public void execute() {
203 + processDefferredBlur();
204 + }
205 + } );
206 + }
207 +
208 + protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) {
209 + show( "showPicker" );
210 + mBlurring = mPicking = true;
211 + setFocus();
212 + mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, //
213 + pAbsoluteLeft, pAbsoluteTop ) );
214 + }
215 +
216 + protected boolean hidePicker() {
217 + show( "hidePicker" );
218 + boolean rv = mPicking;
219 + if ( mPicking ) {
220 + mPicker.hide();
221 + }
222 + return rv;
223 + }
224 +
225 + protected void pickerClosed( boolean autoClosed ) {
226 + show( "pickerClosed", autoClosed );
227 + mPicking = false;
228 + deferBlur();
229 + if ( !autoClosed ) {
230 + setCursor();
231 + }
232 + }
233 + }