litesoft
@ 947
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
// 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.Button; import org.litesoft.GWT.client.widgets.*; import org.litesoft.GWT.forms.client.components.*; import org.litesoft.uispecification.*; import com.google.gwt.core.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.event.logical.shared.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; public abstract class AbstractTextFieldWithPicker extends AbstractTextField { protected DialogBox mPicker; private boolean mBlurring = false; private boolean mPicking = false; private Button mPickerButton = null; private String mPickerButtonName; public AbstractTextFieldWithPicker( String pTooltip, boolean pMixedSizeChars, int pWidth, // String pPickerButtonName, DialogBox pPicker ) { super( pTooltip, pMixedSizeChars, pWidth, pWidth + 1 ); mPickerButtonName = pPickerButtonName; (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() { @Override public void onClose( CloseEvent<PopupPanel> event ) { pickerClosed( event.isAutoClosed() ); } } ); } @Override protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) { int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont ); mInnerHTMLpanel.add( (mPickerButton = createPickerButton()), "cal_" + zUniqueID ); return zUniqueID; } @Override protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) { return buildInputRowWithOptionalCell( pTrId, pInputId, "<td><div class='litesoft-PickerButtonContainer' id='cal_" + pUniqueID + "'></div></td>" ); } protected Button createPickerButton() { final Button button = PickerButton.factory( mPickerButtonName ).create(); button.addClickHandler( new ClickHandler() { @Override public void onClick( ClickEvent event ) { int absoluteLeft = button.getAbsoluteLeft(); int absoluteTop = button.getAbsoluteTop(); Object currentValue = getCurrentValue(); showPicker( absoluteLeft, absoluteTop, currentValue, mLastValidInternalFormValue ); } } ); button.setTabIndex( -1 ); button.addFocusHandler( this ); button.addBlurHandler( this ); return button; } @Override public void setEnabled( boolean pEnabled ) { if ( mPickerButton != null ) { mPickerButton.setEnabled( pEnabled ); } super.setEnabled( pEnabled ); } protected void setCursor() { TextBox textfield = getTextBox(); textfield.setFocus( true ); int length = textfield.getText().length(); textfield.setCursorPos( length ); } protected void setTextValueFromPicker( String pFromPicker ) { if ( !getCurrentText().equals( pFromPicker ) ) { setCurrentText( pFromPicker ); fireChangeListeners(); } } @Override protected void fireChangeListeners() { mInternalFormValid = false; super.fireChangeListeners(); } private boolean mInternalFormValid = false; private Object mInternalFormValue = null; private Object mLastValidInternalFormValue = null; abstract protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) throws IllegalArgumentException; @Override public Object getCurrentValue() { if ( !mInternalFormValid ) { Object zInternalFormValue = null; String currentText = getCurrentText(); if ( currentText.length() != 0 ) { try { zInternalFormValue = parseNotEmptyTextFieldToInternalForm( currentText, mLastValidInternalFormValue ); } catch ( IllegalArgumentException e ) { return new FormTextInputErrorValue( currentText, e.getMessage() ); } } mLastValidInternalFormValue = mInternalFormValue = zInternalFormValue; mInternalFormValid = true; } return mInternalFormValue; } @Override public void setCurrentValue( Object pNewValue ) { if ( pNewValue instanceof String ) { mInternalFormValid = false; setCurrentText( pNewValue.toString() ); // this line and getCurrentValue(); // .................... this one are are doing reformatting/validation! return; } mLastValidInternalFormValue = mInternalFormValue = pNewValue; mInternalFormValid = true; setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() ); } private void show( String pMsg, Object pSender ) { if ( LOGGER.trace.isEnabled() ) { LLshow( pMsg + "(" + simpleClassname( pSender ) + ")" ); } } protected void show( String pMsg, boolean pParam1 ) { if ( LOGGER.trace.isEnabled() ) { LLshow( pMsg + "(" + pParam1 + ")" ); } } protected void show( String pMsg ) { if ( LOGGER.trace.isEnabled() ) { LLshow( pMsg ); } } private void LLshow( String pMsg ) { LOGGER.trace.log( simpleClassname( this ) + " - " + pMsg + " [" + mBlurring + ":Blurring-Picking:" + mPicking + "]" ); } @Override public void publishAnyPendingChanges() { show( "publishAnyPendingChanges" ); if ( hidePicker() || mBlurring ) { mPicking = false; processDefferredBlur(); } super.publishAnyPendingChanges(); } @Override public void onFocus( FocusEvent event ) // TextBox / Button { show( "onFocus", event.getSource() ); if ( mBlurring ) { mBlurring = false; } else { super.onFocus( event ); } } @Override public void onBlur( BlurEvent event ) // TextBox / Button { show( "onLostFocus", event.getSource() ); mBlurring = true; deferBlur(); } protected void processDefferredBlur() { show( "defferredBlur" ); if ( mBlurring && !mPicking ) { mBlurring = false; // Attempt to reformat Object value = getCurrentValue(); if ( !(value instanceof String) && !(value instanceof FormTextInputErrorValue) ) { setCurrentValue( value ); } super.onBlur( null ); } } protected void deferBlur() { Scheduler.get().scheduleDeferred( new Command() { @Override public void execute() { processDefferredBlur(); } } ); } protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) { show( "showPicker" ); mBlurring = mPicking = true; setFocus(); mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, // pAbsoluteLeft, pAbsoluteTop ) ); } protected boolean hidePicker() { show( "hidePicker" ); boolean rv = mPicking; if ( mPicking ) { mPicker.hide(); } return rv; } protected void pickerClosed( boolean autoClosed ) { show( "pickerClosed", autoClosed ); mPicking = false; deferBlur(); if ( !autoClosed ) { setCursor(); } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractTextFieldWithPicker.java
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
154 Diff | GeorgeS | Tue 22 Mar, 2011 20:46:40 +0000 | |
144 Diff | GeorgeS | Mon 14 Mar, 2011 03:42:34 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |