|
|
|
@ -12,7 +12,6 @@ import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.Download
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Icons;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage;
|
|
|
|
@ -52,6 +51,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
|
import com.google.gwt.user.client.ui.NamedFrame;
|
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
import com.google.gwt.user.server.Base64Utils;
|
|
|
|
|
|
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
|
/**
|
|
|
|
@ -62,6 +62,8 @@ import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
*/
|
|
|
|
|
public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
|
|
|
|
|
private static final int PREVIEW_WAITING_TIME = 10000;
|
|
|
|
|
|
|
|
|
|
private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -189,16 +191,24 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
|
|
|
|
|
private Long fileSize = null;
|
|
|
|
|
|
|
|
|
|
private Map<String, List<String>> mapAllowedMimeTypesForPreview;
|
|
|
|
|
|
|
|
|
|
private Image spinnerImage = Resources.getIconLoading().createImage();
|
|
|
|
|
|
|
|
|
|
private Image noPreviewAvailable = new Image(Resources.getPreviewNotAvailable());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Instantiates a new dialog get info bootstrap.
|
|
|
|
|
*
|
|
|
|
|
* @param fileModel the file model
|
|
|
|
|
* @param onCloseCommand the on close command
|
|
|
|
|
* @param mapAllowedMimeTypesForPreview the map allowed mime types for preview
|
|
|
|
|
*/
|
|
|
|
|
public DialogGetInfoBootstrap(final FileModel fileModel, final Command onCloseCommand) {
|
|
|
|
|
public DialogGetInfoBootstrap(final FileModel fileModel, final Command onCloseCommand, Map<String,List<String>> mapAllowedMimeTypesForPreview) {
|
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
this.fileModel = fileModel;
|
|
|
|
|
this.onCloseCommand = onCloseCommand;
|
|
|
|
|
this.mapAllowedMimeTypesForPreview = mapAllowedMimeTypesForPreview;
|
|
|
|
|
this.cgTxtMimeType.setVisible(true);
|
|
|
|
|
|
|
|
|
|
buttonClose.getElement().getStyle().setFloat(Float.RIGHT);
|
|
|
|
@ -340,111 +350,93 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SOLUTION BASED ON GOOGLE DOC VIEWER
|
|
|
|
|
if (typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_PDF_FILE) ||
|
|
|
|
|
|
|
|
|
|
typeEnum.equals(GXTFolderItemTypeEnum.PDF_DOCUMENT)
|
|
|
|
|
|| typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_FILE)) {
|
|
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false,
|
|
|
|
|
new AsyncCallback<PublicLink>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(PublicLink result) {
|
|
|
|
|
|
|
|
|
|
GWT.log("The PublicLink link is: " + result);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
|
|
|
|
|
|
final HTML loadingPreviewHTML = new HTML();
|
|
|
|
|
setPlaceholder(loadingPreviewHTML, "loading preview...");
|
|
|
|
|
|
|
|
|
|
final Frame frame = instanceFrame(googleDocViewerURL, loadingPreviewHTML);
|
|
|
|
|
|
|
|
|
|
final long startTime = new Date().getTime();
|
|
|
|
|
Timer timer = new Timer() {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false,
|
|
|
|
|
new AsyncCallback<PublicLink>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(PublicLink result) {
|
|
|
|
|
|
|
|
|
|
GWT.log("The PublicLink link is: " + result);
|
|
|
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
|
|
|
|
|
|
@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>5000) {//is greater than 5 sec
|
|
|
|
|
try {
|
|
|
|
|
GWT.log("iFrameGoogleDocViewer not loaded within 5 sec, cancelling timer, removing iframe");
|
|
|
|
|
cancel();
|
|
|
|
|
//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";
|
|
|
|
|
|
|
|
|
|
final HTML loadingPreviewHTML = new HTML();
|
|
|
|
|
setPlaceholder(loadingPreviewHTML, true, "loading preview...");
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
htmlPanelFilePreview.add(new Image(Resources.getPreviewNotAvailable()));
|
|
|
|
|
frame.setVisible(false);
|
|
|
|
|
htmlPanelFilePreview.remove(frame);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
//Silent
|
|
|
|
|
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 5 sec, cancelling timer, removing iframe");
|
|
|
|
|
cancel();
|
|
|
|
|
removePlaceHolder(loadingPreviewHTML);
|
|
|
|
|
htmlPanelFilePreview.add(noPreviewAvailable);
|
|
|
|
|
frame.setVisible(false);
|
|
|
|
|
htmlPanelFilePreview.remove(frame);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
//Silent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
timer.scheduleRepeating(200);
|
|
|
|
|
|
|
|
|
|
htmlPanelFilePreview.add(loadingPreviewHTML);
|
|
|
|
|
htmlPanelFilePreview.add(frame);
|
|
|
|
|
htmlPanelFilePreview.setVisible(true);
|
|
|
|
|
};
|
|
|
|
|
timer.scheduleRepeating(200);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SOLUTION BASED ON PDFOBEJCT
|
|
|
|
|
/*if(typeEnum.equals(GXTFolderItemTypeEnum.EXTERNAL_PDF_FILE) ||
|
|
|
|
|
typeEnum.equals(GXTFolderItemTypeEnum.PDF_DOCUMENT)) {
|
|
|
|
|
|
|
|
|
|
GWT.log("The file is a PDF");
|
|
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(fileModel.getIdentifier(), false, new AsyncCallback<PublicLink>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(PublicLink result) {
|
|
|
|
|
|
|
|
|
|
GWT.log("The PublicLink link is: "+result);
|
|
|
|
|
|
|
|
|
|
if(result!=null) {
|
|
|
|
|
|
|
|
|
|
String pdfPreview = "<div id=\"pdfPrewiewDiv\" class=\"my-preview-doc\"> </div>";
|
|
|
|
|
htmlPanelFilePreview.add(new HTML(pdfPreview));
|
|
|
|
|
showPDFPreview(result.getCompleteURL(), "pdfPrewiewDiv");
|
|
|
|
|
htmlPanelFilePreview.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addHandlers();
|
|
|
|
@ -602,7 +594,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
*/
|
|
|
|
|
private void loadLocation(FileModel fileModel) {
|
|
|
|
|
|
|
|
|
|
setPlaceholder(txtLocation, "loading...");
|
|
|
|
|
setPlaceholder(txtLocation, false, "loading...");
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getListParentsByItemIdentifier(fileModel.getIdentifier(), false,
|
|
|
|
|
new AsyncCallback<List<FileModel>>() {
|
|
|
|
|
|
|
|
|
@ -641,7 +633,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
*/
|
|
|
|
|
private void loadSize(final String itemId) {
|
|
|
|
|
GWT.log("Load size");
|
|
|
|
|
setPlaceholder(txtSize, "loading...");
|
|
|
|
|
setPlaceholder(txtSize, false, "loading...");
|
|
|
|
|
fileSize = new Long(-1); //means is loading
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.loadSizeByItemId(itemId, new AsyncCallback<Long>() {
|
|
|
|
|
|
|
|
|
@ -673,7 +665,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
*/
|
|
|
|
|
private void loadCreationDate(final String itemId) {
|
|
|
|
|
|
|
|
|
|
setPlaceholder(txtCreated, "loading...");
|
|
|
|
|
setPlaceholder(txtCreated, false, "loading...");
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getItemCreationDateById(itemId, new AsyncCallback<Date>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -701,7 +693,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
*/
|
|
|
|
|
private void loadLastModificationDate(final String itemId) {
|
|
|
|
|
|
|
|
|
|
setPlaceholder(txtLastMofication, "loading...");
|
|
|
|
|
setPlaceholder(txtLastMofication, false, "loading...");
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.loadLastModificationDateById(itemId, new AsyncCallback<Date>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -794,7 +786,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
*/
|
|
|
|
|
private void loadACLsDescriptionForSharedFolder(String sharedId) {
|
|
|
|
|
|
|
|
|
|
setPlaceholder(txtSharedWith, "loading...");
|
|
|
|
|
setPlaceholder(txtSharedWith, true, "loading...");
|
|
|
|
|
|
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getACLsDescriptionForSharedFolderId(sharedId,
|
|
|
|
|
new AsyncCallback<String>() {
|
|
|
|
@ -827,7 +819,7 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
htmlPanelImagePreview.setVisible(true);
|
|
|
|
|
final HTML txtLoadingPreview = new HTML();
|
|
|
|
|
htmlPanelImagePreview.add(txtLoadingPreview);
|
|
|
|
|
setPlaceholder(txtLoadingPreview, "loading preview...");
|
|
|
|
|
setPlaceholder(txtLoadingPreview, true, "loading preview...");
|
|
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getImageById(fileModel.getIdentifier(),
|
|
|
|
|
fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT), false,
|
|
|
|
@ -863,8 +855,12 @@ public class DialogGetInfoBootstrap extends Composite {
|
|
|
|
|
* @param html the html
|
|
|
|
|
* @param placeholder the placeholder
|
|
|
|
|
*/
|
|
|
|
|
private void setPlaceholder(HTML html, String placeholder) {
|
|
|
|
|
html.setHTML(placeholder);
|
|
|
|
|
private void setPlaceholder(HTML html, boolean spinner, String placeholder) {
|
|
|
|
|
String loadingHMTL = placeholder;
|
|
|
|
|
if(spinner) {
|
|
|
|
|
loadingHMTL = "<span><img src=\""+spinnerImage.getUrl()+"\" style=\"padding-right:5px;\">"+placeholder+"</span>";
|
|
|
|
|
}
|
|
|
|
|
html.setHTML(loadingHMTL);
|
|
|
|
|
html.getElement().addClassName("placeholder-loading");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|