2016-05-12 19:20:39 +02:00
|
|
|
package org.gcube.portlets.user.dataminermanager.client.widgets;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
|
2018-05-03 16:24:26 +02:00
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.FileResource;
|
2017-11-09 18:04:16 +01:00
|
|
|
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent;
|
|
|
|
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent.SelectVariableEventHandler;
|
|
|
|
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.widgets.NetCDFPreviewDialog;
|
2016-05-12 19:20:39 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2016-05-12 19:20:39 +02:00
|
|
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
2017-11-09 18:04:16 +01:00
|
|
|
import com.sencha.gxt.core.client.dom.XDOM;
|
2016-05-12 19:20:39 +02:00
|
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Giancarlo Panichi
|
2017-05-12 11:58:15 +02:00
|
|
|
*
|
2016-05-12 19:20:39 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class FileViewer extends SimpleContainer {
|
|
|
|
|
|
|
|
private FileResource fileResource;
|
|
|
|
|
|
|
|
/**
|
2017-05-12 11:58:15 +02:00
|
|
|
*
|
|
|
|
* @param computationId
|
|
|
|
* computation id
|
|
|
|
* @param fileResource
|
|
|
|
* file resource
|
2016-05-12 19:20:39 +02:00
|
|
|
*/
|
2017-05-12 11:58:15 +02:00
|
|
|
public FileViewer(ComputationId computationId, FileResource fileResource) {
|
2016-05-12 19:20:39 +02:00
|
|
|
super();
|
|
|
|
this.fileResource = fileResource;
|
2017-05-12 11:58:15 +02:00
|
|
|
// this.computationId = computationId;
|
2016-05-12 19:20:39 +02:00
|
|
|
init();
|
|
|
|
create();
|
|
|
|
}
|
2017-05-12 11:58:15 +02:00
|
|
|
|
|
|
|
private void init() {
|
2016-05-12 19:20:39 +02:00
|
|
|
setHeight(56);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void create() {
|
|
|
|
VerticalLayoutContainer lc = new VerticalLayoutContainer();
|
|
|
|
final String fileName = fileResource.getName();
|
|
|
|
final String fileUrl = fileResource.getUrl();
|
2017-05-12 11:58:15 +02:00
|
|
|
HtmlLayoutContainer fileNameHtml = new HtmlLayoutContainer("<div class='computation-output-fileName'><p>"
|
|
|
|
+ new SafeHtmlBuilder().appendEscaped(fileName).toSafeHtml().asString() + "</p></div>");
|
2016-05-12 19:20:39 +02:00
|
|
|
lc.add(fileNameHtml, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
TextButton downloadBtn = new TextButton("Download File");
|
2016-06-01 12:48:06 +02:00
|
|
|
downloadBtn.setIcon(DataMinerManager.resources.download());
|
2016-05-12 19:20:39 +02:00
|
|
|
downloadBtn.addSelectHandler(new SelectEvent.SelectHandler() {
|
|
|
|
@Override
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
com.google.gwt.user.client.Window.open(fileUrl, fileName, "");
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
TextButton netcdfButton = new TextButton("");
|
|
|
|
netcdfButton.setIcon(DataMinerManager.resources.netcdf());
|
|
|
|
netcdfButton.addSelectHandler(new SelectEvent.SelectHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
showNetCDFFile();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-12 19:20:39 +02:00
|
|
|
lc.add(downloadBtn, new VerticalLayoutData(-1, -1, new Margins(0)));
|
2017-11-09 18:04:16 +01:00
|
|
|
if (fileResource.isNetcdf()) {
|
|
|
|
lc.add(netcdfButton, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
}
|
2016-05-12 19:20:39 +02:00
|
|
|
add(lc);
|
|
|
|
}
|
2017-05-12 11:58:15 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private void showNetCDFFile() {
|
|
|
|
if (fileResource != null && fileResource.getUrl() != null && !fileResource.getUrl().isEmpty()
|
|
|
|
&& fileResource.isNetcdf()) {
|
|
|
|
GWT.log("NetcdfBasicWidgetsManager");
|
|
|
|
|
|
|
|
// Example
|
|
|
|
SelectVariableEventHandler handler = new SelectVariableEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(SelectVariableEvent event) {
|
|
|
|
GWT.log("SelectVariable Response: " + event);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NetCDFPreviewDialog netcdfDialog = new NetCDFPreviewDialog(fileResource.getUrl());
|
|
|
|
netcdfDialog.addSelectVariableEventHandler(handler);
|
|
|
|
netcdfDialog.setZIndex(XDOM.getTopZIndex());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:20:39 +02:00
|
|
|
}
|