Updated Export SDMX
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-sdmx-export-widget@86537 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
43eff8205a
commit
3cdde891c1
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.td.sdmxexportwidget.client.progress;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 SDMXExportProgressListener} events.
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SDMXExportProgressBarUpdater implements SDMXExportProgressListener {
|
||||||
|
|
||||||
|
protected ProgressBar progressBar;
|
||||||
|
//protected FramedPanel operationResult;
|
||||||
|
//protected WizardWindow wizardWindow;
|
||||||
|
/**
|
||||||
|
* Creates a new {@link ProgressBar} updater.
|
||||||
|
* @param progressBar the {@link ProgressBar} to update.
|
||||||
|
*/
|
||||||
|
public SDMXExportProgressBarUpdater(ProgressBar progressBar) {
|
||||||
|
this.progressBar = progressBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void operationComplete() {
|
||||||
|
Log.info("Export completed");
|
||||||
|
progressBar.updateProgress(1, "Export completed.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void operationFailed(Throwable caught, String reason, String failureDetails) {
|
||||||
|
Log.info("Export failed");
|
||||||
|
progressBar.updateText("Export failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void operationInitializing() {
|
||||||
|
Log.info("Export Inizializing");
|
||||||
|
progressBar.updateProgress(0, "Initializing...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void operationUpdate(float elaborated) {
|
||||||
|
Log.info("Export 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+"% Exporting...");
|
||||||
|
}
|
||||||
|
if (elaborated == 1) progressBar.updateProgress(1, "Completing...");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.td.sdmxexportwidget.client.progress;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a listener for operation progress.
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface SDMXExportProgressListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
|
@ -0,0 +1,165 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.td.sdmxexportwidget.client.progress;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
import com.google.gwt.user.client.Timer;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
||||||
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
||||||
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SDMXExportProgressUpdater extends Timer {
|
||||||
|
|
||||||
|
protected ArrayList<SDMXExportProgressListener> listeners = new ArrayList<SDMXExportProgressListener>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Log.debug("requesting operation progress");
|
||||||
|
TDGWTServiceAsync.INSTANCE
|
||||||
|
.getCSVExportMonitor(new AsyncCallback<CSVExportMonitor>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(CSVExportMonitor result) {
|
||||||
|
Log.info("retrieved CSVImportMonitor: "
|
||||||
|
+ result.getStatus());
|
||||||
|
switch (result.getStatus()) {
|
||||||
|
case INITIALIZING:
|
||||||
|
Log.info("CSV Export Initializing...");
|
||||||
|
fireOperationInitializing();
|
||||||
|
break;
|
||||||
|
case ABORTED:
|
||||||
|
cancel();
|
||||||
|
Log.info("CSV Export Operation Aborted");
|
||||||
|
break;
|
||||||
|
case IN_PROGRESS:
|
||||||
|
fireOperationUpdate(result.getProgress());
|
||||||
|
break;
|
||||||
|
case FAILED:
|
||||||
|
cancel();
|
||||||
|
errorMessage(result);
|
||||||
|
break;
|
||||||
|
case SUCCEDED:
|
||||||
|
cancel();
|
||||||
|
Log.info("Export fisnish ExportMetadata:"
|
||||||
|
+ result.getTrExportMetadata());
|
||||||
|
fireOperationComplete();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Log.info("Unknow State");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void errorMessage(CSVExportMonitor result) {
|
||||||
|
Log.info("CSV Export Failed");
|
||||||
|
Throwable th = null;
|
||||||
|
String failure = null;
|
||||||
|
String details = null;
|
||||||
|
if (result.getError() != null) {
|
||||||
|
th = result.getError();
|
||||||
|
failure = "Failed Client Library Export";
|
||||||
|
details = result.getError().getLocalizedMessage();
|
||||||
|
} else {
|
||||||
|
th = new Throwable("Failed");
|
||||||
|
failure = "Failed Client Library Export";
|
||||||
|
details = "Error in export";
|
||||||
|
}
|
||||||
|
fireOperationFailed(th, failure, details);
|
||||||
|
|
||||||
|
AlertMessageBox d = new AlertMessageBox("Error in CSV Export", details);
|
||||||
|
d.addHideHandler(new HideHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHide(HideEvent event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getStack(Throwable e) {
|
||||||
|
String message = e.getLocalizedMessage() + " -> <br>";
|
||||||
|
Throwable c = e.getCause();
|
||||||
|
if (c != null)
|
||||||
|
message += getStack(c);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireOperationInitializing() {
|
||||||
|
for (SDMXExportProgressListener listener : listeners)
|
||||||
|
listener.operationInitializing();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireOperationUpdate(float elaborated) {
|
||||||
|
for (SDMXExportProgressListener listener : listeners)
|
||||||
|
listener.operationUpdate(elaborated);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireOperationComplete() {
|
||||||
|
for (SDMXExportProgressListener listener : listeners)
|
||||||
|
listener.operationComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireOperationFailed(Throwable caught, String failure,
|
||||||
|
String failureDetails) {
|
||||||
|
for (SDMXExportProgressListener listener : listeners)
|
||||||
|
listener.operationFailed(caught, failure, failureDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new {@link SDMXExportProgressListener} to this
|
||||||
|
* {@link SDMXExportProgressUpdater}.
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener to add.
|
||||||
|
*/
|
||||||
|
public void addListener(SDMXExportProgressListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the specified {@link SDMXExportProgressListener} from this
|
||||||
|
* {@link SDMXExportProgressUpdater}.
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener to remove.
|
||||||
|
*/
|
||||||
|
public void removeListener(SDMXExportProgressListener listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue