|
@@ -1,22 +1,20 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.client; |
3 |
3 |
|
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import java.util.*; |
7 |
|
- |
|
8 |
4 |
|
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
9 |
6 |
|
import org.litesoft.core.*; |
10 |
7 |
|
|
11 |
8 |
|
import com.google.gwt.event.shared.*; |
12 |
9 |
|
import com.google.gwt.user.client.*; |
13 |
10 |
|
import com.google.gwt.user.client.ui.*; |
14 |
11 |
|
|
|
12 |
+ |
import java.util.*; |
|
13 |
+ |
|
15 |
14 |
|
/** |
16 |
15 |
|
* @noinspection NonJREEmulationClassesInClientCode |
17 |
16 |
|
*/ |
18 |
|
- |
public class UtilsGwt |
19 |
|
- |
{ |
|
17 |
+ |
public class UtilsGwt { |
20 |
18 |
|
public static native String getURL()/*-{ |
21 |
19 |
|
return $wnd.location.href; |
22 |
20 |
|
}-*/; |
|
@@ -138,10 +136,8 @@ |
138 |
136 |
|
return winHandle ? true : false; |
139 |
137 |
|
}-*/; |
140 |
138 |
|
|
141 |
|
- |
public static boolean windowOpen( String pURL, String pName, String pFeatures ) |
142 |
|
- |
{ |
143 |
|
- |
if ( tryWindowOpen( pURL, pName, pFeatures ) ) |
144 |
|
- |
{ |
|
139 |
+ |
public static boolean windowOpen( String pURL, String pName, String pFeatures ) { |
|
140 |
+ |
if ( tryWindowOpen( pURL, pName, pFeatures ) ) { |
145 |
141 |
|
return true; |
146 |
142 |
|
} |
147 |
143 |
|
popupsBlocked(); |
|
@@ -154,33 +150,26 @@ |
154 |
150 |
|
|
155 |
151 |
|
public static final String CHROMELESS_OVERFLOW = CHROMELESS + ",scrollbars=0"; |
156 |
152 |
|
|
157 |
|
- |
public static boolean tryWindowOpenChromeless( String pURL, String pName ) |
158 |
|
- |
{ |
|
153 |
+ |
public static boolean tryWindowOpenChromeless( String pURL, String pName ) { |
159 |
154 |
|
return tryWindowOpen( pURL, pName, CHROMELESS_OVERFLOW ); |
160 |
155 |
|
} |
161 |
156 |
|
|
162 |
|
- |
public static boolean windowOpenChromeless( String pURL, String pName ) |
163 |
|
- |
{ |
|
157 |
+ |
public static boolean windowOpenChromeless( String pURL, String pName ) { |
164 |
158 |
|
return windowOpen( pURL, pName, CHROMELESS_OVERFLOW ); |
165 |
159 |
|
} |
166 |
160 |
|
|
167 |
|
- |
public static void windowOpenWithHtml( String pName, String pFeatures, String pHTML ) |
168 |
|
- |
{ |
169 |
|
- |
if ( !trywindowOpenWithHtml( pName, pFeatures, pHTML ) ) |
170 |
|
- |
{ |
|
161 |
+ |
public static void windowOpenWithHtml( String pName, String pFeatures, String pHTML ) { |
|
162 |
+ |
if ( !trywindowOpenWithHtml( pName, pFeatures, pHTML ) ) { |
171 |
163 |
|
popupsBlocked(); |
172 |
164 |
|
} |
173 |
165 |
|
} |
174 |
166 |
|
|
175 |
|
- |
public static void windowOpenWithHtml( String pName, String pHTML ) |
176 |
|
- |
{ |
|
167 |
+ |
public static void windowOpenWithHtml( String pName, String pHTML ) { |
177 |
168 |
|
windowOpenWithHtml( pName, "", pHTML ); |
178 |
169 |
|
} |
179 |
170 |
|
|
180 |
|
- |
public static void setWindowTitle( String pTitle ) |
181 |
|
- |
{ |
182 |
|
- |
if ( sWindowNameInWindowTitle ) |
183 |
|
- |
{ |
|
171 |
+ |
public static void setWindowTitle( String pTitle ) { |
|
172 |
+ |
if ( sWindowNameInWindowTitle ) { |
184 |
173 |
|
pTitle += " - '" + WindowName.get() + "'"; |
185 |
174 |
|
} |
186 |
175 |
|
Window.setTitle( pTitle ); |
|
@@ -188,86 +177,69 @@ |
188 |
177 |
|
|
189 |
178 |
|
private static boolean sWindowNameInWindowTitle = false; |
190 |
179 |
|
|
191 |
|
- |
public static void addWindowNameToWindowTitle() |
192 |
|
- |
{ |
|
180 |
+ |
public static void addWindowNameToWindowTitle() { |
193 |
181 |
|
sWindowNameInWindowTitle = true; |
194 |
182 |
|
setWindowTitle( Window.getTitle() ); |
195 |
183 |
|
} |
196 |
184 |
|
|
197 |
|
- |
private static void popupsBlocked() |
198 |
|
- |
{ |
|
185 |
+ |
private static void popupsBlocked() { |
199 |
186 |
|
AlertManager.alert( "NewClient", "Browser Configuration Error", |
200 |
187 |
|
"This application requires pop-up windows to run properly.\n\nPlease change your browser options to unblock pop-ups." ); |
201 |
188 |
|
} |
202 |
189 |
|
|
203 |
|
- |
public static void eventPreventDefaultAndCancelBubble( Event pEvent ) |
204 |
|
- |
{ |
|
190 |
+ |
public static void eventPreventDefaultAndCancelBubble( Event pEvent ) { |
205 |
191 |
|
pEvent.preventDefault(); |
206 |
192 |
|
pEvent.stopPropagation(); |
207 |
193 |
|
} |
208 |
194 |
|
|
209 |
|
- |
public static boolean wasAltKeyDownOnCurrentEvent() |
210 |
|
- |
{ |
|
195 |
+ |
public static boolean wasAltKeyDownOnCurrentEvent() { |
211 |
196 |
|
return DOM.eventGetAltKey( DOM.eventGetCurrentEvent() ); |
212 |
197 |
|
} |
213 |
198 |
|
|
214 |
|
- |
public static boolean wasCtrlKeyDownOnCurrentEvent() |
215 |
|
- |
{ |
|
199 |
+ |
public static boolean wasCtrlKeyDownOnCurrentEvent() { |
216 |
200 |
|
// Use Command key for Macs. Ctrl key usually always triggers contextual menu on Macs. |
217 |
|
- |
if ( UserAgent.getInstance().getPlatform() == Platform.Mac ) |
218 |
|
- |
{ |
|
201 |
+ |
if ( UserAgent.getInstance().getPlatform() == Platform.Mac ) { |
219 |
202 |
|
return DOM.eventGetCurrentEvent().getMetaKey(); |
220 |
|
- |
} |
221 |
|
- |
else |
222 |
|
- |
{ |
|
203 |
+ |
} else { |
223 |
204 |
|
return DOM.eventGetCurrentEvent().getCtrlKey(); |
224 |
205 |
|
} |
225 |
206 |
|
} |
226 |
207 |
|
|
227 |
|
- |
public static String shortClassname( String pClassName ) |
228 |
|
- |
{ |
|
208 |
+ |
public static String shortClassname( String pClassName ) { |
229 |
209 |
|
String name = "." + ClassNameFromGoogleClassToStringMethod( pClassName ) + "$"; |
230 |
210 |
|
name = name.substring( 0, name.indexOf( '$' ) ); |
231 |
211 |
|
return name.substring( name.lastIndexOf( '.' ) + 1 ); |
232 |
212 |
|
} |
233 |
213 |
|
|
234 |
|
- |
public static String ClassNameFromGoogleClassToStringMethod( String pClassName ) |
235 |
|
- |
{ |
|
214 |
+ |
public static String ClassNameFromGoogleClassToStringMethod( String pClassName ) { |
236 |
215 |
|
pClassName = Strings.deNull( pClassName ).trim(); |
237 |
216 |
|
int index = pClassName.indexOf( ' ' ) + 1; |
238 |
217 |
|
return index > 0 ? pClassName.substring( index ) : pClassName; |
239 |
218 |
|
} |
240 |
219 |
|
|
241 |
|
- |
public static boolean equalGwtClassStrings( String pClassName1, String pClassName2 ) |
242 |
|
- |
{ |
|
220 |
+ |
public static boolean equalGwtClassStrings( String pClassName1, String pClassName2 ) { |
243 |
221 |
|
return ClassNameFromGoogleClassToStringMethod( pClassName1 ).equals( ClassNameFromGoogleClassToStringMethod( pClassName2 ) ); |
244 |
222 |
|
} |
245 |
223 |
|
|
246 |
|
- |
public static void closeWindowNoConfirm( int pMilliSecDelay ) |
247 |
|
- |
{ |
|
224 |
+ |
public static void closeWindowNoConfirm( int pMilliSecDelay ) { |
248 |
225 |
|
setDisableCloseConfirm( true ); |
249 |
226 |
|
new com.google.gwt.user.client.Timer() // Fully qualified as there are Multiple Versions |
250 |
227 |
|
{ |
251 |
228 |
|
@Override |
252 |
|
- |
public void run() |
253 |
|
- |
{ |
|
229 |
+ |
public void run() { |
254 |
230 |
|
closeWindow(); |
255 |
231 |
|
} |
256 |
232 |
|
}.schedule( (pMilliSecDelay < 1) ? 1 : pMilliSecDelay ); |
257 |
233 |
|
} |
258 |
234 |
|
|
259 |
|
- |
public static void closeWindowNoConfirm( String pAlertMessage ) |
260 |
|
- |
{ |
|
235 |
+ |
public static void closeWindowNoConfirm( String pAlertMessage ) { |
261 |
236 |
|
closeWindowNoConfirm( pAlertMessage, null ); |
262 |
237 |
|
} |
263 |
238 |
|
|
264 |
|
- |
public static void closeWindowNoConfirm( String pAlertMessage, Exception pRootProblem ) |
265 |
|
- |
{ |
266 |
|
- |
AlertManager.alert( "WinClose", null, pAlertMessage, pRootProblem, new DialogCloseCallBack() |
267 |
|
- |
{ |
|
239 |
+ |
public static void closeWindowNoConfirm( String pAlertMessage, Exception pRootProblem ) { |
|
240 |
+ |
AlertManager.alert( "WinClose", null, pAlertMessage, pRootProblem, new DialogCloseCallBack() { |
268 |
241 |
|
@Override |
269 |
|
- |
public void dialogClosed() |
270 |
|
- |
{ |
|
242 |
+ |
public void dialogClosed() { |
271 |
243 |
|
setDisableCloseConfirm( true ); |
272 |
244 |
|
closeWindow(); |
273 |
245 |
|
} |
|
@@ -276,23 +248,17 @@ |
276 |
248 |
|
|
277 |
249 |
|
private static Set<WindowClosingConfirmMessageProvider> sListeners = new HashSet<WindowClosingConfirmMessageProvider>(); |
278 |
250 |
|
|
279 |
|
- |
public static void addListener( WindowClosingConfirmMessageProvider pListener ) |
280 |
|
- |
{ |
281 |
|
- |
if ( pListener != null ) |
282 |
|
- |
{ |
283 |
|
- |
if ( sListeners.add( pListener ) ) |
284 |
|
- |
{ |
|
251 |
+ |
public static void addListener( WindowClosingConfirmMessageProvider pListener ) { |
|
252 |
+ |
if ( pListener != null ) { |
|
253 |
+ |
if ( sListeners.add( pListener ) ) { |
285 |
254 |
|
manageWindowCloseHandler(); |
286 |
255 |
|
} |
287 |
256 |
|
} |
288 |
257 |
|
} |
289 |
258 |
|
|
290 |
|
- |
public static boolean removeListener( WindowClosingConfirmMessageProvider pListener ) |
291 |
|
- |
{ |
292 |
|
- |
if ( pListener != null ) |
293 |
|
- |
{ |
294 |
|
- |
if ( sListeners.remove( pListener ) ) |
295 |
|
- |
{ |
|
259 |
+ |
public static boolean removeListener( WindowClosingConfirmMessageProvider pListener ) { |
|
260 |
+ |
if ( pListener != null ) { |
|
261 |
+ |
if ( sListeners.remove( pListener ) ) { |
296 |
262 |
|
manageWindowCloseHandler(); |
297 |
263 |
|
return true; |
298 |
264 |
|
} |
|
@@ -300,106 +266,79 @@ |
300 |
266 |
|
return false; |
301 |
267 |
|
} |
302 |
268 |
|
|
303 |
|
- |
private static void manageWindowCloseHandler() |
304 |
|
- |
{ |
305 |
|
- |
if ( sListeners.isEmpty() ) |
306 |
|
- |
{ |
307 |
|
- |
if ( sCloseHandlerRegistration != null ) |
308 |
|
- |
{ |
|
269 |
+ |
private static void manageWindowCloseHandler() { |
|
270 |
+ |
if ( sListeners.isEmpty() ) { |
|
271 |
+ |
if ( sCloseHandlerRegistration != null ) { |
309 |
272 |
|
sCloseHandlerRegistration.removeHandler(); |
310 |
273 |
|
sCloseHandlerRegistration = null; |
311 |
274 |
|
} |
312 |
|
- |
} |
313 |
|
- |
else if ( sCloseHandlerRegistration == null ) |
314 |
|
- |
{ |
|
275 |
+ |
} else if ( sCloseHandlerRegistration == null ) { |
315 |
276 |
|
sCloseHandlerRegistration = Window.addWindowClosingHandler( sCloseHandler ); |
316 |
277 |
|
} |
317 |
278 |
|
} |
318 |
279 |
|
|
319 |
280 |
|
private static HandlerRegistration sCloseHandlerRegistration = null; |
320 |
|
- |
private static Window.ClosingHandler sCloseHandler = new Window.ClosingHandler() |
321 |
|
- |
{ |
|
281 |
+ |
private static Window.ClosingHandler sCloseHandler = new Window.ClosingHandler() { |
322 |
282 |
|
@Override |
323 |
|
- |
public void onWindowClosing( Window.ClosingEvent pEvent ) |
324 |
|
- |
{ |
325 |
|
- |
if ( !isDisableCloseConfirm() && !sListeners.isEmpty() ) |
326 |
|
- |
{ |
|
283 |
+ |
public void onWindowClosing( Window.ClosingEvent pEvent ) { |
|
284 |
+ |
if ( !isDisableCloseConfirm() && !sListeners.isEmpty() ) { |
327 |
285 |
|
StringBuilder sb = new StringBuilder(); |
328 |
|
- |
for ( WindowClosingConfirmMessageProvider zProvider : sListeners ) |
329 |
|
- |
{ |
|
286 |
+ |
for ( WindowClosingConfirmMessageProvider zProvider : sListeners ) { |
330 |
287 |
|
String msg = zProvider.getOnWindowClosingConfirmMessage(); |
331 |
|
- |
if ( msg != null ) |
332 |
|
- |
{ |
333 |
|
- |
if ( sb.length() != 0 ) |
334 |
|
- |
{ |
|
288 |
+ |
if ( msg != null ) { |
|
289 |
+ |
if ( sb.length() != 0 ) { |
335 |
290 |
|
sb.append( '\n' ); |
336 |
291 |
|
} |
337 |
292 |
|
sb.append( msg ); |
338 |
293 |
|
} |
339 |
294 |
|
} |
340 |
|
- |
if ( sb.length() != 0 ) |
341 |
|
- |
{ |
|
295 |
+ |
if ( sb.length() != 0 ) { |
342 |
296 |
|
pEvent.setMessage( sb.toString() ); |
343 |
297 |
|
} |
344 |
298 |
|
} |
345 |
299 |
|
} |
346 |
300 |
|
}; |
347 |
301 |
|
|
348 |
|
- |
public static void busyCursor() |
349 |
|
- |
{ |
|
302 |
+ |
public static void busyCursor() { |
350 |
303 |
|
RootPanel.get().getElement().getStyle().setProperty( "cursor", "wait" ); |
351 |
304 |
|
} |
352 |
305 |
|
|
353 |
|
- |
public static void regularCursor() |
354 |
|
- |
{ |
|
306 |
+ |
public static void regularCursor() { |
355 |
307 |
|
RootPanel.get().getElement().getStyle().setProperty( "cursor", "auto" ); |
356 |
308 |
|
} |
357 |
309 |
|
|
358 |
|
- |
public static void hide( Widget pWidget ) |
359 |
|
- |
{ |
|
310 |
+ |
public static void hide( Widget pWidget ) { |
360 |
311 |
|
setHidden( pWidget, true ); |
361 |
312 |
|
} |
362 |
313 |
|
|
363 |
|
- |
public static void unhide( Widget pWidget ) |
364 |
|
- |
{ |
|
314 |
+ |
public static void unhide( Widget pWidget ) { |
365 |
315 |
|
setHidden( pWidget, false ); |
366 |
316 |
|
} |
367 |
317 |
|
|
368 |
|
- |
public static void setHidden( Widget pWidget, boolean pHide ) |
369 |
|
- |
{ |
|
318 |
+ |
public static void setHidden( Widget pWidget, boolean pHide ) { |
370 |
319 |
|
CommonElementHelper.setHidden( pWidget.getElement(), pHide ); |
371 |
320 |
|
} |
372 |
321 |
|
|
373 |
|
- |
public static boolean isHidden( Widget pWidget ) |
374 |
|
- |
{ |
|
322 |
+ |
public static boolean isHidden( Widget pWidget ) { |
375 |
323 |
|
return CommonElementHelper.isHidden( pWidget.getElement() ); |
376 |
324 |
|
} |
377 |
325 |
|
|
378 |
|
- |
public static boolean isVisible( Widget pWidget ) |
379 |
|
- |
{ |
|
326 |
+ |
public static boolean isVisible( Widget pWidget ) { |
380 |
327 |
|
return CommonElementHelper.isVisible( pWidget.getElement() ); |
381 |
328 |
|
} |
382 |
329 |
|
|
383 |
|
- |
public static void style( Widget pWidget, String pStyleName, boolean pAdd ) |
384 |
|
- |
{ |
385 |
|
- |
if ( pAdd ) |
386 |
|
- |
{ |
|
330 |
+ |
public static void style( Widget pWidget, String pStyleName, boolean pAdd ) { |
|
331 |
+ |
if ( pAdd ) { |
387 |
332 |
|
pWidget.addStyleName( pStyleName ); |
388 |
|
- |
} |
389 |
|
- |
else |
390 |
|
- |
{ |
|
333 |
+ |
} else { |
391 |
334 |
|
pWidget.removeStyleName( pStyleName ); |
392 |
335 |
|
} |
393 |
336 |
|
} |
394 |
337 |
|
|
395 |
|
- |
public static boolean isRecursiveVisible( Widget pWidget ) |
396 |
|
- |
{ |
397 |
|
- |
if ( pWidget != null && pWidget.isAttached() ) |
398 |
|
- |
{ |
399 |
|
- |
while ( !isHidden( pWidget ) && isVisible( pWidget ) ) |
400 |
|
- |
{ |
401 |
|
- |
if ( null == (pWidget = pWidget.getParent()) ) |
402 |
|
- |
{ |
|
338 |
+ |
public static boolean isRecursiveVisible( Widget pWidget ) { |
|
339 |
+ |
if ( pWidget != null && pWidget.isAttached() ) { |
|
340 |
+ |
while ( !isHidden( pWidget ) && isVisible( pWidget ) ) { |
|
341 |
+ |
if ( null == (pWidget = pWidget.getParent()) ) { |
403 |
342 |
|
return true; |
404 |
343 |
|
} |
405 |
344 |
|
} |
|
@@ -407,16 +346,14 @@ |
407 |
346 |
|
return false; |
408 |
347 |
|
} |
409 |
348 |
|
|
410 |
|
- |
public static String getExpando( Element pElement, String pName ) |
411 |
|
- |
{ |
|
349 |
+ |
public static String getExpando( Element pElement, String pName ) { |
412 |
350 |
|
return pElement.getPropertyString( pName ); |
413 |
351 |
|
} |
414 |
352 |
|
|
415 |
353 |
|
/** |
416 |
354 |
|
* Set a non-standard attribute. |
417 |
355 |
|
*/ |
418 |
|
- |
public static void setExpando( Element pElement, String pName, String pValue ) |
419 |
|
- |
{ |
|
356 |
+ |
public static void setExpando( Element pElement, String pName, String pValue ) { |
420 |
357 |
|
pElement.setPropertyString( pName, pValue ); |
421 |
358 |
|
} |
422 |
359 |
|
} |