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 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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.GWT.client; import org.litesoft.commonfoundation.typeutils.*; import java.util.*; import org.litesoft.GWT.client.widgets.nonpublic.*; import org.litesoft.core.*; import com.google.gwt.event.shared.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; /** * @noinspection NonJREEmulationClassesInClientCode */ public class UtilsGwt { public static native String getURL()/*-{ return $wnd.location.href; }-*/; // redirect the browser to the given url public static native void redirect( String url )/*-{ $wnd.location.href = url; }-*/; public static native void windowResizeTo( int pWidth, int pHeight ) /*-{ $wnd.resizeTo( pWidth, pHeight ); }-*/; /** * Native method to get a cell's element. * * @param pTable the table element * @param pRow the row of the cell * @param pCol the column of the cell * * @return the TD element */ public static native Element getTableTD( Element pTable, int pRow, int pCol ) /*-{ return pTable.rows[pRow].cells[pCol]; }-*/; public static native Element getElementById( String pID ) /*-{ return $wnd.document.getElementById( pID ); }-*/; /** * Programmatically simulate a User Click Event on an Element located by ID (pID). * * @param pID ID of the element to "click". * * @return Error text - null/empty means no error. */ public static native String clickElementByID( String pID ) /*-{ var zDoc = $wnd.document; var zTarget = zDoc.getElementById( pID ); if ( zTarget ) { var zStep = 1; try { if ( zDoc.dispatchEvent ) // W3C { zStep = 2; var zEvent = document.createEvent( "MouseEvents" ); zStep = 3; zEvent.initMouseEvent( "click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, zTarget ); zStep = 4; zTarget.dispatchEvent( zEvent ); return null; } zStep = 5; if ( document.fireEvent ) // IE { zStep = 6; zTarget.fireEvent( "onclick" ); return null; } return "Un-recognized/supported Browser"; } catch ( e ) { return "Exception at " + zStep + " in clickElementByID:\n\n" + e; } } return "No Element found w/ ID: " + pID; }-*/; public static native boolean windowExists( String name ) /*-{ var winHandle = $wnd.open( "", name, "" ); return winHandle ? true : false; }-*/; public static native void ourWindowToFront() /*-{ $wnd.focus(); }-*/; public static native void windowToFront( String name ) /*-{ var winHandle = $wnd.open( "", name, "" ); winHandle.focus(); }-*/; public static native void closeWindow() /*-{ $wnd.close(); }-*/; public static native void closeWindow( String name ) /*-{ var winHandle = $wnd.open( "", name, "" ); if ( winHandle.DisableCloseConfirmFlag != true ) winHandle.DisableCloseConfirmFlag = true; winHandle.close(); }-*/; public static native boolean isDisableCloseConfirm() /*-{ return !($wnd.DisableCloseConfirmFlag != true); }-*/; public static native void setDisableCloseConfirm( boolean pDisableConfirm ) /*-{ $wnd.DisableCloseConfirmFlag = pDisableConfirm; }-*/; public static native boolean trywindowOpenWithHtml( String pName, String pFeatures, String pHTML ) /*-{ var winHandle = $wnd.open( "", pName, pFeatures ); if ( !winHandle ) { return false; } winHandle.document.write( pHTML ); winHandle.document.close(); return true; }-*/; public static native boolean tryWindowOpen( String pURL, String pName, String pFeatures ) /*-{ var winHandle = $wnd.open( pURL, pName, pFeatures ); return winHandle ? true : false; }-*/; public static boolean windowOpen( String pURL, String pName, String pFeatures ) { if ( tryWindowOpen( pURL, pName, pFeatures ) ) { return true; } popupsBlocked(); return false; } private static final String CHROMELESS = "directories=0,location=0,menubar=0,status=1,toolbar=0,resizable=1"; public static final String CHROMELESS_SCROLLED = CHROMELESS + ",scrollbars=1"; public static final String CHROMELESS_OVERFLOW = CHROMELESS + ",scrollbars=0"; public static boolean tryWindowOpenChromeless( String pURL, String pName ) { return tryWindowOpen( pURL, pName, CHROMELESS_OVERFLOW ); } public static boolean windowOpenChromeless( String pURL, String pName ) { return windowOpen( pURL, pName, CHROMELESS_OVERFLOW ); } public static void windowOpenWithHtml( String pName, String pFeatures, String pHTML ) { if ( !trywindowOpenWithHtml( pName, pFeatures, pHTML ) ) { popupsBlocked(); } } public static void windowOpenWithHtml( String pName, String pHTML ) { windowOpenWithHtml( pName, "", pHTML ); } public static void setWindowTitle( String pTitle ) { if ( sWindowNameInWindowTitle ) { pTitle += " - '" + WindowName.get() + "'"; } Window.setTitle( pTitle ); } private static boolean sWindowNameInWindowTitle = false; public static void addWindowNameToWindowTitle() { sWindowNameInWindowTitle = true; setWindowTitle( Window.getTitle() ); } private static void popupsBlocked() { AlertManager.alert( "NewClient", "Browser Configuration Error", "This application requires pop-up windows to run properly.\n\nPlease change your browser options to unblock pop-ups." ); } public static void eventPreventDefaultAndCancelBubble( Event pEvent ) { pEvent.preventDefault(); pEvent.stopPropagation(); } public static boolean wasAltKeyDownOnCurrentEvent() { return DOM.eventGetAltKey( DOM.eventGetCurrentEvent() ); } public static boolean wasCtrlKeyDownOnCurrentEvent() { // Use Command key for Macs. Ctrl key usually always triggers contextual menu on Macs. if ( UserAgent.getInstance().getPlatform() == Platform.Mac ) { return DOM.eventGetCurrentEvent().getMetaKey(); } else { return DOM.eventGetCurrentEvent().getCtrlKey(); } } public static String shortClassname( String pClassName ) { String name = "." + ClassNameFromGoogleClassToStringMethod( pClassName ) + "$"; name = name.substring( 0, name.indexOf( '$' ) ); return name.substring( name.lastIndexOf( '.' ) + 1 ); } public static String ClassNameFromGoogleClassToStringMethod( String pClassName ) { pClassName = Strings.deNull( pClassName ).trim(); int index = pClassName.indexOf( ' ' ) + 1; return index > 0 ? pClassName.substring( index ) : pClassName; } public static boolean equalGwtClassStrings( String pClassName1, String pClassName2 ) { return ClassNameFromGoogleClassToStringMethod( pClassName1 ).equals( ClassNameFromGoogleClassToStringMethod( pClassName2 ) ); } public static void closeWindowNoConfirm( int pMilliSecDelay ) { setDisableCloseConfirm( true ); new com.google.gwt.user.client.Timer() // Fully qualified as there are Multiple Versions { @Override public void run() { closeWindow(); } }.schedule( (pMilliSecDelay < 1) ? 1 : pMilliSecDelay ); } public static void closeWindowNoConfirm( String pAlertMessage ) { closeWindowNoConfirm( pAlertMessage, null ); } public static void closeWindowNoConfirm( String pAlertMessage, Exception pRootProblem ) { AlertManager.alert( "WinClose", null, pAlertMessage, pRootProblem, new DialogCloseCallBack() { @Override public void dialogClosed() { setDisableCloseConfirm( true ); closeWindow(); } } ); } private static Set<WindowClosingConfirmMessageProvider> sListeners = new HashSet<WindowClosingConfirmMessageProvider>(); public static void addListener( WindowClosingConfirmMessageProvider pListener ) { if ( pListener != null ) { if ( sListeners.add( pListener ) ) { manageWindowCloseHandler(); } } } public static boolean removeListener( WindowClosingConfirmMessageProvider pListener ) { if ( pListener != null ) { if ( sListeners.remove( pListener ) ) { manageWindowCloseHandler(); return true; } } return false; } private static void manageWindowCloseHandler() { if ( sListeners.isEmpty() ) { if ( sCloseHandlerRegistration != null ) { sCloseHandlerRegistration.removeHandler(); sCloseHandlerRegistration = null; } } else if ( sCloseHandlerRegistration == null ) { sCloseHandlerRegistration = Window.addWindowClosingHandler( sCloseHandler ); } } private static HandlerRegistration sCloseHandlerRegistration = null; private static Window.ClosingHandler sCloseHandler = new Window.ClosingHandler() { @Override public void onWindowClosing( Window.ClosingEvent pEvent ) { if ( !isDisableCloseConfirm() && !sListeners.isEmpty() ) { StringBuilder sb = new StringBuilder(); for ( WindowClosingConfirmMessageProvider zProvider : sListeners ) { String msg = zProvider.getOnWindowClosingConfirmMessage(); if ( msg != null ) { if ( sb.length() != 0 ) { sb.append( '\n' ); } sb.append( msg ); } } if ( sb.length() != 0 ) { pEvent.setMessage( sb.toString() ); } } } }; public static void busyCursor() { RootPanel.get().getElement().getStyle().setProperty( "cursor", "wait" ); } public static void regularCursor() { RootPanel.get().getElement().getStyle().setProperty( "cursor", "auto" ); } public static void hide( Widget pWidget ) { setHidden( pWidget, true ); } public static void unhide( Widget pWidget ) { setHidden( pWidget, false ); } public static void setHidden( Widget pWidget, boolean pHide ) { CommonElementHelper.setHidden( pWidget.getElement(), pHide ); } public static boolean isHidden( Widget pWidget ) { return CommonElementHelper.isHidden( pWidget.getElement() ); } public static boolean isVisible( Widget pWidget ) { return CommonElementHelper.isVisible( pWidget.getElement() ); } public static void style( Widget pWidget, String pStyleName, boolean pAdd ) { if ( pAdd ) { pWidget.addStyleName( pStyleName ); } else { pWidget.removeStyleName( pStyleName ); } } public static boolean isRecursiveVisible( Widget pWidget ) { if ( pWidget != null && pWidget.isAttached() ) { while ( !isHidden( pWidget ) && isVisible( pWidget ) ) { if ( null == (pWidget = pWidget.getParent()) ) { return true; } } } return false; } public static String getExpando( Element pElement, String pName ) { return pElement.getPropertyString( pName ); } /** * Set a non-standard attribute. */ public static void setExpando( Element pElement, String pName, String pValue ) { pElement.setPropertyString( pName, pValue ); } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/UtilsGwt.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
823 Diff | GeorgeS | Sun 19 Aug, 2012 16:10:13 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +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 |