From fd600be7007b98edfde22a0b548f1f1beee81199 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 2 Jul 2014 16:50:13 +0000 Subject: [PATCH] Updated Normalization git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@98326 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../normalization/NormalizationDialog.java | 71 +++++++ .../normalization/NormalizationPanel.java | 59 +++++- .../NormalizationProgressBarUpdater.java | 103 +++++++++ .../progress/NormalizationProgressDialog.java | 178 ++++++++++++++++ .../NormalizationProgressListener.java | 63 ++++++ .../NormalizationProgressUpdater.java | 195 ++++++++++++++++++ 6 files changed, 666 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressBarUpdater.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressListener.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressUpdater.java diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationDialog.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationDialog.java new file mode 100644 index 0000000..cb61446 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationDialog.java @@ -0,0 +1,71 @@ +package org.gcube.portlets.user.td.tablewidget.client.normalization; + +import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle; +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.widget.core.client.Window; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; + +/** + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public class NormalizationDialog extends Window { + protected String WIDTH = "650px"; + protected String HEIGHT = "530px"; + protected EventBus eventBus; + protected NormalizationPanel normalizationPanel; + protected TRId trId; + + public NormalizationDialog(TRId trId, EventBus eventBus) { + super(); + Log.debug("AddColumnDialog"); + this.eventBus = eventBus; + this.trId=trId; + initWindow(); + normalizationPanel = new NormalizationPanel(this, trId,eventBus); + add(normalizationPanel); + } + + protected void initWindow() { + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + + setClosable(true); + setModal(true); + forceLayoutOnResize = true; + getHeader().setIcon(ResourceBundle.INSTANCE.columnValue()); + setHeadingText("Normalization"); + } + + /** + * {@inheritDoc} + */ + @Override + protected void initTools() { + super.initTools(); + + closeBtn.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + close(); + } + }); + + } + + public void close() { + hide(); + + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationPanel.java index 844dafc..a5128ef 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/normalization/NormalizationPanel.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.td.tablewidget.client.normalization; import java.util.ArrayList; import java.util.List; +import org.gcube.portlets.user.td.columnwidget.client.progress.ProgressDialogListener; 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.tr.ColumnData; @@ -10,7 +11,10 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.Normalizati import org.gcube.portlets.user.td.tablewidget.client.progress.DuplicatesRowsProgressDialog; import org.gcube.portlets.user.td.tablewidget.client.properties.ColumnDataProperties; 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.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -46,7 +50,7 @@ import com.sencha.gxt.widget.core.client.grid.ColumnConfig; import com.sencha.gxt.widget.core.client.grid.ColumnModel; import com.sencha.gxt.widget.core.client.grid.Grid; -public class NormalizationPanel extends FramedPanel { +public class NormalizationPanel extends FramedPanel implements ProgressDialogListener { protected String WIDTH = "640px"; protected String HEIGHT = "520px"; @@ -64,14 +68,29 @@ public class NormalizationPanel extends FramedPanel { protected TextButton normalizeButton; protected TextField normalizedColumnName; protected TextField valueColumnName; + protected NormalizationDialog parent; + + public NormalizationPanel(NormalizationDialog parent,TRId trId, EventBus eventBus) { + this.parent=parent; + this.trId = trId; + this.eventBus = eventBus; + create(); + } + public NormalizationPanel(TRId trId, EventBus eventBus) { + this.trId = trId; + this.eventBus = eventBus; + this.parent=null; + create(); + } + + protected void create(){ + setWidth(WIDTH); setHeight(HEIGHT); setHeaderVisible(false); setBodyBorder(false); - this.trId = trId; - this.eventBus = eventBus; Log.debug("Create NormalizationPanel(): [" + trId.toString() + "]"); ColumnDataProperties props = GWT.create(ColumnDataProperties.class); @@ -241,4 +260,38 @@ public class NormalizationPanel extends FramedPanel { } + public void close() { + if (parent != null) { + parent.close(); + } + } + + + @Override + public void operationComplete(TRId trId) { + ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.ADDCOLUMN, trId, why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + + } + + @Override + public void operationFailed(Throwable caught, String reason) { + UtilsGXT3.alert("Error in Add Column", reason); + close(); + } + + @Override + public void operationStopped(TRId trId, String reason, String details) { + ChangeTableWhy why = ChangeTableWhy.TABLECURATION; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.ADDCOLUMN, trId, why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + } + + + } diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressBarUpdater.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressBarUpdater.java new file mode 100644 index 0000000..307f504 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressBarUpdater.java @@ -0,0 +1,103 @@ +/** + * + */ +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 NormalizationProgressBarUpdater implements + NormalizationProgressListener { + + protected ProgressBar progressBar; + + /** + * Creates a new {@link ProgressBar} updater. + * + * @param progressBar + * the {@link ProgressBar} to update. + */ + public NormalizationProgressBarUpdater(ProgressBar progressBar) { + this.progressBar = progressBar; + } + + /** + * {@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) + 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 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/tablewidget/client/progress/NormalizationProgressDialog.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressDialog.java new file mode 100644 index 0000000..8626d8f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressDialog.java @@ -0,0 +1,178 @@ +package org.gcube.portlets.user.td.tablewidget.client.progress; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.columnwidget.client.progress.ProgressDialogListener; +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; + +/** + * + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class NormalizationProgressDialog extends Window implements + NormalizationProgressListener { + 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 NormalizationProgressUpdater progressUpdater; + protected TextButton ok; + protected TRId trId; + private String reason; + + private String details; + + public NormalizationProgressDialog(EventBus eventBus) { + this.eventBus = eventBus; + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(true); + setModal(true); + setHeadingText("Normalization 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 NormalizationProgressUpdater(); + progressUpdater + .addListener(new NormalizationProgressBarUpdater(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/tablewidget/client/progress/NormalizationProgressListener.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressListener.java new file mode 100644 index 0000000..be4266e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressListener.java @@ -0,0 +1,63 @@ +/** + * + */ +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 NormalizationProgressListener { + + + /** + * 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/tablewidget/client/progress/NormalizationProgressUpdater.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressUpdater.java new file mode 100644 index 0000000..e633423 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/progress/NormalizationProgressUpdater.java @@ -0,0 +1,195 @@ +/** + * + */ +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.tr.normalization.NormalizationMonitor; +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 NormalizationProgressUpdater extends Timer { + + protected ArrayList listeners = new ArrayList(); + + /** + * {@inheritDoc} + */ + @Override + public void run() { + Log.debug("requesting operation progress"); + TDGWTServiceAsync.INSTANCE + .getNormalizationMonitor(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(NormalizationMonitor result) { + Log.info("retrieved NormalizationMonitor: " + + 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(NormalizationMonitor result) { + Log.info("Normalization Failed"); + Throwable th = null; + String failure = null; + String details = null; + if (result.getError() != null) { + th = result.getError(); + failure = "Failed Client Library Normalization"; + details = result.getError().getLocalizedMessage(); + } else { + th = new Throwable("Failed"); + failure = "Failed Client Library Normalization"; + details = "Normalization failed"; + } + + fireOperationFailed(th, failure, details); + } + + protected void stopMessage(NormalizationMonitor result) { + Log.info("Normalization Stopped"); + String failure = null; + String details = null; + if (result.getError() != null) { + failure = "Stopped normalization"; + details = result.getError().getLocalizedMessage(); + } else { + failure = "Stopped normalization"; + details = "Normalization 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 (NormalizationProgressListener listener : listeners) + listener.operationInitializing(); + } + + protected void fireOperationGeneratingView() { + for (NormalizationProgressListener listener : listeners) + listener.operationGeneratingView(); + } + + protected void fireOperationUpdate(float elaborated) { + for (NormalizationProgressListener listener : listeners) + listener.operationUpdate(elaborated); + } + + protected void fireOperationValidate(float elaborated) { + for (NormalizationProgressListener listener : listeners) + listener.operationValidate(elaborated); + } + + protected void fireOperationComplete(TRId trId) { + for (NormalizationProgressListener listener : listeners) + listener.operationComplete(trId); + } + + protected void fireOperationFailed(Throwable caught, String failure, + String failureDetails) { + for (NormalizationProgressListener listener : listeners) + listener.operationFailed(caught, failure, failureDetails); + } + + protected void fireOperationStopped(TRId trId, String reason, String details) { + for (NormalizationProgressListener listener : listeners) + listener.operationStopped(trId,reason, details); + } + + + /** + * Add a new {@link NormalizationProgressListener} to this + * {@link NormalizationProgressUpdater}. + * + * @param listener + * the listener to add. + */ + public void addListener(NormalizationProgressListener listener) { + listeners.add(listener); + } + + /** + * Removes the specified {@link NormalizationProgressListener} from this + * {@link NormalizationProgressUpdater}. + * + * @param listener + * the listener to remove. + */ + public void removeListener(NormalizationProgressListener listener) { + listeners.remove(listener); + } +}