Subversion Repository Public Repository

litesoft

Diff Revisions 528 vs 529 for /trunk/GWT_Sandbox/Upload/src/org/litesoft/sandbox/csapp/client/widgets/UploadWidget.java

Diff revisions: vs.
  @@ -7,6 +7,11 @@
7 7
8 8 public class UploadWidget extends Composite implements IsWidget
9 9 {
10 + private static final String BUSY_IMAGE_URL = "common/Money.gif";
11 + private static final int SECONDS_TO_WAIT = 30;
12 + private static final String[] BUSY_PRE_SECONDS_REMAINING_MESSAGE = {"Checking Certificate Validity,", "this can take a while..."};
13 + private static final String[] BUSY_POST_SECONDS_REMAINING_MESSAGE = {"seconds until timeout."};
14 +
10 15 private static int instance = 1;
11 16
12 17 private final FileUpload upload = createFileUploadWidget();
  @@ -249,29 +254,114 @@
249 254
250 255 protected void hideBusy()
251 256 {
252 - busyPopup.hide();
253 - busyPopup = null;
257 + if ( busyPopup != null )
258 + {
259 + busyPopup.hide();
260 + busyPopup = null;
261 + }
254 262 }
255 263
256 264 protected void showBusy()
257 265 {
258 - if ( busyPopup == null )
266 + hideBusy();
267 + (busyPopup = new OurBusyPopup()).setPopupPositionAndShow( new PopupPanel.PositionCallback()
259 268 {
260 - busyPopup = new OurBusyPopup();
261 - }
262 - busyPopup.show();
269 + @Override
270 + public void setPosition( int offsetWidth, int offsetHeight )
271 + {
272 + int left = (Window.getClientWidth() - offsetWidth) / 2;
273 + int top = (Window.getClientHeight() - offsetHeight) / 2;
274 + busyPopup.setPopupPosition( left, top );
275 + }
276 + } );
263 277 }
264 278
265 279 private OurBusyPopup busyPopup;
266 280
267 281 private class OurBusyPopup extends PopupPanel
268 282 {
283 + private Widget messageWidget;
284 + private boolean messageShowing = false;
285 + private int secondsRemaining = SECONDS_TO_WAIT;
286 + private Label secondsRemainingLabel = new Label( "" + secondsRemaining );
287 + private long started = System.currentTimeMillis();
288 + private float currentOpacity = 0;
289 + private Timer timer;
290 +
269 291 private OurBusyPopup()
270 292 {
271 293 setModal( true );
272 294 setGlassEnabled( true );
273 - getGlassElement().getStyle().setOpacity( 0.5 );
274 - setWidget( new Image( "common/Money.gif" ) );
295 + getGlassElement().getStyle().setBackgroundColor( "#fff" );
296 + getGlassElement().getStyle().setCursor( Style.Cursor.WAIT );
297 + getGlassElement().getStyle().setOpacity( currentOpacity );
298 +
299 + VerticalPanel panel = new VerticalPanel();
300 + panel.setStyleName( "UploadWidgetBusyMessage" );
301 + panel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
302 + panel.add( new Image( BUSY_IMAGE_URL ) );
303 + panel.add( new HTML( " " ) );
304 + for ( String line : BUSY_PRE_SECONDS_REMAINING_MESSAGE )
305 + {
306 + panel.add( new Label( line ) );
307 + }
308 + panel.add( secondsRemainingLabel );
309 + for ( String line : BUSY_POST_SECONDS_REMAINING_MESSAGE )
310 + {
311 + panel.add( new Label( line ) );
312 + }
313 + panel.getElement().getStyle().setVisibility( Style.Visibility.HIDDEN );
314 + setWidget( messageWidget = panel );
315 + startTimer();
316 + }
317 +
318 + @Override
319 + public void hide()
320 + {
321 + stopTimer();
322 + super.hide();
323 + }
324 +
325 + private void stopTimer()
326 + {
327 + if ( timer != null )
328 + {
329 + timer.cancel();
330 + timer = null;
331 + }
332 + }
333 +
334 + private void startTimer()
335 + {
336 + stopTimer();
337 + (timer = new Timer()
338 + {
339 + @Override
340 + public void run()
341 + {
342 + if ( currentOpacity < 0.75 )
343 + {
344 + getGlassElement().getStyle().setOpacity( currentOpacity += 0.01 );
345 + }
346 + int secondsPassed = (int) ((System.currentTimeMillis() - started) / 1000);
347 + if ( (secondsPassed > 1) && !messageShowing )
348 + {
349 + messageShowing = true;
350 + messageWidget.getElement().getStyle().setVisibility( Style.Visibility.VISIBLE );
351 + }
352 + int calcSecondsRemaining = SECONDS_TO_WAIT - secondsPassed;
353 + if ( calcSecondsRemaining < 1 )
354 + {
355 + stopTimer();
356 + submitResponse( "Error: Timeout" );
357 + return;
358 + }
359 + if ( calcSecondsRemaining != secondsRemaining )
360 + {
361 + secondsRemainingLabel.setText( (secondsRemaining = calcSecondsRemaining) + "" );
362 + }
363 + }
364 + }).scheduleRepeating( 100 );
275 365 }
276 366 }
277 367 }