From d7da7f3cb985ca2d77f72a62716f680da1be7e6a Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 26 Aug 2014 14:19:54 +0000 Subject: [PATCH] Minor Update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-extractcodelist-widget@99286 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.validation.prefs | 2 + pom.xml | 11 +- ...xtractCodelistOperationInProgressCard.java | 121 ++++++----- .../ExtractCodelistProgressBarUpdater.java | 98 --------- .../ExtractCodelistProgressListener.java | 63 ------ .../ExtractCodelistProgressUpdater.java | 192 ------------------ .../ExtractCodelistWizardTD.gwt.xml | 3 +- 7 files changed, 84 insertions(+), 406 deletions(-) create mode 100644 .settings/org.eclipse.wst.validation.prefs delete mode 100644 src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressBarUpdater.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressListener.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressUpdater.java diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/pom.xml b/pom.xml index c96a884..b3b4893 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,16 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided - + + + + org.gcube.portlets.user + tabular-data-monitor-widget + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + provided + + + org.gcube.portlets.user diff --git a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistOperationInProgressCard.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistOperationInProgressCard.java index c5a5b6a..793d596 100644 --- a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistOperationInProgressCard.java +++ b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistOperationInProgressCard.java @@ -3,12 +3,14 @@ */ package org.gcube.portlets.user.td.extractcodelistwidget.client; -import org.gcube.portlets.user.td.extractcodelistwidget.client.progress.ExtractCodelistProgressBarUpdater; -import org.gcube.portlets.user.td.extractcodelistwidget.client.progress.ExtractCodelistProgressListener; -import org.gcube.portlets.user.td.extractcodelistwidget.client.progress.ExtractCodelistProgressUpdater; 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.widgetcommonevent.client.event.SessionExpiredEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -34,67 +36,70 @@ import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it * */ -public class ExtractCodelistOperationInProgressCard extends WizardCard implements - ExtractCodelistProgressListener { +public class ExtractCodelistOperationInProgressCard extends WizardCard + implements MonitorUpdaterListener { public static final int STATUS_POLLING_DELAY = 1000; protected ExtractCodelistOperationInProgressCard thisCard; protected ExtractCodelistSession extractCodelistSession; - protected ExtractCodelistProgressUpdater progressUpdater; + protected MonitorUpdater progressUpdater; + protected ProgressBar progressBar; + protected final FlexTable description; protected final FramedPanel summary; - protected final ProgressBar progressBar; - public ExtractCodelistOperationInProgressCard(final ExtractCodelistSession extractCodelistSession) { + + public ExtractCodelistOperationInProgressCard( + final ExtractCodelistSession extractCodelistSession) { super("Operation In Progress", ""); - this.extractCodelistSession = extractCodelistSession; + this.extractCodelistSession = extractCodelistSession; thisCard = this; VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer(); operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER); - + progressBar = new ProgressBar(); operationInProgressPanel.add(progressBar, new BoxLayoutData( new Margins(10, 30, 10, 5))); - progressUpdater = new ExtractCodelistProgressUpdater(); - progressUpdater - .addListener(new ExtractCodelistProgressBarUpdater(progressBar)); - - progressUpdater.addListener(this); - - - 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"); - + 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(summary, new BoxLayoutData(new Margins(20, + 5, 10, 5))); + setContent(operationInProgressPanel); summary.setVisible(false); } - - public void extractCodelist() { TDGWTServiceAsync.INSTANCE.startExtractCodelist(extractCodelistSession, - new AsyncCallback() { + new AsyncCallback() { - public void onSuccess(Void result) { + 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); + } public void onFailure(Throwable caught) { @@ -104,8 +109,7 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { - showErrorAndHide( - "Error in extract codelist", + showErrorAndHide("Error in extract codelist", "An error occured in extract codelist: " + caught.getLocalizedMessage(), caught.getStackTrace().toString(), caught); @@ -124,25 +128,28 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement extractCodelist(); } - public void operationInitializing() { - - } - - public void operationUpdate(float elaborated) { - - } - @Override - public void operationComplete(final TRId trId) { + public void monitorInitializing(OperationMonitor operationMonitor) { + + } + + @Override + public void monitorUpdate(OperationMonitor operationMonitor) { + + } + + @Override + public void monitorComplete(final TRId trId) { summary.setVisible(true); progressBar.setVisible(false); forceLayout(); - + Command sayComplete = new Command() { public void execute() { try { getWizardWindow().close(false); - Log.info("fire Complete: tableId"); + Log.info("fire Complete: " + trId); + getWizardWindow().fireCompleted(trId); } catch (Exception e) { @@ -157,7 +164,8 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement getWizardWindow().setEnableNextButton(true); } - public void operationFailed(Throwable caught, String reason, + @Override + public void monitorFailed(Throwable caught, String reason, String failureDetails) { if (caught instanceof TDGWTSessionExpiredException) { getEventBus() @@ -165,9 +173,8 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { - - AlertMessageBox d = new AlertMessageBox("Error in Extract Codelist", - reason); + AlertMessageBox d = new AlertMessageBox( + "Error in Codelist Mapping Import", reason); d.addHideHandler(new HideHandler() { public void onHide(HideEvent event) { } @@ -177,16 +184,16 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement } @Override - public void operationStopped(TRId trId, String reason, String details) { - + public void monitorStopped(final TRId trId, String reason, String details) { Command sayComplete = new Command() { public void execute() { try { getWizardWindow().close(false); - Log.info("fire Complete: tableId"); + Log.info("fire Complete: tabular resource " + trId.getId()); + Log.info("fire Complete: tableId " + trId.getTableId()); - getWizardWindow().fireCompleted(null); + getWizardWindow().fireCompleted(trId); } catch (Exception e) { Log.error("fire Complete :" + e.getLocalizedMessage()); @@ -202,13 +209,25 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard implement } @Override - public void operationGeneratingView() { + public void monitorGeneratingView(OperationMonitor operationMonitor) { // TODO Auto-generated method stub } @Override - public void operationValidate(float elaborated) { + public void monitorValidate(OperationMonitor operationMonitor) { + // TODO Auto-generated method stub + + } + + @Override + public void monitorAborted() { + // TODO Auto-generated method stub + + } + + @Override + public void monitorPutInBackground() { // TODO Auto-generated method stub } diff --git a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressBarUpdater.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressBarUpdater.java deleted file mode 100644 index 603fcfb..0000000 --- a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressBarUpdater.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.td.extractcodelistwidget.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; - -/** - * Updates a {@link ProgressBar} progress and text based on {@link ExtractCodelistProgressListener} events. - * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * - */ -public class ExtractCodelistProgressBarUpdater implements ExtractCodelistProgressListener { - - protected ProgressBar progressBar; - //protected FramedPanel operationResult; - //protected WizardWindow wizardWindow; - /** - * Creates a new {@link ProgressBar} updater. - * @param progressBar the {@link ProgressBar} to update. - */ - public ExtractCodelistProgressBarUpdater(ProgressBar progressBar) { - this.progressBar = progressBar; - this.progressBar.updateProgress(0, "Please Wait..."); - } - - - /** - * {@inheritDoc} - */ - @Override - public void operationComplete(TRId trId) { - Log.info("Completed "+trId.toString()); - 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("Export 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/extractcodelistwidget/client/progress/ExtractCodelistProgressListener.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressListener.java deleted file mode 100644 index d591e7f..0000000 --- a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressListener.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.td.extractcodelistwidget.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 ExtractCodelistProgressListener { - - /** - * 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/extractcodelistwidget/client/progress/ExtractCodelistProgressUpdater.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressUpdater.java deleted file mode 100644 index 87a2819..0000000 --- a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/progress/ExtractCodelistProgressUpdater.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.td.extractcodelistwidget.client.progress; - -import java.util.ArrayList; - -import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; -import org.gcube.portlets.user.td.gwtservice.shared.monitor.ExtractCodelistMonitor; -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 ExtractCodelistProgressUpdater extends Timer { - - protected ArrayList listeners = new ArrayList(); - - /** - * {@inheritDoc} - */ - @Override - public void run() { - Log.debug("requesting operation progress"); - TDGWTServiceAsync.INSTANCE - .getExtractCodelistMonitor(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(ExtractCodelistMonitor result) { - Log.info("retrieved Monitor: " - + result.getStatus()); - switch (result.getStatus()) { - case INITIALIZING: - Log.info("Initializing..."); - fireOperationInitializing(); - break; - case ABORTED: - cancel(); - Log.info("Operation 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 FAILED: - cancel(); - errorMessage(result); - break; - case STOPPED: - cancel(); - stopMessage(result); - break; - case SUCCEDED: - cancel(); - Log.info("Finish:" - + result.toString()); - fireOperationComplete(result.getTrId()); - break; - default: - Log.info("Unknow State"); - break; - } - - } - - }); - - } - - protected void errorMessage(ExtractCodelistMonitor result) { - Log.info("Extract Codelist Failed"); - Throwable th = null; - String failure = null; - String details = null; - if (result.getError() != null) { - th = result.getError(); - failure = "Failed Client Library Extract Codelist"; - details = result.getError().getLocalizedMessage(); - } else { - th = new Throwable("Failed"); - failure = "Failed Client Library Extract Codelist"; - details = "Error in export"; - } - - fireOperationFailed(th, failure, details); - } - - - protected void stopMessage(ExtractCodelistMonitor result) { - Log.info("Extract Codelist Stopped"); - String failure = null; - String details = null; - if (result.getError() != null) { - failure = "Stopped extract codelist"; - details = result.getError().getLocalizedMessage(); - } else { - failure = "Stopped extract codelist"; - details = "Stopped extract codelist"; - } - - 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 (ExtractCodelistProgressListener listener : listeners) - listener.operationInitializing(); - } - - protected void fireOperationGeneratingView() { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationGeneratingView(); - } - - protected void fireOperationUpdate(float elaborated) { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationUpdate(elaborated); - } - - protected void fireOperationValidate(float elaborated) { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationValidate(elaborated); - } - - protected void fireOperationComplete(TRId trId) { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationComplete(trId); - } - - protected void fireOperationFailed(Throwable caught, String failure, - String failureDetails) { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationFailed(caught, failure, failureDetails); - } - - protected void fireOperationStopped(TRId trId, String reason, String details) { - for (ExtractCodelistProgressListener listener : listeners) - listener.operationStopped(trId,reason, details); - } - - /** - * Add a new {@link ExtractCodelistProgressListener} to this - * {@link ExtractCodelistProgressUpdater}. - * - * @param listener - * the listener to add. - */ - public void addListener(ExtractCodelistProgressListener listener) { - listeners.add(listener); - } - - /** - * Removes the specified {@link ExtractCodelistProgressListener} from this - * {@link ExtractCodelistProgressUpdater}. - * - * @param listener - * the listener to remove. - */ - public void removeListener(ExtractCodelistProgressListener listener) { - listeners.remove(listener); - } -} diff --git a/src/main/resources/org/gcube/portlets/user/td/extractcodelistwidget/ExtractCodelistWizardTD.gwt.xml b/src/main/resources/org/gcube/portlets/user/td/extractcodelistwidget/ExtractCodelistWizardTD.gwt.xml index 4bac994..58e4c43 100644 --- a/src/main/resources/org/gcube/portlets/user/td/extractcodelistwidget/ExtractCodelistWizardTD.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/td/extractcodelistwidget/ExtractCodelistWizardTD.gwt.xml @@ -20,7 +20,8 @@ - + +