Minor updated
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-sdmx-import-widget@84885 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f40992a719
commit
8329a4061a
|
@ -21,16 +21,13 @@ import com.sencha.gxt.widget.core.client.ProgressBar;
|
|||
public class ImportProgressBarUpdater implements OperationProgressListener {
|
||||
|
||||
protected ProgressBar progressBar;
|
||||
//protected FramedPanel operationResult;
|
||||
//protected WizardWindow wizardWindow;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ProgressBar} updater.
|
||||
* @param progressBar the {@link ProgressBar} to update.
|
||||
*/
|
||||
public ImportProgressBarUpdater(ProgressBar progressBar) {
|
||||
this.progressBar = progressBar;
|
||||
//this.wizardWindow = w;
|
||||
//this.operationResult = operationResult;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,21 +35,9 @@ public class ImportProgressBarUpdater implements OperationProgressListener {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void operationComplete(TRId trId) {// TODO Auto-generated method stub
|
||||
public void operationComplete(TRId trId) {
|
||||
Log.info("Import complete");
|
||||
progressBar.updateProgress(1, "Import complete.");
|
||||
/*final FlexTable descriptionResult = new FlexTable();
|
||||
descriptionResult.setCellSpacing(10);
|
||||
descriptionResult.setCellPadding(4);
|
||||
descriptionResult.setBorderWidth(0);
|
||||
descriptionResult.setText(0, 0, "Result: ");
|
||||
descriptionResult.setText(0, 1, "Import complete");
|
||||
|
||||
operationResult.add(descriptionResult);
|
||||
operationResult.setVisible(true);
|
||||
*/
|
||||
//wizardWindow.setEnableNextButton(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -68,19 +53,19 @@ public class ImportProgressBarUpdater implements OperationProgressListener {
|
|||
@Override
|
||||
public void operationInitializing() {
|
||||
Log.info("Inport inizializing");
|
||||
progressBar.updateProgress(0, "initializing...");
|
||||
progressBar.updateProgress(0, "Initializing...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationUpdate(float elaborated) {
|
||||
Log.info("Import elaborated: "+elaborated);
|
||||
if (elaborated == 0) progressBar.updateProgress(0, "initializing...");
|
||||
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+"% importing...");
|
||||
progressBar.updateProgress(elaborated,elab+"% Importing...");
|
||||
}
|
||||
if (elaborated == 1) progressBar.updateProgress(1, "completing...");
|
||||
if (elaborated == 1) progressBar.updateProgress(1, "Completed");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,29 +5,28 @@ package org.gcube.portlets.user.td.sdmximportwidget.client.progress;
|
|||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Defines a listener for operation progress.
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public interface OperationProgressListener {
|
||||
|
||||
|
||||
/**
|
||||
* Called when the operation is starting.
|
||||
*/
|
||||
public void operationInitializing();
|
||||
|
||||
|
||||
/**
|
||||
* Called when there is a progress for the operation.
|
||||
* @param elaborated the elaborated part.
|
||||
*
|
||||
* @param elaborated
|
||||
* the elaborated part.
|
||||
*/
|
||||
public void operationUpdate(float elaborated);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when the operation is complete.
|
||||
*/
|
||||
|
@ -35,8 +34,12 @@ public interface OperationProgressListener {
|
|||
|
||||
/**
|
||||
* Called when the operation is failed.
|
||||
* @param caught the failure exception.
|
||||
* @param reason the failure reason.
|
||||
*
|
||||
* @param caught
|
||||
* the failure exception.
|
||||
* @param reason
|
||||
* the failure reason.
|
||||
*/
|
||||
public void operationFailed(Throwable caught, String reason, String failureDetails);
|
||||
public void operationFailed(Throwable caught, String reason,
|
||||
String failureDetails);
|
||||
}
|
||||
|
|
|
@ -9,124 +9,129 @@ import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportMonitor;
|
||||
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
/**
|
||||
* This {@link Timer} retrieves {@link OperationProgress} from the specified {@link OperationProgressSource} with the scheduled interval.
|
||||
* The retrieved information are spread to the subscribed {@link OperationProgressListener}.
|
||||
* This {@link Timer} retrieves {@link OperationProgress} from the specified
|
||||
* {@link OperationProgressSource} with the scheduled interval. The retrieved
|
||||
* information are spread to the subscribed {@link OperationProgressListener}.
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class OperationProgressUpdater extends Timer {
|
||||
|
||||
protected ArrayList<OperationProgressListener> listeners = new ArrayList<OperationProgressListener>();
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("requesting operation progress");
|
||||
TDGWTServiceAsync.INSTANCE.getSDMXImportMonitor(new AsyncCallback<SDMXImportMonitor>() {
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getSDMXImportMonitor(new AsyncCallback<SDMXImportMonitor>() {
|
||||
|
||||
@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(SDMXImportMonitor result) {
|
||||
Log.info("retrieved ImportMonitor: "
|
||||
+ result.getStatus());
|
||||
switch (result.getStatus()) {
|
||||
case INITIALIZING:
|
||||
Log.info("Initializing...");
|
||||
fireOperationInitializing();
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
fireOperationUpdate(result.getProgress());
|
||||
break;
|
||||
case FAILED:
|
||||
cancel();
|
||||
Log.info("Import SDMX Failed");
|
||||
fireOperationFailed(result.getError(),
|
||||
"Failed Client Library Import",
|
||||
result.getStatusDescription());
|
||||
break;
|
||||
case SUCCEDED:
|
||||
cancel();
|
||||
Log.info("Import fisnish TableId :"
|
||||
+ result.getTrId());
|
||||
fireOperationComplete(result.getTrId());
|
||||
break;
|
||||
case ABORTED:
|
||||
Log.info("Import SDMX Aborted");
|
||||
cancel();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@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(SDMXImportMonitor result) {
|
||||
Log.info("retrieved ImportMonitor: "+result.getStatus());
|
||||
switch (result.getStatus()) {
|
||||
case INITIALIZING:
|
||||
Log.info("Initializing...");
|
||||
fireOperationInitializing();
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
fireOperationUpdate(result.getProgress());
|
||||
break;
|
||||
case FAILED:
|
||||
cancel();
|
||||
Log.info("Import SDMX Failed");
|
||||
fireOperationFailed(result.getError(),"Failed Client Library Import", result.getStatusDescription());
|
||||
break;
|
||||
case SUCCEDED:
|
||||
cancel();
|
||||
Log.info("Import fisnish TableId :"+result.getTrId());
|
||||
fireOperationComplete(result.getTrId());
|
||||
break;
|
||||
case ABORTED:
|
||||
Log.info("Import SDMX Aborted");
|
||||
cancel();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected String getStack(Throwable e)
|
||||
{
|
||||
String message = e.getLocalizedMessage()+" -> <br>";
|
||||
|
||||
protected String getStack(Throwable e) {
|
||||
String message = e.getLocalizedMessage() + " -> <br>";
|
||||
Throwable c = e.getCause();
|
||||
if (c!=null) message += getStack(c);
|
||||
if (c != null)
|
||||
message += getStack(c);
|
||||
return message;
|
||||
}
|
||||
|
||||
protected void fireOperationInitializing()
|
||||
{
|
||||
for (OperationProgressListener listener:listeners) listener.operationInitializing();
|
||||
}
|
||||
|
||||
protected void fireOperationUpdate(float elaborated)
|
||||
{
|
||||
for (OperationProgressListener listener:listeners) listener.operationUpdate(elaborated);
|
||||
protected void fireOperationInitializing() {
|
||||
for (OperationProgressListener listener : listeners)
|
||||
listener.operationInitializing();
|
||||
}
|
||||
|
||||
protected void fireOperationComplete(TRId trId)
|
||||
{
|
||||
for (OperationProgressListener listener:listeners) listener.operationComplete(trId);
|
||||
protected void fireOperationUpdate(float elaborated) {
|
||||
for (OperationProgressListener listener : listeners)
|
||||
listener.operationUpdate(elaborated);
|
||||
}
|
||||
|
||||
protected void fireOperationFailed(Throwable caught, String failure, String failureDetails)
|
||||
{
|
||||
for (OperationProgressListener listener:listeners) listener.operationFailed(caught, failure, failureDetails);
|
||||
|
||||
protected void fireOperationComplete(TRId trId) {
|
||||
for (OperationProgressListener listener : listeners)
|
||||
listener.operationComplete(trId);
|
||||
}
|
||||
|
||||
|
||||
protected void fireOperationFailed(Throwable caught, String failure,
|
||||
String failureDetails) {
|
||||
for (OperationProgressListener listener : listeners)
|
||||
listener.operationFailed(caught, failure, failureDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new {@link OperationProgressListener} to this {@link OperationProgressUpdater}.
|
||||
* @param listener the listener to add.
|
||||
* Add a new {@link OperationProgressListener} to this
|
||||
* {@link OperationProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to add.
|
||||
*/
|
||||
public void addListener(OperationProgressListener listener)
|
||||
{
|
||||
public void addListener(OperationProgressListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified {@link OperationProgressListener} from this {@link OperationProgressUpdater}.
|
||||
* @param listener the listener to remove.
|
||||
* Removes the specified {@link OperationProgressListener} from this
|
||||
* {@link OperationProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to remove.
|
||||
*/
|
||||
public void removeListener(OperationProgressListener listener)
|
||||
{
|
||||
public void removeListener(OperationProgressListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue