305 lines
9.7 KiB
Java
305 lines
9.7 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.dataminermanager.client.experiments;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.FileResource;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.ImagesResource;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.MapResource;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.ObjectResource;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.Resource;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.Resource.ResourceType;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.output.TableResource;
|
|
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
|
|
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.user.dataminermanager.client.widgets.ImagesViewer;
|
|
import org.gcube.portlets.user.dataminermanager.client.widgets.ResourceViewer;
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.ComputationId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.safehtml.shared.SafeHtml;
|
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.sencha.gxt.core.client.XTemplates;
|
|
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 email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class ComputationOutputPanel extends SimpleContainer {
|
|
|
|
private ComputationId computationId;
|
|
private VerticalLayoutContainer v;
|
|
|
|
public ComputationOutputPanel(ComputationId computationId) {
|
|
super();
|
|
this.computationId = computationId;
|
|
Log.debug("ComputationOutputPanel");
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
v = new VerticalLayoutContainer();
|
|
add(v);
|
|
|
|
// request for a jobItem linked with the computationId (or jobId)
|
|
DataMinerPortletServiceAsync.INSTANCE.getResourceByComputationId(computationId,
|
|
new AsyncCallback<Resource>() {
|
|
@Override
|
|
public void onSuccess(Resource result) {
|
|
// unmask();
|
|
showOutputInfo(result);
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Log.error("Error in getResourceByComputationId: "
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert(
|
|
"Error",
|
|
"Impossible to retrieve output info. "
|
|
+ caught.getLocalizedMessage());
|
|
|
|
}
|
|
});
|
|
|
|
// this.mask("Loading Result Info...");
|
|
}
|
|
|
|
/**
|
|
* @param jobOutput
|
|
*/
|
|
private void showOutputInfo(Resource resource) {
|
|
try {
|
|
Log.info("Show Output Info on: " + resource);
|
|
if (resource == null)
|
|
return;
|
|
|
|
ResourceType resourceType = resource.getResourceType();
|
|
|
|
switch (resourceType) {
|
|
|
|
case FILE:
|
|
FileResource fileResource = (FileResource) resource;
|
|
v.add(getHtmlTitle("The algorithm produced a", "File"),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
v.add(getFileResourceOutput(fileResource),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
break;
|
|
|
|
case TABULAR:
|
|
TableResource tabResource = (TableResource) resource;
|
|
v.add(getHtmlTitle("The algorithm produced a", "Table"),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
// v.add(getTabResourceOutput(tabResource),
|
|
//new VerticalLayoutData(1, -1, new Margins(0)));
|
|
break;
|
|
|
|
case IMAGES:
|
|
v.add(getHtmlTitle("The algorithm produced an", "Set of Images"),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
final ImagesResource imagesResource = (ImagesResource) resource;
|
|
v.add(getImagesResourceOutput(imagesResource),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
break;
|
|
|
|
case MAP:
|
|
v.add(getHtmlTitle("The algorithm produced ",
|
|
"Multiple Results"), new VerticalLayoutData(1, -1,
|
|
new Margins(0)));
|
|
|
|
final MapResource mapResource = (MapResource) resource;
|
|
|
|
v.add(getMultipleOutput(mapResource), new VerticalLayoutData(1,
|
|
-1, new Margins(0)));
|
|
break;
|
|
case ERROR:
|
|
break;
|
|
case OBJECT:
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
forceLayout();
|
|
} catch (Throwable e) {
|
|
Log.error("Error in show output info: " + e.getLocalizedMessage());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public interface TitleTemplate extends XTemplates {
|
|
@XTemplate("<div class='computation-output-outputType'><p>{intro} <b>{produced}<b>.</p></div>")
|
|
SafeHtml getTemplate(String intro, String produced);
|
|
}
|
|
|
|
/**
|
|
* @param string
|
|
* @return
|
|
*/
|
|
private HtmlLayoutContainer getHtmlTitle(String intro, String produced) {
|
|
TitleTemplate templates = GWT.create(TitleTemplate.class);
|
|
HtmlLayoutContainer c = new HtmlLayoutContainer(templates.getTemplate(
|
|
intro, produced));
|
|
|
|
return c;
|
|
}
|
|
|
|
/**
|
|
* @param imagesResource
|
|
* @return
|
|
*/
|
|
private SimpleContainer getImagesResourceOutput(
|
|
ImagesResource imagesResource) {
|
|
return new ImagesViewer(computationId, imagesResource);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param fileResource
|
|
* @return
|
|
*/
|
|
private SimpleContainer getFileResourceOutput(FileResource fileResource) {
|
|
VerticalLayoutContainer lc = new VerticalLayoutContainer();
|
|
SimpleContainer container = new SimpleContainer();
|
|
final String fileName = fileResource.getName();
|
|
final String fileUrl = fileResource.getUrl();
|
|
HtmlLayoutContainer fileNameHtml = new HtmlLayoutContainer(
|
|
"<div class='computation-output-fileName'><p>"
|
|
+ new SafeHtmlBuilder().appendEscaped(fileName)
|
|
.toSafeHtml().asString() + "</p></div>");
|
|
lc.add(fileNameHtml, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
TextButton downloadBtn = new TextButton("Download File");
|
|
downloadBtn.setIcon(DataMinerManager.resources.fileDownload());
|
|
downloadBtn.addSelectHandler(new SelectEvent.SelectHandler() {
|
|
@Override
|
|
public void onSelect(SelectEvent event) {
|
|
com.google.gwt.user.client.Window.open(fileUrl, fileName, "");
|
|
|
|
}
|
|
});
|
|
|
|
lc.add(downloadBtn, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
container.add(lc);
|
|
return container;
|
|
}
|
|
|
|
/**
|
|
* @param map
|
|
* @return
|
|
*/
|
|
private SimpleContainer getMultipleOutput(MapResource mapResource) {
|
|
Map<String, Resource> map = mapResource.getMap();
|
|
VerticalLayoutContainer vp = new VerticalLayoutContainer();
|
|
SimpleContainer container = new SimpleContainer();
|
|
|
|
Map<String, ObjectResource> mapValues = new LinkedHashMap<>();
|
|
Map<String, FileResource> mapFiles = new LinkedHashMap<>();
|
|
Map<String, TableResource> mapTabs = new LinkedHashMap<>();
|
|
Map<String, ImagesResource> mapImages = new LinkedHashMap<>();
|
|
|
|
for (String key : map.keySet()) {
|
|
Resource resource = map.get(key);
|
|
ResourceType resourceType = resource.getResourceType();
|
|
|
|
switch (resourceType) {
|
|
case OBJECT:
|
|
mapValues.put(key, (ObjectResource) resource);
|
|
break;
|
|
case FILE:
|
|
mapFiles.put(key, (FileResource) resource);
|
|
break;
|
|
case TABULAR:
|
|
mapTabs.put(key, (TableResource) resource);
|
|
break;
|
|
case IMAGES:
|
|
mapImages.put(key, (ImagesResource) resource);
|
|
break;
|
|
case MAP:
|
|
break;
|
|
case ERROR:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (mapValues.size() > 0) {
|
|
HtmlLayoutContainer html = new HtmlLayoutContainer("Output Values");
|
|
html.setStyleName("computation-output-groupTitle");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
vp.add((new ResourceViewer(mapValues)).getHtml(),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
|
|
html = new HtmlLayoutContainer(
|
|
"<div class='computation-output-separator'></div>");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
}
|
|
|
|
if (mapFiles.size() > 0) {
|
|
HtmlLayoutContainer html = new HtmlLayoutContainer("Files");
|
|
html.setStyleName("computation-output-groupTitle");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
for (String fileKey : mapFiles.keySet()) {
|
|
// vp.add(new Html("<i>"+fileKey+"</i>"));
|
|
vp.add(getFileResourceOutput(mapFiles.get(fileKey)),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
}
|
|
|
|
html = new HtmlLayoutContainer(
|
|
"<div class='computation-output-separator'></div>");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
}
|
|
|
|
if (mapTabs.size() > 0) {
|
|
HtmlLayoutContainer html = new HtmlLayoutContainer("Tables");
|
|
html.setStyleName("computation-output-groupTitle");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
for (String tabKey : mapTabs.keySet()) {
|
|
// vp.add(new Html("<i>"+tabKey+"</i>"));
|
|
// vp.add(getTabResourceOutput(mapTabs.get(tabKey)));
|
|
}
|
|
|
|
html = new HtmlLayoutContainer(
|
|
"<div class='computation-output-separator'></div>");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
}
|
|
|
|
if (mapImages.size() > 0) {
|
|
HtmlLayoutContainer html = new HtmlLayoutContainer("Images");
|
|
html.setStyleName("computation-output-groupTitle");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
for (String imagesKey : mapImages.keySet()) {
|
|
vp.add(getImagesResourceOutput(mapImages.get(imagesKey)),
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
}
|
|
|
|
html = new HtmlLayoutContainer(
|
|
"<div class='computation-output-separator'></div>");
|
|
vp.add(html, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
}
|
|
|
|
container.add(vp);
|
|
return container;
|
|
}
|
|
}
|