changed the business logic to show the preview on files

This commit is contained in:
Francesco Mangiacrapa 2020-07-22 17:35:33 +02:00
parent aec8ae3332
commit 2e6b3d031f
1 changed files with 105 additions and 87 deletions

View File

@ -62,7 +62,7 @@ import com.google.gwt.user.server.Base64Utils;
*/ */
public class DialogGetInfoBootstrap extends Composite { public class DialogGetInfoBootstrap extends Composite {
private static final int PREVIEW_WAITING_TIME = 10000; private static final int PREVIEW_WAITING_TIME = 9000; //9 sec
private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class); private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class);
@ -197,6 +197,10 @@ public class DialogGetInfoBootstrap extends Composite {
private Image noPreviewAvailable = new Image(Resources.getPreviewNotAvailable()); private Image noPreviewAvailable = new Image(Resources.getPreviewNotAvailable());
private Frame iFrameGDV = null;
private Timer timerGDV = null;
/** /**
* Instantiates a new dialog get info bootstrap. * Instantiates a new dialog get info bootstrap.
* *
@ -335,36 +339,46 @@ public class DialogGetInfoBootstrap extends Composite {
loadACLsDescriptionForSharedFolder(fileModel.getIdentifier()); loadACLsDescriptionForSharedFolder(fileModel.getIdentifier());
} }
boolean previewManaged = false;
if (typeEnum != null) { if (typeEnum != null) {
// is it an image? // is it an image?
if (typeEnum.equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT) if (typeEnum.equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT)
|| typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_IMAGE)) { || typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_IMAGE)) {
previewManaged = true;
loadThumbnailsForImage(); loadThumbnailsForImage();
} }
// is it a GCUBE-Item? // is it a GCUBE-Item?
if (typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM)) { if (typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM)) {
previewManaged = true; //preview not avaible for the type GCUBE_ITEM
loadGcubeItemProperties(); loadGcubeItemProperties();
} }
}
//If the preview is not managed
//through the previous code
//managing it by checking the mime-type
if(!previewManaged) {
if (!fileModel.isDirectory() && mapAllowedMimeTypesForPreview.containsKey(fileModel.getType())) {
// SOLUTION BASED ON GOOGLE DOC VIEWER // SOLUTION BASED ON GOOGLE DOC VIEWER
if (typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_PDF_FILE)
|| typeEnum.equals(GXTFolderItemTypeEnum.PDF_DOCUMENT)
|| typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_FILE)
|| typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM)
|| typeEnum.equals(GXTFolderItemTypeEnum.URL_DOCUMENT)
|| typeEnum.equals(GXTFolderItemTypeEnum.METADATA)){
if(mapAllowedMimeTypesForPreview.containsKey(fileModel.getType())){
GWT.log("Mime type " + fileModel.getType() + " allowed for preview, try to display it"); GWT.log("Mime type " + fileModel.getType() + " allowed for preview, try to display it");
final HTML loadingPreviewHTML = new HTML();
setPlaceholder(loadingPreviewHTML, true, "loading preview...");
htmlPanelFilePreview.add(loadingPreviewHTML);
htmlPanelFilePreview.setVisible(true);
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false, AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false,
new AsyncCallback<PublicLink>() { new AsyncCallback<PublicLink>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
removePlaceHolder(loadingPreviewHTML);
GWT.log("Error on loading the Public link for: "+fileModel.getIdentifier());
htmlPanelFilePreview.add(noPreviewAvailable);
htmlPanelFilePreview.setVisible(true);
} }
@Override @Override
@ -383,20 +397,13 @@ public class DialogGetInfoBootstrap extends Composite {
return; return;
} }
// String pdfPreview = "<iframe frameBorder=\"0\" class=\"my-preview-doc\" "
// + "src=\"https://docs.google.com/viewer?url="
// + URL.encode(result.getCompleteURL()) + "&embedded=true\">" + "</iframe>";
String googleDocViewerURL = "https://docs.google.com/viewer?url=" String googleDocViewerURL = "https://docs.google.com/viewer?url="
+ URL.encode(result.getCompleteURL()) + "&embedded=true"; + URL.encode(result.getCompleteURL()) + "&embedded=true";
final HTML loadingPreviewHTML = new HTML(); iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
setPlaceholder(loadingPreviewHTML, true, "loading preview...");
final Frame frame = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
final long startTime = new Date().getTime(); final long startTime = new Date().getTime();
Timer timer = new Timer() { timerGDV = new Timer() {
@Override @Override
public void run() { public void run() {
@ -411,23 +418,21 @@ public class DialogGetInfoBootstrap extends Composite {
long diff = checkTime - startTime; long diff = checkTime - startTime;
if (diff > PREVIEW_WAITING_TIME) {// is greater than 10 sec if (diff > PREVIEW_WAITING_TIME) {// is greater than 10 sec
try { try {
GWT.log("iFrameGoogleDocViewer not loaded within 5 sec, cancelling timer, removing iframe"); GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec, cancelling timer, removing iframe");
cancel(); cancel();
removePlaceHolder(loadingPreviewHTML); removePlaceHolder(loadingPreviewHTML);
htmlPanelFilePreview.add(noPreviewAvailable); htmlPanelFilePreview.add(noPreviewAvailable);
frame.setVisible(false); iFrameGDV.setVisible(false);
htmlPanelFilePreview.remove(frame); htmlPanelFilePreview.remove(iFrameGDV);
} catch (Exception e) { } catch (Exception e) {
// Silent // Silent
} }
} }
} }
}; };
timer.scheduleRepeating(200); timerGDV.scheduleRepeating(PREVIEW_WAITING_TIME/3);
htmlPanelFilePreview.add(iFrameGDV);
htmlPanelFilePreview.add(loadingPreviewHTML);
htmlPanelFilePreview.add(frame);
htmlPanelFilePreview.setVisible(true);
} }
} }
}); });
@ -437,11 +442,24 @@ public class DialogGetInfoBootstrap extends Composite {
htmlPanelFilePreview.setVisible(true); htmlPanelFilePreview.setVisible(true);
} }
} }
}
addHandlers(); addHandlers();
} }
@Override
protected void onDetach() {
super.onDetach();
GWT.log("Detached...");
htmlPanelFilePreview.clear();
if(timerGDV!=null) {
try {
timerGDV.cancel();
}catch (Exception e) {
// TODO: handle exception
}
}
}
public Frame instanceFrame(String fileURL, final HTML thePreviewPlaceholder) { public Frame instanceFrame(String fileURL, final HTML thePreviewPlaceholder) {
//addLoading(); //addLoading();
String urlEncoded = URL.encode(fileURL); String urlEncoded = URL.encode(fileURL);