data-miner-manager/src/main/java/org/gcube/portlets/user/dataminermanager/client/computations/ComputationsViewerPanel.java

310 lines
10 KiB
Java

package org.gcube.portlets.user.dataminermanager.client.computations;
import java.util.LinkedHashMap;
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
import org.gcube.portlets.user.dataminermanager.client.events.ComputationDataEvent;
import org.gcube.portlets.user.dataminermanager.client.events.DataMinerWorkAreaEvent;
import org.gcube.portlets.user.dataminermanager.client.events.RefreshDataMinerWorkAreaEvent;
import org.gcube.portlets.user.dataminermanager.client.events.UIStateEvent;
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.data.ComputationData;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.dom.client.Style.Unit;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.FramedPanel;
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.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.TextArea;
import com.sencha.gxt.widget.core.client.form.TextField;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ComputationsViewerPanel extends FramedPanel {
private VerticalLayoutContainer v;
private ComputationData computationData;
public ComputationsViewerPanel() {
super();
Log.debug("ComputationsPanel");
// msgs = GWT.create(ServiceCategoryMessages.class);
init();
bindToEvents();
create();
}
private void init() {
setId("ComputationsViewerPanel");
forceLayoutOnResize = true;
setBodyBorder(true);
setBodyStyle("backgroundColor:white;");
setHeaderVisible(true);
setResize(true);
setAnimCollapse(false);
setHeadingText("Computations Viewer");
}
private void create() {
v = new VerticalLayoutContainer();
v.setScrollMode(ScrollMode.AUTO);
add(v);
}
private void bindToEvents() {
EventBusProvider.INSTANCE.addHandler(UIStateEvent.TYPE,
new UIStateEvent.UIStateEventHandler() {
@Override
public void onChange(UIStateEvent event) {
Log.debug("Catch UIStateEvent: " + event);
manageStateEvents(event);
}
});
EventBusProvider.INSTANCE.addHandler(DataMinerWorkAreaEvent.TYPE,
new DataMinerWorkAreaEvent.DataMinerWorkAreaEventHandler() {
@Override
public void onChange(DataMinerWorkAreaEvent event) {
Log.debug("Catch DataMinerWorkAreaEvent: " + event);
manageDataMinerWorkAreaEvents(event);
}
});
EventBusProvider.INSTANCE
.addHandler(
RefreshDataMinerWorkAreaEvent.TYPE,
new RefreshDataMinerWorkAreaEvent.RefreshDataMinerWorkAreaEventHandler() {
@Override
public void onRefresh(
RefreshDataMinerWorkAreaEvent event) {
Log.debug("Catch RefreshDataMinerWorkAreaEvent: "
+ event);
manageRefreshDataMinerWorkAreaEvents(event);
}
});
EventBusProvider.INSTANCE.addHandler(ComputationDataEvent.getType(),
new ComputationDataEvent.ComputationDataEventHandler() {
@Override
public void onComputationData(ComputationDataEvent event) {
Log.debug("Catch ComputationDataEvent: " + event);
showOutput(event);
}
});
}
private void manageStateEvents(UIStateEvent event) {
switch (event.getUiStateType()) {
case START:
break;
case WAITING:
break;
case UPDATE:
break;
default:
break;
}
}
private void manageDataMinerWorkAreaEvents(DataMinerWorkAreaEvent event) {
switch (event.getDataMinerWorkAreaEventType()) {
case OPEN:
case UPDATE:
resetPanel();
break;
default:
break;
}
}
private void manageRefreshDataMinerWorkAreaEvents(
RefreshDataMinerWorkAreaEvent event) {
switch (event.getDataMinerWorkAreaElementType()) {
case Computations:
resetPanel();
break;
case InputDataSets:
break;
case OutputDataSets:
break;
default:
break;
}
}
public void resetPanel() {
v.clear();
SimpleContainer sectionTitle=new SimpleContainer();
HtmlLayoutContainer title=new HtmlLayoutContainer(
"<br><center>No computation selected.</center>");
sectionTitle.add(title);
v.add(sectionTitle, new VerticalLayoutData(-1, -1, new Margins(15)));
computationData=null;
forceLayout();
}
private void showOutput(ComputationDataEvent event) {
v.clear();
computationData = event.getComputationData();
addComputationData();
}
/**
*
*/
private void addComputationData() {
if(computationData==null){
Log.error("ComputationData is null!");
UtilsGXT3.alert("Error", "No information on computation is retrieved!");
return;
}
SimpleContainer sectionTitle=new SimpleContainer();
// title
HtmlLayoutContainer title = new HtmlLayoutContainer(
".: Computation Report of <b>" + computationData.getComputationId().getId() + "</b>");
sectionTitle.add(title);
//v.add(sectionTitle, new VerticalLayoutData(1, -1, new Margins(15)));
if(computationData.getOutputParameters()!=null&&!computationData.getOutputParameters().isEmpty()){
VerticalLayoutContainer outputVBox=new VerticalLayoutContainer();
LinkedHashMap<String,String> output=computationData.getOutputParameters();
for(String key:output.keySet()){
TextField textField=new TextField();
textField.setValue(output.get(key));
textField.setReadOnly(true);
FieldLabel fieldLabel=new FieldLabel(textField, key);
fieldLabel.setLabelWidth(200);
fieldLabel.setLabelWordWrap(true);
outputVBox.add(fieldLabel,new VerticalLayoutData(1, -1, new Margins(4)));
}
FieldSet outputFieldSet=new FieldSet();
outputFieldSet.setHeadingText("Output Result");
outputFieldSet.setCollapsible(true);
outputFieldSet.add(outputVBox);
outputFieldSet.getElement().getStyle().setMarginRight(15, Unit.PX);
v.add(outputFieldSet, new VerticalLayoutData(1, -1, new Margins(15)));
}
if(computationData.getInputParameters()!=null&&!computationData.getInputParameters().isEmpty()){
VerticalLayoutContainer inputVBox=new VerticalLayoutContainer();
LinkedHashMap<String,String> input=computationData.getInputParameters();
for(String key:input.keySet()){
TextField textField=new TextField();
textField.setValue(input.get(key));
textField.setReadOnly(true);
FieldLabel fieldLabel=new FieldLabel(textField, key);
fieldLabel.setLabelWidth(200);
fieldLabel.setLabelWordWrap(true);
inputVBox.add(fieldLabel,new VerticalLayoutData(1, -1, new Margins(4)));
}
FieldSet inputFieldSet=new FieldSet();
inputFieldSet.setHeadingText("Input Parameters");
inputFieldSet.setCollapsible(true);
inputFieldSet.add(inputVBox);
inputFieldSet.getElement().getStyle().setMarginRight(15, Unit.PX);
v.add(inputFieldSet, new VerticalLayoutData(1, -1, new Margins(15)));
}
VerticalLayoutContainer detailsVBox=new VerticalLayoutContainer();
TextField startDateField=new TextField();
startDateField.setValue(computationData.getStartDate());
startDateField.setReadOnly(true);
FieldLabel startDateLabel=new FieldLabel(startDateField, "Start Date");
startDateLabel.setLabelWidth(200);
startDateLabel.setLabelWordWrap(true);
detailsVBox.add(startDateLabel,new VerticalLayoutData(1, -1, new Margins(4)));
TextField endDateField=new TextField();
endDateField.setValue(computationData.getEndDate());
endDateField.setReadOnly(true);
FieldLabel endDateLabel=new FieldLabel(endDateField, "End Date");
endDateLabel.setLabelWidth(200);
endDateLabel.setLabelWordWrap(true);
detailsVBox.add(endDateLabel,new VerticalLayoutData(1, -1, new Margins(4)));
TextField statusField=new TextField();
statusField.setValue(computationData.getStatus());
statusField.setReadOnly(true);
FieldLabel statusLabel=new FieldLabel(statusField, "Status");
statusLabel.setLabelWidth(200);
statusLabel.setLabelWordWrap(true);
detailsVBox.add(statusLabel,new VerticalLayoutData(1, -1, new Margins(4)));
TextField vreField=new TextField();
vreField.setValue(computationData.getVre());
vreField.setReadOnly(true);
FieldLabel vreLabel=new FieldLabel(vreField, "VRE");
vreLabel.setLabelWidth(200);
vreLabel.setLabelWordWrap(true);
detailsVBox.add(vreLabel,new VerticalLayoutData(1, -1, new Margins(4)));
FieldSet detailsFieldSet=new FieldSet();
detailsFieldSet.setHeadingText("Computation Details");
detailsFieldSet.setCollapsible(true);
detailsFieldSet.add(detailsVBox);
detailsFieldSet.getElement().getStyle().setMarginRight(15, Unit.PX);
v.add(detailsFieldSet, new VerticalLayoutData(1, -1, new Margins(15)));
VerticalLayoutContainer operatorVBox=new VerticalLayoutContainer();
TextField operatorNameField=new TextField();
operatorNameField.setValue(computationData.getComputationId().getOperatorName());
operatorNameField.setReadOnly(true);
FieldLabel operatorNameLabel=new FieldLabel(operatorNameField, "Operator Name");
operatorNameLabel.setLabelWidth(200);
operatorNameLabel.setLabelWordWrap(true);
operatorVBox.add(operatorNameLabel,new VerticalLayoutData(1, -1, new Margins(4)));
TextArea operatorDescriptionField=new TextArea();
operatorDescriptionField.setHeight("50px");
operatorDescriptionField.setValue(computationData.getOperatorDescription());
operatorDescriptionField.setReadOnly(true);
FieldLabel operatorDescriptionLabel=new FieldLabel(operatorDescriptionField, "Operator Description");
operatorDescriptionLabel.setLabelWidth(200);
operatorDescriptionLabel.setLabelWordWrap(true);
operatorVBox.add(operatorDescriptionLabel,new VerticalLayoutData(1, -1, new Margins(5)));
FieldSet operatorFieldSet=new FieldSet();
operatorFieldSet.setHeadingText("Operator Details");
operatorFieldSet.setCollapsible(true);
operatorFieldSet.add(operatorVBox);
operatorFieldSet.getElement().getStyle().setMarginRight(15, Unit.PX);
v.add(operatorFieldSet, new VerticalLayoutData(1, -1, new Margins(15)));
forceLayout();
}
}