Updated OperationMonitor

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

View File

@ -6,25 +6,21 @@ package org.gcube.portlets.user.td.extractcodelistwidget.client;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession;
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,17 +33,12 @@ import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
*
*/
public class ExtractCodelistOperationInProgressCard extends WizardCard
implements MonitorUpdaterListener {
implements MonitorDialogListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected ExtractCodelistOperationInProgressCard thisCard;
protected ExtractCodelistSession extractCodelistSession;
protected MonitorUpdater progressUpdater;
protected ProgressBar progressBar;
protected final FlexTable description;
protected final FramedPanel summary;
protected TRId newTrId;
protected HtmlLayoutContainer resultField;
public ExtractCodelistOperationInProgressCard(
final ExtractCodelistSession extractCodelistSession) {
@ -59,29 +50,13 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer();
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
progressBar = new ProgressBar();
operationInProgressPanel.add(progressBar, new BoxLayoutData(
new Margins(10, 30, 10, 5)));
resultField = new HtmlLayoutContainer("<div></div>");
description = new FlexTable();
description.setCellSpacing(10);
description.setCellPadding(4);
description.setBorderWidth(0);
description
.setHTML(0, 0,
"The Codelists is available in the list of yours tabular resources");
summary = new FramedPanel();
summary.setHeadingText("Operation Completed");
summary.setWidth(400);
summary.add(description);
operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20,
5, 10, 5)));
operationInProgressPanel.add(resultField, new BoxLayoutData(
new Margins(10, 5, 10, 5)));
setContent(operationInProgressPanel);
summary.setVisible(false);
resultField.setVisible(false);
}
@ -90,15 +65,7 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
new AsyncCallback<String>() {
public void onSuccess(String taskId) {
OperationMonitorSession operationMonitorSession = new OperationMonitorSession(
taskId);
progressUpdater = new MonitorUpdater(
operationMonitorSession);
progressUpdater.addListener(new MonitorBarUpdater(
progressBar));
progressUpdater.addListener(thisCard);
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
openMonitorDialog(taskId);
}
@ -128,29 +95,29 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
extractCodelist();
}
@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) {
summary.setVisible(true);
progressBar.setVisible(false);
forceLayout();
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>"
+ "<div style=' margin-top:30px;text-align:center;font-size:medium;font-weight:bold; color:black;'>The Codelists is available in the list of yours tabular resources</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Complete: " + trId);
Log.info("fire Complete: " + newTrId);
getWizardWindow().fireCompleted(trId);
getWizardWindow().fireCompleted(newTrId);
} catch (Exception e) {
Log.error("fire Complete :" + e.getLocalizedMessage());
@ -162,11 +129,17 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
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(
@ -181,19 +154,27 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
});
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());
@ -205,30 +186,67 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
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 monitorGeneratingView(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");
@Override
public void monitorValidate(OperationMonitor operationMonitor) {
// TODO Auto-generated method stub
getWizardWindow().fireAborted();
}
} catch (Exception e) {
Log.error("fire Operation In Background :"
+ e.getLocalizedMessage());
}
}
};
@Override
public void monitorAborted() {
// TODO Auto-generated method stub
getWizardWindow().setNextButtonCommand(sayComplete);
}
@Override
public void monitorPutInBackground() {
// TODO Auto-generated method stub
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}