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 {
|
public class DialogGetInfoBootstrap extends Composite {
|
||||||
|
|
||||||
private static final int PREVIEW_WAITING_TIME = 9000; //9 sec
|
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);
|
private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class);
|
||||||
|
|
||||||
|
@ -396,12 +399,14 @@ public class DialogGetInfoBootstrap extends Composite {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String googleDocViewerURL = "https://docs.google.com/viewer?url="
|
final String googleDocViewerURL = "https://docs.google.com/viewer?url="
|
||||||
+ URL.encode(result.getCompleteURL()) + "&embedded=true";
|
+ URL.encode(result.getCompleteURL()) + "&embedded=true";
|
||||||
|
|
||||||
iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
||||||
|
|
||||||
final long startTime = new Date().getTime();
|
loaderPreviewStartTime = new Date().getTime();
|
||||||
|
showPreviewAttempt = 1;
|
||||||
|
|
||||||
timerGDV = new Timer() {
|
timerGDV = new Timer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -414,22 +419,42 @@ public class DialogGetInfoBootstrap extends Composite {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long checkTime = new Date().getTime();
|
long checkTime = new Date().getTime();
|
||||||
long diff = checkTime - startTime;
|
long diff = checkTime - loaderPreviewStartTime;
|
||||||
if (diff > PREVIEW_WAITING_TIME) {// is greater than 10 sec
|
if (diff > PREVIEW_WAITING_TIME) { // is greater than PREVIEW_WAITING_TIME, performs a new attempt or terminate
|
||||||
try {
|
if(showPreviewAttempt >= PREVIEW_MAX_RETRIES) {
|
||||||
GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec, cancelling timer, removing iframe");
|
try {
|
||||||
cancel();
|
GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec and max retries "+PREVIEW_MAX_RETRIES+", cancelling timer, removing iframe");
|
||||||
removePlaceHolder(loadingPreviewHTML);
|
cancel();
|
||||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
removePlaceHolder(loadingPreviewHTML);
|
||||||
iFrameGDV.setVisible(false);
|
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||||
htmlPanelFilePreview.remove(iFrameGDV);
|
iFrameGDV.setVisible(false);
|
||||||
} catch (Exception e) {
|
htmlPanelFilePreview.remove(iFrameGDV);
|
||||||
// Silent
|
} 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);
|
htmlPanelFilePreview.add(iFrameGDV);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue