201 lines
5.9 KiB
Java
201 lines
5.9 KiB
Java
package org.gcube.portlets.user.dataminermanager.client.experimentArea;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.ComputationItem;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.Operator;
|
|
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.JobsGridGotDirtyEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.ResubmitComputationEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.ComputationId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.widget.core.client.ContentPanel;
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
import com.sencha.gxt.widget.core.client.container.MarginData;
|
|
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;
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
|
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
|
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class ComputationPanel extends ContentPanel {
|
|
|
|
private List<ComputationStatusPanel> computationStatusPanels = new ArrayList<ComputationStatusPanel>();
|
|
|
|
private static final String DELETE_ALL_BUTTON_TOOLTIP = "Remove Computations Log";
|
|
private TextButton removeAllButton;
|
|
|
|
private VerticalLayoutContainer vert;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public ComputationPanel() {
|
|
super();
|
|
|
|
bind();
|
|
|
|
// this.setHeading(".: Computation Execution");
|
|
this.setHeaderVisible(false);
|
|
this.addStyleName("computationExcecutionPanel");
|
|
|
|
setToolsPanel();
|
|
vert = new VerticalLayoutContainer();
|
|
add(vert, new MarginData(0));
|
|
}
|
|
|
|
public void startNewComputation(final Operator operator,
|
|
String computationTitle, String computationDescription) {
|
|
Log.debug("Computation Panel: start new computation ");
|
|
final ComputationStatusPanel statusPanel = new ComputationStatusPanel(
|
|
operator);
|
|
computationStatusPanels.add(statusPanel);
|
|
Log.debug("Added status bar ");
|
|
vert.insert(statusPanel, 0, new VerticalLayoutData(1, -1,
|
|
new Margins(0)));
|
|
removeAllButton.setEnabled(true);
|
|
|
|
DataMinerManager.getService().startComputation(operator,
|
|
computationTitle, computationDescription,
|
|
new AsyncCallback<ComputationId>() {
|
|
@Override
|
|
public void onSuccess(ComputationId computationId) {
|
|
if (computationId == null)
|
|
UtilsGXT3
|
|
.alert("ERROR",
|
|
"Failed to start computation "
|
|
+ operator.getName()
|
|
+ ", the computation id is null (1)");
|
|
else {
|
|
statusPanel.computationStarted(computationId);
|
|
EventBusProvider.INSTANCE
|
|
.fireEvent(new JobsGridGotDirtyEvent());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
UtilsGXT3.alert(
|
|
"ERROR",
|
|
"Failed to start computation "
|
|
+ operator.getName()
|
|
+ " (2)<br/>Cause:" + caught.getCause()
|
|
+ "<br/>Message:" + caught.getMessage());
|
|
}
|
|
});
|
|
|
|
forceLayout();
|
|
|
|
}
|
|
|
|
private void bind() {
|
|
EventBusProvider.INSTANCE.addHandler(
|
|
ResubmitComputationEvent.getType(),
|
|
new ResubmitComputationEvent.ResubmitComputationHandler() {
|
|
@Override
|
|
public void onResubmitComputation(
|
|
ResubmitComputationEvent event) {
|
|
resubmitComputation(event.getJobItem());
|
|
}
|
|
});
|
|
}
|
|
|
|
public void resubmitComputation(final ComputationItem computationItem) {
|
|
final ComputationStatusPanel statusPanel = new ComputationStatusPanel(
|
|
computationItem.getOperator());
|
|
computationStatusPanels.add(statusPanel);
|
|
vert.insert(statusPanel, 0, new VerticalLayoutData(1, -1,
|
|
new Margins(0)));
|
|
removeAllButton.setEnabled(true);
|
|
|
|
DataMinerManager.getService().resubmit(
|
|
computationItem.getComputationId(),
|
|
new AsyncCallback<ComputationId>() {
|
|
@Override
|
|
public void onSuccess(ComputationId id) {
|
|
if (id == null)
|
|
UtilsGXT3
|
|
.alert("ERROR",
|
|
"Failed to resubmit computation "
|
|
+ computationItem.getName()
|
|
+ ", the computation id is null (1)");
|
|
else {
|
|
statusPanel.computationStarted(id);
|
|
EventBusProvider.INSTANCE
|
|
.fireEvent(new JobsGridGotDirtyEvent());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
UtilsGXT3.alert("ERROR",
|
|
"Failed to start computation "
|
|
+ computationItem.getName()
|
|
+ " (2)<br/>Cause:" + caught.getCause()
|
|
+ "<br/>Message:" + caught.getMessage());
|
|
}
|
|
});
|
|
|
|
forceLayout();
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private void emptyPanel() {
|
|
// stop timers
|
|
for (ComputationStatusPanel statusPanel : computationStatusPanels)
|
|
statusPanel.stopTimer();
|
|
|
|
removeAllButton.setEnabled(false);
|
|
|
|
computationStatusPanels.clear();
|
|
|
|
vert.clear();
|
|
forceLayout();
|
|
}
|
|
|
|
private void setToolsPanel() {
|
|
ToolBar toolBar = new ToolBar();
|
|
|
|
removeAllButton = new TextButton("Remove All");
|
|
|
|
removeAllButton.addSelectHandler(new SelectHandler() {
|
|
|
|
@Override
|
|
public void onSelect(SelectEvent event) {
|
|
emptyPanel();
|
|
|
|
}
|
|
});
|
|
|
|
removeAllButton.setIcon(DataMinerManager.resources.removeAll());
|
|
|
|
removeAllButton.setToolTip(DELETE_ALL_BUTTON_TOOLTIP);
|
|
removeAllButton.setScale(ButtonScale.MEDIUM);
|
|
removeAllButton.setEnabled(false);
|
|
|
|
FieldLabel toolsLabel = new FieldLabel(removeAllButton, "Tools");
|
|
|
|
toolBar.add(toolsLabel);
|
|
|
|
addTool(toolBar);
|
|
|
|
}
|
|
}
|