Updated on stop of the tasks

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@92511 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-02-28 15:54:56 +00:00
parent 6660c42fd3
commit 033abe9f58
5 changed files with 83 additions and 16 deletions

View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-csv-import-widget</artifactId> <artifactId>tabular-data-csv-import-widget</artifactId>
<version>2.0.0-SNAPSHOT</version> <version>2.0.1-SNAPSHOT</version>
<name>tabular-data-csv-import-widget</name> <name>tabular-data-csv-import-widget</name>
<description>tabular-data-csv-import-widget allows csv import from file and workspace</description> <description>tabular-data-csv-import-widget allows csv import from file and workspace</description>

View File

@ -35,7 +35,7 @@ import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
* *
*/ */
public class CSVOperationInProgressCard extends WizardCard implements public class CSVOperationInProgressCard extends WizardCard implements
CSVImportProgressListener { CSVImportProgressListener {
public static final int STATUS_POLLING_DELAY = 1000; public static final int STATUS_POLLING_DELAY = 1000;
protected CSVOperationInProgressCard thisCard; protected CSVOperationInProgressCard thisCard;
@ -52,7 +52,7 @@ CSVImportProgressListener {
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER); operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
final FlexTable description = new FlexTable(); final FlexTable description = new FlexTable();
//FlexCellFormatter cellFormatter = description.getFlexCellFormatter(); // FlexCellFormatter cellFormatter = description.getFlexCellFormatter();
description.setCellSpacing(10); description.setCellSpacing(10);
description.setCellPadding(4); description.setCellPadding(4);
description.setBorderWidth(0); description.setBorderWidth(0);
@ -69,7 +69,6 @@ CSVImportProgressListener {
"<span style=\"font-weight:bold;\";>File: </span>"); "<span style=\"font-weight:bold;\";>File: </span>");
description.setText(2, 1, importSession.getTabResource().getName()); description.setText(2, 1, importSession.getTabResource().getName());
FramedPanel summary = new FramedPanel(); FramedPanel summary = new FramedPanel();
summary.setHeadingText("Import Summary"); summary.setHeadingText("Import Summary");
summary.setWidth(400); summary.setWidth(400);
@ -82,26 +81,31 @@ CSVImportProgressListener {
new Margins(10, 5, 10, 5))); new Margins(10, 5, 10, 5)));
progressUpdater = new CSVImportProgressUpdater(); progressUpdater = new CSVImportProgressUpdater();
progressUpdater.addListener(new CSVImportProgressBarUpdater(progressBar)); progressUpdater
.addListener(new CSVImportProgressBarUpdater(progressBar));
progressUpdater.addListener(this); progressUpdater.addListener(this);
setContent(operationInProgressPanel); setContent(operationInProgressPanel);
} }
//columnToImportMask
// columnToImportMask
public void importCSV() { public void importCSV() {
TDGWTServiceAsync.INSTANCE.startCSVImport(importSession, new AsyncCallback<Void>() { TDGWTServiceAsync.INSTANCE.startCSVImport(importSession,
new AsyncCallback<Void>() {
public void onSuccess(Void result) { public void onSuccess(Void result) {
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY); progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
} }
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
showErrorAndHide("Error in importCSV", showErrorAndHide(
"An error occured in importCSV: "+caught.getLocalizedMessage(), caught.getStackTrace().toString(), caught); "Error in importCSV",
"An error occured in importCSV: "
+ caught.getLocalizedMessage(), caught
.getStackTrace().toString(), caught);
} }
}); });
} }
@ -116,7 +120,6 @@ CSVImportProgressListener {
importCSV(); importCSV();
} }
public void operationInitializing() { public void operationInitializing() {
} }
@ -149,7 +152,6 @@ CSVImportProgressListener {
getWizardWindow().setEnableNextButton(true); getWizardWindow().setEnableNextButton(true);
} }
public void operationFailed(Throwable caught, String reason, public void operationFailed(Throwable caught, String reason,
String failureDetails) { String failureDetails) {
AlertMessageBox d = new AlertMessageBox("Error in CSV Import", reason); AlertMessageBox d = new AlertMessageBox("Error in CSV Import", reason);
@ -160,4 +162,30 @@ CSVImportProgressListener {
d.show(); d.show();
} }
@Override
public void operationStopped(final TRId trId, String reason, String details) {
// final String tableId,final String tableResourceId) {
Command sayComplete = new Command() {
public void execute() {
try {
getWizardWindow().close(false);
Log.info("fire Complete: tabular resource " + trId.getId());
Log.info("fire Complete: tableId " + trId.getTableId());
getWizardWindow().fireCompleted(trId);
} catch (Exception e) {
Log.error("fire Complete :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setNextButtonCommand(sayComplete);
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
}
} }

View File

@ -35,6 +35,7 @@ public class CSVImportProgressBarUpdater implements CSVImportProgressListener {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void operationComplete(TRId trId) { public void operationComplete(TRId trId) {
Log.info("Import completed"); Log.info("Import completed");
progressBar.updateProgress(1, "Import completed."); progressBar.updateProgress(1, "Import completed.");
@ -44,16 +45,19 @@ public class CSVImportProgressBarUpdater implements CSVImportProgressListener {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void operationFailed(Throwable caught, String reason, String failureDetails) { public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("Import failed"); Log.info("Import failed");
progressBar.updateText("Import failed."); progressBar.updateText("Import failed.");
} }
@Override
public void operationInitializing() { public void operationInitializing() {
Log.info("Inport Inizializing"); Log.info("Inport Inizializing");
progressBar.updateProgress(0, "Initializing..."); progressBar.updateProgress(0, "Initializing...");
} }
@Override
public void operationUpdate(float elaborated) { public void operationUpdate(float elaborated) {
Log.info("Import elaborated: "+elaborated); Log.info("Import elaborated: "+elaborated);
if (elaborated == 0) progressBar.updateProgress(0, "Initializing..."); if (elaborated == 0) progressBar.updateProgress(0, "Initializing...");
@ -65,5 +69,13 @@ public class CSVImportProgressBarUpdater implements CSVImportProgressListener {
if (elaborated == 1) progressBar.updateProgress(1, "Completing..."); 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");
}
} }

View File

@ -39,4 +39,14 @@ public interface CSVImportProgressListener {
* @param reason the failure reason. * @param reason the failure reason.
*/ */
public void operationFailed(Throwable caught, String reason, String failureDetails); 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);
} }

View File

@ -12,9 +12,6 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback; 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;
/** /**
* This {@link Timer} retrieves {@link OperationProgress} from the specified * This {@link Timer} retrieves {@link OperationProgress} from the specified
@ -68,7 +65,7 @@ public class CSVImportProgressUpdater extends Timer {
break; break;
case STOPPED: case STOPPED:
cancel(); cancel();
errorMessage(result); stopMessage(result);
break; break;
case FAILED: case FAILED:
cancel(); cancel();
@ -108,6 +105,21 @@ public class CSVImportProgressUpdater extends Timer {
fireOperationFailed(th, failure, details); fireOperationFailed(th, failure, details);
} }
protected void stopMessage(CSVImportMonitor result) {
Log.info("CSV Import Stopped");
String failure = null;
String details = null;
if (result.getError() != null) {
failure = "Stopped";
details = result.getError().getLocalizedMessage();
} else {
failure = "Stopped";
details = "Stopped import CSV";
}
fireOperationStopped(result.getTrId(),failure, details);
}
protected String getStack(Throwable e) { protected String getStack(Throwable e) {
String message = e.getLocalizedMessage() + " -> <br>"; String message = e.getLocalizedMessage() + " -> <br>";
@ -137,6 +149,11 @@ public class CSVImportProgressUpdater extends Timer {
for (CSVImportProgressListener listener : listeners) for (CSVImportProgressListener listener : listeners)
listener.operationFailed(caught, failure, failureDetails); listener.operationFailed(caught, failure, failureDetails);
} }
protected void fireOperationStopped(TRId trId, String reason, String details) {
for (CSVImportProgressListener listener : listeners)
listener.operationStopped(trId,reason, details);
}
/** /**
* Add a new {@link CSVImportProgressListener} to this * Add a new {@link CSVImportProgressListener} to this