Optimized the business logic to show the preview of files by Get Info
(as reported at https://support.d4science.org/issues/19600#note-7)
This commit is contained in:
parent
26b7497446
commit
049f96dff2
|
@ -62,6 +62,9 @@ import com.google.gwt.user.client.ui.Widget;
|
|||
public class DialogGetInfoBootstrap extends Composite {
|
||||
|
||||
private static final int PREVIEW_WAITING_TIME = 9000; //9 sec
|
||||
private static final int PREVIEW_MAX_RETRIES = 3;
|
||||
private int showPreviewAttempt = 0;
|
||||
private long loaderPreviewStartTime = 0;
|
||||
|
||||
private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class);
|
||||
|
||||
|
@ -396,12 +399,14 @@ public class DialogGetInfoBootstrap extends Composite {
|
|||
return;
|
||||
}
|
||||
|
||||
String googleDocViewerURL = "https://docs.google.com/viewer?url="
|
||||
final String googleDocViewerURL = "https://docs.google.com/viewer?url="
|
||||
+ URL.encode(result.getCompleteURL()) + "&embedded=true";
|
||||
|
||||
iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
||||
|
||||
final long startTime = new Date().getTime();
|
||||
loaderPreviewStartTime = new Date().getTime();
|
||||
showPreviewAttempt = 1;
|
||||
|
||||
timerGDV = new Timer() {
|
||||
|
||||
@Override
|
||||
|
@ -414,10 +419,11 @@ public class DialogGetInfoBootstrap extends Composite {
|
|||
return;
|
||||
}
|
||||
long checkTime = new Date().getTime();
|
||||
long diff = checkTime - startTime;
|
||||
if (diff > PREVIEW_WAITING_TIME) {// is greater than 10 sec
|
||||
long diff = checkTime - loaderPreviewStartTime;
|
||||
if (diff > PREVIEW_WAITING_TIME) { // is greater than PREVIEW_WAITING_TIME, performs a new attempt or terminate
|
||||
if(showPreviewAttempt >= PREVIEW_MAX_RETRIES) {
|
||||
try {
|
||||
GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec, cancelling timer, removing iframe");
|
||||
GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec and max retries "+PREVIEW_MAX_RETRIES+", cancelling timer, removing iframe");
|
||||
cancel();
|
||||
removePlaceHolder(loadingPreviewHTML);
|
||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||
|
@ -426,10 +432,29 @@ public class DialogGetInfoBootstrap extends Composite {
|
|||
} catch (Exception e) {
|
||||
// Silent
|
||||
}
|
||||
}else {
|
||||
GWT.log("iFrameGoogleDocViewer not loaded on attempt "+showPreviewAttempt+", instancing new iFrame");
|
||||
//new retry by instancing the iFrame again...
|
||||
iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
||||
try {
|
||||
//removing old iFrame
|
||||
htmlPanelFilePreview.remove(iFrameGDV);
|
||||
}catch (Exception e) {
|
||||
//silent
|
||||
}
|
||||
//adding the new one
|
||||
htmlPanelFilePreview.add(iFrameGDV);
|
||||
//new attempt so incrementing it
|
||||
showPreviewAttempt++;
|
||||
GWT.log("Retry, go to attempt "+showPreviewAttempt);
|
||||
//resetting start time for new attempt
|
||||
loaderPreviewStartTime = new Date().getTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
timerGDV.scheduleRepeating(PREVIEW_WAITING_TIME/3);
|
||||
int attemptRepeater = PREVIEW_WAITING_TIME / 3;
|
||||
timerGDV.scheduleRepeating(attemptRepeater);
|
||||
htmlPanelFilePreview.add(iFrameGDV);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue