From 12820ca65482090b7a4d2a296dde5b347e72c3d3 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 21 Mar 2014 11:46:52 +0000 Subject: [PATCH] Minor Update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@93415 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../TemplateApplyProgressBarUpdater.java | 75 ++++++++ .../progress/TemplateApplyProgressDialog.java | 127 ++++++++++++ .../TemplateApplyProgressListener.java | 52 +++++ .../TemplateApplyProgressUpdater.java | 181 ++++++++++++++++++ .../client/template/TemplateApplyPanel.java | 32 +++- 5 files changed, 465 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressBarUpdater.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressListener.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressUpdater.java diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressBarUpdater.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressBarUpdater.java new file mode 100644 index 0000000..8ffe7eb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressBarUpdater.java @@ -0,0 +1,75 @@ +/** + * + */ +package org.gcube.portlets.user.td.tablewidget.client.progress; + + + + +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 TemplateApplyProgressBarUpdater implements TemplateApplyProgressListener { + + protected ProgressBar progressBar; + + /** + * Creates a new {@link ProgressBar} updater. + * @param progressBar the {@link ProgressBar} to update. + */ + public TemplateApplyProgressBarUpdater(ProgressBar progressBar) { + this.progressBar = progressBar; + } + + + /** + * {@inheritDoc} + */ + public void operationComplete(TRId trId) { + Log.info("Completed"); + progressBar.updateProgress(1, "Completed"); + + } + + /** + * {@inheritDoc} + */ + public void operationFailed(Throwable caught, String reason, String failureDetails) { + Log.info("Failed"); + progressBar.updateText("Failed"); + } + + public void operationInitializing() { + Log.info("Inizializing"); + progressBar.updateProgress(0, "Initializing..."); + } + + public void operationUpdate(float elaborated) { + Log.info("Import elaborated: "+elaborated); + if (elaborated == 0) progressBar.updateProgress(0, "Initializing..."); + 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 operationStopped(TRId trId,String reason, String details) { + Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]"); + progressBar.updateText("Stopped"); + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressDialog.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressDialog.java new file mode 100644 index 0000000..a7551da --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressDialog.java @@ -0,0 +1,127 @@ +package org.gcube.portlets.user.td.tablewidget.client.progress; + +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; +import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType; +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; + + + +/** + * LabelColumnProgressDialog is a Dialog that show progress of change the column label + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class TemplateApplyProgressDialog extends Window implements TemplateApplyProgressListener { + public static final int STATUS_POLLING_DELAY = 1000; + protected String WIDTH = "400px"; + protected String HEIGHT = "120px"; + protected TemplateApplySession templateApplySession; + protected EventBus eventBus; + protected TemplateApplyProgressUpdater progressUpdater; + protected TextButton ok; + protected TRId trId; + + public TemplateApplyProgressDialog(TemplateApplySession templateApplySession, EventBus eventBus) { + this.templateApplySession=templateApplySession; + this.eventBus=eventBus; + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(true); + setModal(true); + setHeadingText("Template Apply 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 TemplateApplyProgressUpdater(); + progressUpdater.addListener(new TemplateApplyProgressBarUpdater(progressBar)); + + progressUpdater.addListener(this); + progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY); + show(); + ok.setVisible(false); + + } + + public void operationInitializing() { + // TODO Auto-generated method stub + + } + + public void operationUpdate(float elaborated) { + // TODO Auto-generated method stub + + } + + public void operationComplete(TRId trId) { + Log.debug("Operation Complete return: "+trId.toString()); + ok.setVisible(true); + this.trId=trId; + } + + public void operationFailed(Throwable caught, String reason, + String failureDetails) { + ok.setVisible(true); + this.trId=null; + UtilsGXT3.alert("Error in Template Apply", reason); + + } + + public void updateInvocation(){ + if(trId!=null){ + ChangeTableRequestEvent changeTableRequestEvent= + new ChangeTableRequestEvent(ChangeTableRequestType.TEMPLATEAPPLY, trId); + eventBus.fireEvent(changeTableRequestEvent); + } + hide(); + } + + @Override + public void operationStopped(TRId trId,String reason, String details) { + Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]"); + ok.setVisible(true); + this.trId=trId; + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressListener.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressListener.java new file mode 100644 index 0000000..94951cd --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressListener.java @@ -0,0 +1,52 @@ +/** + * + */ +package org.gcube.portlets.user.td.tablewidget.client.progress; + +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 TemplateApplyProgressListener { + + /** + * 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 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); + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressUpdater.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressUpdater.java new file mode 100644 index 0000000..aed9b9d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/TemplateApplyProgressUpdater.java @@ -0,0 +1,181 @@ +/** + * + */ +package org.gcube.portlets.user.td.tablewidget.client.progress; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor; +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 TemplateApplyProgressUpdater extends Timer { + + protected ArrayList listeners = new ArrayList(); + + /** + * {@inheritDoc} + */ + @Override + public void run() { + Log.debug("requesting operation progress"); + TDGWTServiceAsync.INSTANCE + .getTemplateApplyMonitor(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(TemplateApplyMonitor result) { + Log.info("retrieved TemplateApplyMonitor: " + + result.getStatus()); + switch (result.getStatus()) { + case INITIALIZING: + Log.info("Initializing..."); + fireOperationInitializing(); + break; + case ABORTED: + cancel(); + Log.info("Template Apply Operation Aborted"); + break; + case IN_PROGRESS: + fireOperationUpdate(result.getProgress()); + break; + case VALIDATING_RULES: + fireOperationUpdate(result.getProgress()); + break; + case STOPPED: + cancel(); + stopMessage(result); + break; + case FAILED: + cancel(); + errorMessage(result); + break; + case SUCCEDED: + cancel(); + Log.info("Fisnish TableId :" + + result.getTrId()); + fireOperationComplete(result.getTrId()); + break; + default: + Log.info("Unknow State"); + break; + } + + } + + + + }); + + } + + protected void errorMessage(TemplateApplyMonitor result) { + Log.info("Template Apply Failed"); + Throwable th = null; + String failure = null; + String details = null; + if (result.getError() != null) { + th = result.getError(); + failure = "Failed Client Library applying template"; + details = result.getError().getLocalizedMessage(); + } else { + th = new Throwable("Failed"); + failure = "Failed Client Library applying template"; + details = "Template Apply failed"; + } + + fireOperationFailed(th, failure, details); + } + + protected void stopMessage(TemplateApplyMonitor result) { + Log.info("Template Apply Stopped"); + String failure = null; + String details = null; + if (result.getError() != null) { + failure = "Stopped applying template"; + details = result.getError().getLocalizedMessage(); + } else { + failure = "Stopped applying template"; + details = "Apply template 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 (TemplateApplyProgressListener listener : listeners) + listener.operationInitializing(); + } + + protected void fireOperationUpdate(float elaborated) { + for (TemplateApplyProgressListener listener : listeners) + listener.operationUpdate(elaborated); + } + + protected void fireOperationComplete(TRId trId) { + for (TemplateApplyProgressListener listener : listeners) + listener.operationComplete(trId); + } + + protected void fireOperationFailed(Throwable caught, String failure, + String failureDetails) { + for (TemplateApplyProgressListener listener : listeners) + listener.operationFailed(caught, failure, failureDetails); + } + + protected void fireOperationStopped(TRId trId, String reason, String details) { + for (TemplateApplyProgressListener listener : listeners) + listener.operationStopped(trId,reason, details); + } + + + /** + * Add a new {@link TemplateApplyProgressListener} to this + * {@link TemplateApplyProgressUpdater}. + * + * @param listener + * the listener to add. + */ + public void addListener(TemplateApplyProgressListener listener) { + listeners.add(listener); + } + + /** + * Removes the specified {@link TemplateApplyProgressListener} from this + * {@link TemplateApplyProgressUpdater}. + * + * @param listener + * the listener to remove. + */ + public void removeListener(TemplateApplyProgressListener listener) { + listeners.remove(listener); + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/template/TemplateApplyPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/template/TemplateApplyPanel.java index b01c705..8e69a11 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/template/TemplateApplyPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/template/TemplateApplyPanel.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; import org.gcube.portlets.user.td.tablewidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3; @@ -220,11 +221,38 @@ public class TemplateApplyPanel extends FramedPanel { }); } - - + + + protected TemplateData getSelectedItem() { + return grid.getSelectionModel().getSelectedItem(); + } + + protected void apply(){ + TemplateApplySession applyTemplateSession=new TemplateApplySession(); + applyTemplateSession.setTemplateData(getSelectedItem()); + applyTemplateSession.setTrId(trId); + Log.debug("applyTemplateSession: "+applyTemplateSession); + TDGWTServiceAsync.INSTANCE.startTemplateApply(applyTemplateSession, + new AsyncCallback() { + public void onFailure(Throwable caught) { + Log.debug("Apply Template Error: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Apply Template Error ", + "Error in invocation of apply template operation!"); + + } + + public void onSuccess(Void result) { + /*TemplateApplyProgressDialog = new ChangeColumnTypeProgressDialog( + changeColumnTypeSession, eventBus);*/ + } + + }); + + } protected void close(){