litesoft
@ 948
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / util / UtilsGwt.java
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 |
package com.temp.client.foundation.util; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; import com.temp.client.foundation.widget.*; import java.util.*; /** * This Utility class provides low level support for GWT Widgets & UI. * * @author georgs */ public class UtilsGwt { 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 widget ) { setHidden( widget, true ); } public static void unhide( Widget widget ) { setHidden( widget, false ); } public static void setHidden( Widget widget, boolean hide ) { if ( widget != null ) { CommonElementHelper.setHidden( widget.getElement(), hide ); } } public static boolean isHidden( Widget widget ) { return CommonElementHelper.isHidden( widget.getElement() ); } public static boolean isVisible( Widget widget ) { return CommonElementHelper.isVisible( widget.getElement() ); } public static boolean isRecursiveVisible( Widget widget ) { if ( widget != null && widget.isAttached() ) { while ( !isHidden( widget ) && isVisible( widget ) ) { if ( null == (widget = widget.getParent()) ) { return true; } } } return false; } public static void enableWithStyle( boolean enable, Widget widget, String enabledCssClassName, String disabledCssClassName ) { if ( enable ) { changeStyleOnFromTo( widget, disabledCssClassName, enabledCssClassName ); } else { changeStyleOnFromTo( widget, enabledCssClassName, disabledCssClassName ); } } public static void changeStyleOnFromTo( Widget widget, String fromCssClassName, String toCssClassName ) { widget.removeStyleName( fromCssClassName ); widget.addStyleName( toCssClassName ); } public static String getMetaElementContent( String id ) { Element metaElement = DOM.getElementById( id ); return (metaElement == null) ? null : metaElement.getAttribute( "content" ); } public static String getCustomerFullName() { return UtilsGwt.getMetaElementContent( "meta-username" ); } public static String getCustomerEmailId() { return UtilsGwt.getMetaElementContent( "meta-email" ); } public static Widget horizontal( Widget... pWidgets ) { HorizontalPanel zPanel = new HorizontalPanel(); if ( pWidgets != null ) { for ( Widget zWidget : pWidgets ) { if ( zWidget != null ) { zPanel.add( zWidget ); } } } if ( zPanel.getWidgetCount() == 0 ) { zPanel.add( new Spacer() ); } return zPanel; } public static VerticalPanel vertical( String styleClassName ) { VerticalPanel zPanel = new VerticalPanel(); zPanel.addStyleName( styleClassName ); return zPanel; } public static VerticalPanel add( VerticalPanel panel, IsWidget widget ) { return (widget == null) ? panel : add( panel, widget.asWidget() ); } public static VerticalPanel add( VerticalPanel panel, Widget widget ) { if ( (panel != null) && (widget != null) ) { panel.add( widget ); } return panel; } /** * set the "ID" of the Widget to a simplified class Name. * <p/> * Simplified class Name is one that: * <ol> * <li>Ignores Inner Classes (removes '$' and anything after)</li> * <li>Removes the "package" (everything thru the last '.')</li> * <li>Removes "Impl" from the end if there</li> * </ol> * e.g. * "com.temp.client.module.dashboard.dash.DashViewImpl$1" -> * "DashView" */ public static void setIdToClassNameOf( Widget widget, Object forClassName ) { if ( (widget != null) && (forClassName != null) ) { String name = "." + forClassName.getClass().getName() + "$"; name = name.substring( 0, name.indexOf( '$' ) ); name = name.substring( name.lastIndexOf( '.' ) + 1 ); if ( name.endsWith( "Impl" ) ) { name = name.substring( 0, name.length() - 4 ); } widget.getElement().setId( name ); } } public static native void openWithFocus( String url, String name, String features ) /*-{ var win = $wnd.open( url, name, features ); win.focus(); }-*/; public static final String CHROMELESS_SCROLLABLE_WITH_MENUS = "directories=0,location=0,toolbar=0,status=1,resizable=1,scrollbars=1,menubar=1"; public static void windowOpenWithHtml( String pName, String pFeatures, String pHTML ) { if ( !trywindowOpenWithHtml( pName, pFeatures, pHTML ) ) { popupsBlocked(); } } 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; }-*/; private static void popupsBlocked() { Window.alert( "Browser Configuration Error\n\n\nThis feature requires pop-up windows to run properly.\n\nPlease change your browser options to unblock " + "pop-ups." ); } public static String convertToString( List<String> inputList ) { String result = null; if ( inputList != null ) { result = inputList.toString(); result = result.substring( 0, result.length() - 1 ); } return result; } } |