284 lines
8.2 KiB
Java
284 lines
8.2 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.dataminermanager.client.widgets;
|
|
|
|
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.shared.data.ComputationId;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
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.event.SelectEvent;
|
|
|
|
/**
|
|
* @author ceras
|
|
*
|
|
*/
|
|
public class ComputationOutputPanel extends SimpleContainer {
|
|
|
|
private ComputationId computationId;
|
|
private final DataMinerPortletServiceAsync service = DataMinerManager.getService();
|
|
private VerticalLayoutContainer v;
|
|
|
|
public ComputationOutputPanel(ComputationId computationId) {
|
|
super();
|
|
this.computationId = computationId;
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
v = new VerticalLayoutContainer();
|
|
add(v);
|
|
|
|
// request for a jobItem linked with the computationId (or jobId)
|
|
service.getResourceByComputationId(computationId,
|
|
new AsyncCallback<Resource>() {
|
|
@Override
|
|
public void onSuccess(Resource result) {
|
|
unmask();
|
|
showOutputInfo(result);
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
unmask();
|
|
UtilsGXT3.alert("Error",
|
|
"Impossible to retrieve output info.", null);
|
|
}
|
|
});
|
|
|
|
this.mask("Loading Result Info...");
|
|
}
|
|
|
|
/**
|
|
* @param jobOutput
|
|
*/
|
|
protected void showOutputInfo(Resource resource) {
|
|
if (resource == null)
|
|
return;
|
|
|
|
ResourceType resourceType = resource.getResourceType();
|
|
|
|
switch (resourceType) {
|
|
|
|
case FILE:
|
|
FileResource fileResource = (FileResource) resource;
|
|
v.add(getHtmlTitle("The algorithm produced a <b>File</b>."));
|
|
v.add(getFileResourceOutput(fileResource));
|
|
break;
|
|
|
|
case TABULAR:
|
|
TableResource tabResource = (TableResource) resource;
|
|
v.add(getHtmlTitle("The algorithm produced a <b>Table</b>."));
|
|
// v.add(getTabResourceOutput(tabResource));
|
|
break;
|
|
|
|
case IMAGES:
|
|
v.add(getHtmlTitle("The algorithm produced an <b>Set of Images</b>."));
|
|
final ImagesResource imagesResource = (ImagesResource) resource;
|
|
v.add(getImagesResourceOutput(imagesResource));
|
|
break;
|
|
|
|
case MAP:
|
|
v.add(getHtmlTitle("The algorithm produced <b>Multiple Results</b>."));
|
|
|
|
final MapResource mapResource = (MapResource) resource;
|
|
|
|
v.add(getMultipleOutput(mapResource));
|
|
break;
|
|
case ERROR:
|
|
break;
|
|
case OBJECT:
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
this.add(new HTML("<br/>"));
|
|
forceLayout();
|
|
}
|
|
|
|
/**
|
|
* @param string
|
|
* @return
|
|
*/
|
|
private HTML getHtmlTitle(String title) {
|
|
HTML html = new HTML(title);
|
|
html.setStyleName("jobViewer-output-outputType");
|
|
return html;
|
|
}
|
|
|
|
/**
|
|
* @param imagesResource
|
|
* @return
|
|
*/
|
|
private SimpleContainer getImagesResourceOutput(
|
|
ImagesResource imagesResource) {
|
|
SimpleContainer container = new SimpleContainer();
|
|
container.add(new ImagesViewer(computationId, imagesResource));
|
|
return container;
|
|
}
|
|
|
|
/**
|
|
* @param tabResource
|
|
*
|
|
* private LayoutContainer getTabResourceOutput(TableResource
|
|
* tabResource) { final String tableName = tabResource.getName();
|
|
* final String tableId = tabResource.getResourceId();
|
|
* LayoutContainer lc = new LayoutContainer(); lc.add(new
|
|
* Html("Data Set Created: <b>" + tableName + "</b><br/>
|
|
* <br/>
|
|
* "));
|
|
*
|
|
* lc.add(new Button("<b>Show Data Set</b>", Images.table(), new
|
|
* SelectionListener<ButtonEvent>() {
|
|
* @Override public void componentSelected(ButtonEvent ce) { final
|
|
* TabularData tabularData = DataMinerManager .getTabularData();
|
|
* TabularDataGridPanel grid = tabularData.getGridPanel();
|
|
* grid.setHeaderVisible(false); Window window = new Window();
|
|
* window.setMaximizable(true); window.setHeadingText("Data Set "
|
|
* + tableName); window.setModal(true); window.add(grid);
|
|
* window.setWidth(900); window.setHeight(500);
|
|
* tabularData.openTable(tableId); window.show(); } })); return
|
|
* lc; }
|
|
*/
|
|
|
|
/**
|
|
* @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();
|
|
lc.add(new HTML(fileName));
|
|
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);
|
|
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) {
|
|
HTML html = new HTML("Output Values");
|
|
html.setStyleName("jobViewer-output-groupTitle");
|
|
vp.add(html);
|
|
|
|
vp.add((new ResourceViewer(mapValues)).getHtml());
|
|
|
|
html = new HTML("<div class='jobViewer-output-separator'></div>");
|
|
vp.add(html);
|
|
}
|
|
|
|
if (mapFiles.size() > 0) {
|
|
HTML html = new HTML("Files");
|
|
html.setStyleName("jobViewer-output-groupTitle");
|
|
vp.add(html);
|
|
|
|
for (String fileKey : mapFiles.keySet()) {
|
|
// vp.add(new Html("<i>"+fileKey+"</i>"));
|
|
vp.add(getFileResourceOutput(mapFiles.get(fileKey)));
|
|
}
|
|
|
|
html = new HTML("<div class='jobViewer-output-separator'></div>");
|
|
vp.add(html);
|
|
}
|
|
|
|
if (mapTabs.size() > 0) {
|
|
HTML html = new HTML("Tables");
|
|
html.setStyleName("jobViewer-output-groupTitle");
|
|
vp.add(html);
|
|
|
|
for (String tabKey : mapTabs.keySet()) {
|
|
// vp.add(new Html("<i>"+tabKey+"</i>"));
|
|
// vp.add(getTabResourceOutput(mapTabs.get(tabKey)));
|
|
}
|
|
|
|
html = new HTML("<div class='jobViewer-output-separator'></div>");
|
|
vp.add(html);
|
|
}
|
|
|
|
if (mapImages.size() > 0) {
|
|
HTML html = new HTML("Images");
|
|
html.setStyleName("jobViewer-output-groupTitle");
|
|
vp.add(html);
|
|
|
|
for (String imagesKey : mapImages.keySet()) {
|
|
// vp.add(new Html("<i>"+imagesKey+"</i>"));
|
|
vp.add(getImagesResourceOutput(mapImages.get(imagesKey)));
|
|
}
|
|
|
|
html = new HTML("<div class='jobViewer-output-separator'></div>");
|
|
vp.add(html);
|
|
}
|
|
|
|
container.add(vp);
|
|
return container;
|
|
}
|
|
}
|