changed the business logic to show the preview on files
This commit is contained in:
parent
aec8ae3332
commit
2e6b3d031f
|
@ -62,7 +62,7 @@ import com.google.gwt.user.server.Base64Utils;
|
|||
*/
|
||||
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);
|
||||
|
||||
|
@ -197,6 +197,10 @@ public class DialogGetInfoBootstrap extends Composite {
|
|||
|
||||
private Image noPreviewAvailable = new Image(Resources.getPreviewNotAvailable());
|
||||
|
||||
private Frame iFrameGDV = null;
|
||||
|
||||
private Timer timerGDV = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new dialog get info bootstrap.
|
||||
*
|
||||
|
@ -335,113 +339,127 @@ public class DialogGetInfoBootstrap extends Composite {
|
|||
loadACLsDescriptionForSharedFolder(fileModel.getIdentifier());
|
||||
}
|
||||
|
||||
boolean previewManaged = false;
|
||||
|
||||
if (typeEnum != null) {
|
||||
|
||||
// is it an image?
|
||||
if (typeEnum.equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT)
|
||||
|| typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_IMAGE)) {
|
||||
previewManaged = true;
|
||||
loadThumbnailsForImage();
|
||||
}
|
||||
|
||||
// is it a GCUBE-Item?
|
||||
if (typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM)) {
|
||||
previewManaged = true; //preview not avaible for the type GCUBE_ITEM
|
||||
loadGcubeItemProperties();
|
||||
}
|
||||
}
|
||||
|
||||
//If the preview is not managed
|
||||
//through the previous code
|
||||
//managing it by checking the mime-type
|
||||
if(!previewManaged) {
|
||||
|
||||
// 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 (!fileModel.isDirectory() && mapAllowedMimeTypesForPreview.containsKey(fileModel.getType())) {
|
||||
// SOLUTION BASED ON GOOGLE DOC VIEWER
|
||||
GWT.log("Mime type " + fileModel.getType() + " allowed for preview, try to display it");
|
||||
|
||||
if(mapAllowedMimeTypesForPreview.containsKey(fileModel.getType())){
|
||||
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,
|
||||
new AsyncCallback<PublicLink>() {
|
||||
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false,
|
||||
new AsyncCallback<PublicLink>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
}
|
||||
@Override
|
||||
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
|
||||
public void onSuccess(PublicLink result) {
|
||||
@Override
|
||||
public void onSuccess(PublicLink result) {
|
||||
|
||||
GWT.log("The PublicLink link is: " + result);
|
||||
GWT.log("The PublicLink link is: " + result);
|
||||
|
||||
if (result != null) {
|
||||
if (result != null) {
|
||||
|
||||
//if file size is null or greater than 25MB
|
||||
long byteTo25MB = 1024*1024*25;
|
||||
GWT.log("The file size is: "+fileSize);
|
||||
if(fileSize==null || fileSize>byteTo25MB) {
|
||||
GWT.log("The file size is null or greater than "+byteTo25MB+", returning");
|
||||
//htmlPanelFilePreview.add(new Image(Resources.getPreviewNotAvailable()));
|
||||
return;
|
||||
}
|
||||
// if file size is null or greater than 25MB
|
||||
long byteTo25MB = 1024 * 1024 * 25;
|
||||
GWT.log("The file size is: " + fileSize);
|
||||
if (fileSize == null || fileSize > byteTo25MB) {
|
||||
GWT.log("The file size is null or greater than " + byteTo25MB + ", returning");
|
||||
// htmlPanelFilePreview.add(new Image(Resources.getPreviewNotAvailable()));
|
||||
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="
|
||||
+ URL.encode(result.getCompleteURL()) + "&embedded=true";
|
||||
|
||||
String googleDocViewerURL = "https://docs.google.com/viewer?url="
|
||||
+ URL.encode(result.getCompleteURL()) + "&embedded=true";
|
||||
iFrameGDV = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
||||
|
||||
final HTML loadingPreviewHTML = new HTML();
|
||||
setPlaceholder(loadingPreviewHTML, true, "loading preview...");
|
||||
final long startTime = new Date().getTime();
|
||||
timerGDV = new Timer() {
|
||||
|
||||
final Frame frame = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
||||
|
||||
final long startTime = new Date().getTime();
|
||||
Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
GWT.log("Checking if the iFrameGoogleDocViewer is ready");
|
||||
if(iFrameGoogleDocViewerLoaded) {
|
||||
removePlaceHolder(loadingPreviewHTML);
|
||||
GWT.log("iFrameGoogleDocViewer currently loaded, cancelling timer");
|
||||
@Override
|
||||
public void run() {
|
||||
GWT.log("Checking if the iFrameGoogleDocViewer is ready");
|
||||
if (iFrameGoogleDocViewerLoaded) {
|
||||
removePlaceHolder(loadingPreviewHTML);
|
||||
GWT.log("iFrameGoogleDocViewer currently loaded, cancelling timer");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
long checkTime = new Date().getTime();
|
||||
long diff = checkTime - startTime;
|
||||
if (diff > PREVIEW_WAITING_TIME) {// is greater than 10 sec
|
||||
try {
|
||||
GWT.log("iFrameGoogleDocViewer not loaded within "+PREVIEW_WAITING_TIME+" sec, cancelling timer, removing iframe");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
long checkTime = new Date().getTime();
|
||||
long diff = checkTime - startTime;
|
||||
if(diff>PREVIEW_WAITING_TIME) {//is greater than 10 sec
|
||||
try {
|
||||
GWT.log("iFrameGoogleDocViewer not loaded within 5 sec, cancelling timer, removing iframe");
|
||||
cancel();
|
||||
removePlaceHolder(loadingPreviewHTML);
|
||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||
frame.setVisible(false);
|
||||
htmlPanelFilePreview.remove(frame);
|
||||
}catch (Exception e) {
|
||||
//Silent
|
||||
}
|
||||
removePlaceHolder(loadingPreviewHTML);
|
||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||
iFrameGDV.setVisible(false);
|
||||
htmlPanelFilePreview.remove(iFrameGDV);
|
||||
} catch (Exception e) {
|
||||
// Silent
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.scheduleRepeating(200);
|
||||
}
|
||||
};
|
||||
timerGDV.scheduleRepeating(PREVIEW_WAITING_TIME/3);
|
||||
htmlPanelFilePreview.add(iFrameGDV);
|
||||
|
||||
htmlPanelFilePreview.add(loadingPreviewHTML);
|
||||
htmlPanelFilePreview.add(frame);
|
||||
htmlPanelFilePreview.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}else {
|
||||
GWT.log("Mime type "+fileModel.getType()+" NOT allowed for preview, displaying 'No preview available'");
|
||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||
htmlPanelFilePreview.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
GWT.log("Mime type " + fileModel.getType() + " NOT allowed for preview, displaying 'No preview available'");
|
||||
htmlPanelFilePreview.add(noPreviewAvailable);
|
||||
htmlPanelFilePreview.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
//addLoading();
|
||||
String urlEncoded = URL.encode(fileURL);
|
||||
|
|
Loading…
Reference in New Issue