|
@@ -7,6 +7,13 @@ |
7 |
7 |
|
|
8 |
8 |
|
public class UploadWidget extends Composite implements IsWidget |
9 |
9 |
|
{ |
|
10 |
+ |
public interface Callback |
|
11 |
+ |
{ |
|
12 |
+ |
public void timeout( String filename ); |
|
13 |
+ |
|
|
14 |
+ |
public void parseResponse( String fileName, String pHtmlResponse ); |
|
15 |
+ |
} |
|
16 |
+ |
|
10 |
17 |
|
private static final String BUSY_IMAGE_URL = "common/Money.gif"; |
11 |
18 |
|
private static final int SECONDS_TO_WAIT = 30; |
12 |
19 |
|
private static final String[] BUSY_PRE_SECONDS_REMAINING_MESSAGE = {"Checking Certificate Validity,", "this can take a while..."}; |
|
@@ -21,17 +28,15 @@ |
21 |
28 |
|
private final Widget sizingWidget; |
22 |
29 |
|
private boolean externallyEnabled; |
23 |
30 |
|
|
|
31 |
+ |
private final Callback callback; |
|
32 |
+ |
|
24 |
33 |
|
private String servletPath; |
25 |
34 |
|
private Timer timer; |
26 |
35 |
|
private boolean sized = false; |
27 |
36 |
|
|
28 |
|
- |
public UploadWidget() |
29 |
|
- |
{ |
30 |
|
- |
this( new Button( "Pick" ) ); |
31 |
|
- |
} |
32 |
|
- |
|
33 |
|
- |
public UploadWidget( ButtonBase illusionaryClickWidget ) |
|
37 |
+ |
public UploadWidget( ButtonBase illusionaryClickWidget, Callback callback ) |
34 |
38 |
|
{ |
|
39 |
+ |
this.callback = callback; |
35 |
40 |
|
externallyEnabled = illusionaryClickWidget.isEnabled(); |
36 |
41 |
|
sizingWidget = createConstrainer( this.illusionaryClickWidget = illusionaryClickWidget ); |
37 |
42 |
|
initWidget( createStylingDiv( "UploadWidget", createConstrainer( createFlowPanel( sizingWidget, viewPort ) ) ) ); |
|
@@ -155,22 +160,20 @@ |
155 |
160 |
|
showBusy(); |
156 |
161 |
|
} |
157 |
162 |
|
|
158 |
|
- |
private void submitResponse( String pHtmlResponse ) |
|
163 |
+ |
private void timeout() |
159 |
164 |
|
{ |
160 |
165 |
|
hideBusy(); |
161 |
|
- |
// Truly Bad Url: |
162 |
|
- |
// null |
163 |
|
- |
|
164 |
|
- |
// No Servlet: |
165 |
|
- |
// <h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre> |
166 |
|
- |
// <p>RequestURI=/v2/TestSubmit</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br> |
167 |
|
- |
// <br> |
168 |
|
- |
// <br> |
169 |
|
- |
// <br> |
170 |
|
- |
// ... |
|
166 |
+ |
String filename = upload.getFilename(); |
|
167 |
+ |
resetUploadWidget(); |
|
168 |
+ |
callback.timeout( filename ); |
|
169 |
+ |
} |
171 |
170 |
|
|
172 |
|
- |
System.out.println( "UploadWidget.onSubmitComplete:\n" + pHtmlResponse ); |
|
171 |
+ |
private void submitResponse( String htmlResponse ) |
|
172 |
+ |
{ |
|
173 |
+ |
hideBusy(); |
|
174 |
+ |
String filename = upload.getFilename(); |
173 |
175 |
|
resetUploadWidget(); |
|
176 |
+ |
callback.parseResponse( filename, htmlResponse ); |
174 |
177 |
|
} |
175 |
178 |
|
|
176 |
179 |
|
private static Widget createConstrainer( Widget widget ) |
|
@@ -296,11 +299,12 @@ |
296 |
299 |
|
getGlassElement().getStyle().setCursor( Style.Cursor.WAIT ); |
297 |
300 |
|
getGlassElement().getStyle().setOpacity( currentOpacity ); |
298 |
301 |
|
|
|
302 |
+ |
VerticalPanel outerpanel = new VerticalPanel(); |
|
303 |
+ |
outerpanel.setStyleName( "UploadWidgetBusyContainer" ); |
|
304 |
+ |
outerpanel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER ); |
|
305 |
+ |
outerpanel.add( new Image( BUSY_IMAGE_URL ) ); |
299 |
306 |
|
VerticalPanel panel = new VerticalPanel(); |
300 |
|
- |
panel.setStyleName( "UploadWidgetBusyMessage" ); |
301 |
307 |
|
panel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER ); |
302 |
|
- |
panel.add( new Image( BUSY_IMAGE_URL ) ); |
303 |
|
- |
panel.add( new HTML( " " ) ); |
304 |
308 |
|
for ( String line : BUSY_PRE_SECONDS_REMAINING_MESSAGE ) |
305 |
309 |
|
{ |
306 |
310 |
|
panel.add( new Label( line ) ); |
|
@@ -310,8 +314,9 @@ |
310 |
314 |
|
{ |
311 |
315 |
|
panel.add( new Label( line ) ); |
312 |
316 |
|
} |
313 |
|
- |
panel.getElement().getStyle().setVisibility( Style.Visibility.HIDDEN ); |
314 |
|
- |
setWidget( messageWidget = panel ); |
|
317 |
+ |
outerpanel.add( createStylingDiv( "UploadWidgetBusyMessage", panel ) ); |
|
318 |
+ |
outerpanel.getElement().getStyle().setVisibility( Style.Visibility.HIDDEN ); |
|
319 |
+ |
setWidget( messageWidget = outerpanel ); |
315 |
320 |
|
startTimer(); |
316 |
321 |
|
} |
317 |
322 |
|
|
|
@@ -341,7 +346,7 @@ |
341 |
346 |
|
{ |
342 |
347 |
|
if ( currentOpacity < 0.75 ) |
343 |
348 |
|
{ |
344 |
|
- |
getGlassElement().getStyle().setOpacity( currentOpacity += 0.01 ); |
|
349 |
+ |
getGlassElement().getStyle().setOpacity( currentOpacity += 0.025 ); |
345 |
350 |
|
} |
346 |
351 |
|
int secondsPassed = (int) ((System.currentTimeMillis() - started) / 1000); |
347 |
352 |
|
if ( (secondsPassed > 1) && !messageShowing ) |
|
@@ -353,7 +358,7 @@ |
353 |
358 |
|
if ( calcSecondsRemaining < 1 ) |
354 |
359 |
|
{ |
355 |
360 |
|
stopTimer(); |
356 |
|
- |
submitResponse( "Error: Timeout" ); |
|
361 |
+ |
timeout(); |
357 |
362 |
|
return; |
358 |
363 |
|
} |
359 |
364 |
|
if ( calcSecondsRemaining != secondsRemaining ) |