Updated OperationMonitor

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-export-widget@99352 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-08-29 17:31:26 +00:00
parent 8219fe48ad
commit ec14ca558b
1 changed files with 107 additions and 63 deletions

View File

@ -6,25 +6,23 @@ package org.gcube.portlets.user.td.csvexportwidget.client;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorBarUpdater;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorUpdater;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorUpdaterListener;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.ProgressBar;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayoutAlign;
import com.sencha.gxt.widget.core.client.event.HideEvent;
@ -37,13 +35,12 @@ import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
*
*/
public class CSVOperationInProgressCard extends WizardCard implements
MonitorUpdaterListener {
MonitorDialogListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected CSVOperationInProgressCard thisCard;
protected CSVExportSession exportSession;
protected MonitorUpdater progressUpdater;
protected ProgressBar progressBar;
protected TRId newTrId;
protected HtmlLayoutContainer resultField;
public CSVOperationInProgressCard(final CSVExportSession exportSession) {
super("Operation In Progress", "");
@ -79,31 +76,23 @@ public class CSVOperationInProgressCard extends WizardCard implements
operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20,
5, 10, 5)));
progressBar = new ProgressBar();
operationInProgressPanel.add(progressBar, new BoxLayoutData(
new Margins(10, 5, 10, 5)));
resultField = new HtmlLayoutContainer("<div></div>");
operationInProgressPanel.add(resultField, new BoxLayoutData(
new Margins(10, 5, 10, 5)));
setContent(operationInProgressPanel);
resultField.setVisible(false);
}
// columnToImportMask
public void exportCSV() {
TDGWTServiceAsync.INSTANCE.startCSVExport(exportSession,
new AsyncCallback<String>() {
public void onSuccess(String taskId) {
OperationMonitorSession operationMonitorSession=new OperationMonitorSession(taskId);
progressUpdater = new MonitorUpdater(operationMonitorSession);
progressUpdater
.addListener(new MonitorBarUpdater(progressBar));
openMonitorDialog(taskId);
progressUpdater.addListener(thisCard);
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
}
public void onFailure(Throwable caught) {
@ -133,27 +122,29 @@ public class CSVOperationInProgressCard extends WizardCard implements
exportCSV();
}
@Override
public void monitorInitializing(OperationMonitor operationMonitor) {
//
protected void openMonitorDialog(String taskId) {
MonitorDialog monitorDialog = new MonitorDialog(taskId, getEventBus());
monitorDialog.addProgressDialogListener(this);
monitorDialog.show();
}
@Override
public void monitorUpdate(OperationMonitor operationMonitor) {
}
@Override
public void monitorComplete(final TRId trId, OperationMonitor operationMonitor) {
public void operationComplete(TRId trId) {
newTrId = trId;
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold; color:#009900;'>Operation Completed</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Complete: "+ trId);
getWizardWindow().fireCompleted(trId);
Log.info("fire Complete: " + newTrId);
getWizardWindow().fireCompleted(newTrId);
} catch (Exception e) {
Log.error("fire Complete :" + e.getLocalizedMessage());
@ -165,11 +156,18 @@ public class CSVOperationInProgressCard extends WizardCard implements
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
public void monitorFailed(Throwable caught, String reason,
String failureDetails, OperationMonitor operationMonitor) {
public void operationFailed(Throwable caught, String reason, String details) {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color:red;'>Operation Failed</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus()
.fireEvent(
@ -184,19 +182,28 @@ public class CSVOperationInProgressCard extends WizardCard implements
});
d.show();
}
forceLayout();
}
@Override
public void monitorStopped(final TRId trId, String reason, String details, OperationMonitor operationMonitor) {
public void operationStopped(TRId trId, String reason, String details) {
newTrId = trId;
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #FF9900;'>Problems in the Operation</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Complete: tabular resource " + trId.getId());
Log.info("fire Complete: tableId " + trId.getTableId());
Log.info("fire Complete: tabular resource "
+ newTrId.getId());
Log.info("fire Complete: tableId " + newTrId.getTableId());
getWizardWindow().fireCompleted(trId);
getWizardWindow().fireCompleted(newTrId);
} catch (Exception e) {
Log.error("fire Complete :" + e.getLocalizedMessage());
@ -209,31 +216,68 @@ public class CSVOperationInProgressCard extends WizardCard implements
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
public void monitorGeneratingView(OperationMonitor operationMonitor) {
// TODO Auto-generated method stub
public void operationAborted() {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #AA00AA;'>Operation Aborted</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Aborted");
getWizardWindow().fireAborted();
} catch (Exception e) {
Log.error("fire Aborted :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setNextButtonCommand(sayComplete);
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
public void monitorValidate(OperationMonitor operationMonitor) {
// TODO Auto-generated method stub
public void operationPutInBackground() {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #00AAAA;'>Operation in Background</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Operation In Background");
getWizardWindow().fireAborted();
} catch (Exception e) {
Log.error("fire Operation In Background :"
+ e.getLocalizedMessage());
}
}
};
getWizardWindow().setNextButtonCommand(sayComplete);
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
public void monitorAborted() {
// TODO Auto-generated method stub
}
@Override
public void monitorPutInBackground() {
// TODO Auto-generated method stub
}
}