From 7d8a0f714288e8891ed6c9da68b82ff1653606be Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 1 Aug 2014 17:50:58 +0000 Subject: [PATCH] Minor Update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-monitor-widget@99199 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ProgressBarUpdater.java | 94 +++++++++ .../monitorwidget/client/ProgressDialog.java | 179 ++++++++++++++++ .../client/ProgressDialogListener.java | 34 ++++ .../client/ProgressListener.java | 60 ++++++ .../monitorwidget/client/ProgressUpdater.java | 192 ++++++++++++++++++ 5 files changed, 559 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressBarUpdater.java create mode 100644 src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialogListener.java create mode 100644 src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressListener.java create mode 100644 src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressUpdater.java diff --git a/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressBarUpdater.java b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressBarUpdater.java new file mode 100644 index 0000000..7a3c772 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressBarUpdater.java @@ -0,0 +1,94 @@ +package org.gcube.portlets.user.td.monitorwidget.client; + + + + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +import com.allen_sauer.gwt.log.client.Log; +import com.sencha.gxt.widget.core.client.ProgressBar; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class ProgressBarUpdater implements ProgressListener { + + protected ProgressBar progressBar; + + /** + * Creates a new {@link ProgressBar} updater. + * @param progressBar the {@link ProgressBar} to update. + */ + public ProgressBarUpdater(ProgressBar progressBar) { + this.progressBar = progressBar; + this.progressBar.updateProgress(0, "Please Wait..."); + } + + + /** + * {@inheritDoc} + */ + @Override + public void operationComplete(TRId trId) { + Log.info("Completed"); + progressBar.updateProgress(1, "Completed"); + + } + + /** + * {@inheritDoc} + */ + @Override + public void operationFailed(Throwable caught, String reason, String failureDetails) { + Log.info("Failed"); + progressBar.updateText("Failed"); + } + + @Override + public void operationInitializing() { + Log.info("Inizializing"); + progressBar.updateProgress(0, "Initializing..."); + } + + @Override + public void operationUpdate(float elaborated) { + Log.info("Elaborated: "+elaborated); + if (elaborated>=0 && elaborated<1) { + Log.trace("progress "+elaborated); + int elab=new Float(elaborated*100).intValue(); + progressBar.updateProgress(elaborated,elab+"% Progress..."); + } + if (elaborated == 1) progressBar.updateProgress(1, "Completing..."); + + } + + @Override + public void operationValidate(float elaborated) { + Log.info("Validation Elaborated: "+elaborated); + if (elaborated == 0) progressBar.updateProgress(0, "Start Validation..."); + if (elaborated>0 && elaborated<1) { + Log.trace("Validation progress "+elaborated); + int elab=new Float(elaborated*100).intValue(); + progressBar.updateProgress(elaborated,elab+"% Validation Progress..."); + } + if (elaborated == 1) progressBar.updateProgress(1, "Validation..."); + } + + @Override + public void operationStopped(TRId trId,String reason, String details) { + Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]"); + progressBar.updateText("Validations failed"); + + } + + @Override + public void operationGeneratingView() { + Log.info("Generating View..."); + progressBar.updateText("Generating View..."); + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialog.java b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialog.java new file mode 100644 index 0000000..8d491ec --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialog.java @@ -0,0 +1,179 @@ +package org.gcube.portlets.user.td.monitorwidget.client; + + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +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 com.allen_sauer.gwt.log.client.Log; +import com.google.web.bindery.event.shared.EventBus; +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.Window; +import com.sencha.gxt.widget.core.client.button.TextButton; +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; + +/** + * AddColumnProgressDialog is a Dialog that show progress of AddColumn + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ProgressDialog extends Window implements + ProgressListener { + protected ArrayList listeners = new ArrayList(); + + public static final int STATUS_POLLING_DELAY = 1000; + protected String WIDTH = "400px"; + protected String HEIGHT = "120px"; + protected EventBus eventBus; + protected ProgressUpdater progressUpdater; + protected TextButton ok; + protected TRId trId; + private String reason; + private String details; + + public ProgressDialog( + EventBus eventBus) { + this.eventBus = eventBus; + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(true); + setModal(true); + setHeadingText("Add Column Progress"); + + trId = null; + + FramedPanel panel = new FramedPanel(); + panel.setHeaderVisible(false); + panel.setBodyBorder(false); + + VerticalLayoutContainer v = new VerticalLayoutContainer(); + + ProgressBar progressBar = new ProgressBar(); + + ok = new TextButton("OK"); + ok.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + updateInvocation(); + + } + }); + + v.add(progressBar, + new VerticalLayoutData(1, 1, new Margins(5, 5, 5, 5))); + + panel.add(v); + panel.addButton(ok); + add(panel); + + progressUpdater = new ProgressUpdater(); + progressUpdater.addListener(new ProgressBarUpdater( + progressBar)); + + progressUpdater.addListener(this); + progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY); + show(); + ok.setVisible(false); + + } + + public void addProgressDialogListener(ProgressDialogListener listener) { + listeners.add(listener); + } + + public void removeProgressDialogListener(ProgressDialogListener listener) { + listeners.remove(listener); + } + + @Override + public void operationInitializing() { + // TODO Auto-generated method stub + + } + + @Override + public void operationUpdate(float elaborated) { + // TODO Auto-generated method stub + + } + + @Override + public void operationComplete(TRId trId) { + Log.debug("Operation Complete return: " + trId.toString()); + this.trId = trId; + fireOperationComplete(trId); + hide(); + } + + @Override + public void operationFailed(Throwable caught, String reason, + String failureDetails) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + fireOperationFailed(caught,reason); + hide(); + + } + } + + public void updateInvocation() { + if (trId != null) { + fireOperationStopped(trId, reason, details); + } + hide(); + + } + + @Override + public void operationStopped(TRId trId, String reason, String details) { + Log.debug("Operation Stopped: [" + trId.toString() + ", " + reason + + ", " + details + "]"); + this.trId = trId; + this.reason=reason; + this.details=details; + ok.setVisible(true); + + } + + @Override + public void operationGeneratingView() { + // TODO Auto-generated method stub + + } + + @Override + public void operationValidate(float elaborated) { + // TODO Auto-generated method stub + + } + + protected void fireOperationComplete(TRId trId) { + for (ProgressDialogListener listener : listeners) + listener.operationComplete(trId); + } + + protected void fireOperationFailed(Throwable caught, String reason) { + for (ProgressDialogListener listener : listeners) + listener.operationFailed(caught, reason); + } + + protected void fireOperationStopped(TRId trId, String reason, String details) { + for (ProgressDialogListener listener : listeners) + listener.operationStopped(trId,reason, details); + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialogListener.java b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialogListener.java new file mode 100644 index 0000000..c0154f4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressDialogListener.java @@ -0,0 +1,34 @@ +package org.gcube.portlets.user.td.monitorwidget.client; + + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +public interface ProgressDialogListener { + + + /** + * Called when the operation is complete. + */ + public void operationComplete(TRId trId); + + /** + * Called when the operation is failed. + * @param caught the failure exception. + * @param reason the failure reason. + */ + public void operationFailed(Throwable caught, String reason); + + + + /** + * Called when the operation is stopped + * + * @param trId + * @param reason + * @param details + */ + public void operationStopped(TRId trId, String reason, String details); + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressListener.java b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressListener.java new file mode 100644 index 0000000..e93a164 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressListener.java @@ -0,0 +1,60 @@ +package org.gcube.portlets.user.td.monitorwidget.client; + + +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + + + +/** + * Defines a listener for operation progress. + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface ProgressListener { + + /** + * Called when the operation is starting. + */ + public void operationInitializing(); + + /** + * Called when there is a progress for the operation. + * @param elaborated the elaborated part. + */ + public void operationUpdate(float elaborated); + + /** + * Called when there is a validate for the operation. + * @param elaborated the elaborated part. + */ + public void operationValidate(float elaborated); + + /** + * Called when the operation is complete. + */ + public void operationComplete(TRId trId); + + /** + * Called when the operation is failed. + * @param caught the failure exception. + * @param reason the failure reason. + */ + public void operationFailed(Throwable caught, String reason, String failureDetails); + + /** + * Called when the operation is stopped + * + * @param trId + * @param reason + * @param details + */ + public void operationStopped(TRId trId, String reason, String details); + + /** + * Called when the operation is generating the view + */ + public void operationGeneratingView(); + +} diff --git a/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressUpdater.java b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressUpdater.java new file mode 100644 index 0000000..18b6987 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/ProgressUpdater.java @@ -0,0 +1,192 @@ +package org.gcube.portlets.user.td.monitorwidget.client; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.monitor.AddColumnMonitor; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class ProgressUpdater extends Timer { + + protected ArrayList listeners = new ArrayList(); + + /** + * {@inheritDoc} + */ + @Override + public void run() { + Log.debug("requesting operation progress"); + TDGWTServiceAsync.INSTANCE + .getAddColumnMonitor(new AsyncCallback() { + + + public void onFailure(Throwable caught) { + cancel(); + Log.error("Error retrieving the operation state", + caught); + String message = getStack(caught); + fireOperationFailed(caught, + "Failed getting operation updates", message); + } + + public void onSuccess(AddColumnMonitor result) { + Log.info("retrieved AddColumnMonitor: " + + result.getStatus()); + switch (result.getStatus()) { + case INITIALIZING: + Log.info("Initializing..."); + fireOperationInitializing(); + break; + case ABORTED: + cancel(); + Log.info("Aborted"); + break; + case IN_PROGRESS: + fireOperationUpdate(result.getProgress()); + break; + case VALIDATING_RULES: + fireOperationValidate(result.getProgress()); + break; + case GENERATING_VIEW: + Log.info("Generating View..."); + fireOperationGeneratingView(); + break; + case STOPPED: + cancel(); + stopMessage(result); + break; + case FAILED: + cancel(); + errorMessage(result); + break; + case SUCCEDED: + cancel(); + Log.info("Fisnish :" + + result.getTrId()); + fireOperationComplete(result.getTrId()); + break; + default: + Log.info("Unknow State"); + break; + } + + } + + + + }); + + } + + protected void errorMessage(AddColumnMonitor result) { + Log.info("AddColumn Failed"); + Throwable th = null; + String failure = null; + String details = null; + if (result.getError() != null) { + th = result.getError(); + failure = "Failed Client Library Add Column"; + details = result.getError().getLocalizedMessage(); + } else { + th = new Throwable("Failed"); + failure = "Failed Client Library Add Columnn"; + details = "Add Column failed"; + } + + fireOperationFailed(th, failure, details); + } + + protected void stopMessage(AddColumnMonitor result) { + Log.info("Add Column Stopped"); + String failure = null; + String details = null; + if (result.getError() != null) { + failure = "Stopped add column"; + details = result.getError().getLocalizedMessage(); + } else { + failure = "Stopped add column"; + details = "Add Column stopped"; + } + + fireOperationStopped(result.getTrId(),failure, details); + } + + + protected String getStack(Throwable e) { + String message = e.getLocalizedMessage() + " ->
"; + Throwable c = e.getCause(); + if (c != null) + message += getStack(c); + return message; + } + + protected void fireOperationInitializing() { + for (ProgressListener listener : listeners) + listener.operationInitializing(); + } + + protected void fireOperationGeneratingView() { + for (ProgressListener listener : listeners) + listener.operationGeneratingView(); + } + + protected void fireOperationUpdate(float elaborated) { + for (ProgressListener listener : listeners) + listener.operationUpdate(elaborated); + } + + protected void fireOperationValidate(float elaborated) { + for (ProgressListener listener : listeners) + listener.operationValidate(elaborated); + } + + protected void fireOperationComplete(TRId trId) { + for (ProgressListener listener : listeners) + listener.operationComplete(trId); + } + + protected void fireOperationFailed(Throwable caught, String failure, + String failureDetails) { + for (ProgressListener listener : listeners) + listener.operationFailed(caught, failure, failureDetails); + } + + protected void fireOperationStopped(TRId trId, String reason, String details) { + for (ProgressListener listener : listeners) + listener.operationStopped(trId,reason, details); + } + + + /** + * Add a new {@link ProgressListener} to this + * {@link AddColumnProgressUpdater}. + * + * @param listener + * the listener to add. + */ + public void addListener(ProgressListener listener) { + listeners.add(listener); + } + + /** + * Removes the specified {@link ProgressListener} from this + * {@link AddColumnProgressUpdater}. + * + * @param listener + * the listener to remove. + */ + public void removeListener(ProgressListener listener) { + listeners.remove(listener); + } +}