2013-12-02 17:45:23 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.td.csvexportwidget.client;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.td.csvexportwidget.client.progress.CSVExportProgressBarUpdater;
|
|
|
|
import org.gcube.portlets.user.td.csvexportwidget.client.progress.CSVExportProgressListener;
|
|
|
|
import org.gcube.portlets.user.td.csvexportwidget.client.progress.CSVExportProgressUpdater;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
2014-02-28 16:22:22 +01:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
2013-12-02 17:45:23 +01:00
|
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.user.client.Command;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
|
|
|
import com.sencha.gxt.widget.core.client.ProgressBar;
|
2014-02-11 14:59:13 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
2013-12-02 17:45:23 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayoutAlign;
|
2014-02-11 14:59:13 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
2013-12-02 17:45:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi" <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CSVOperationInProgressCard extends WizardCard implements
|
2014-02-28 16:22:22 +01:00
|
|
|
CSVExportProgressListener {
|
2013-12-02 17:45:23 +01:00
|
|
|
|
|
|
|
public static final int STATUS_POLLING_DELAY = 1000;
|
|
|
|
protected CSVOperationInProgressCard thisCard;
|
|
|
|
protected CSVExportSession exportSession;
|
|
|
|
protected CSVExportProgressUpdater progressUpdater;
|
|
|
|
|
|
|
|
public CSVOperationInProgressCard(final CSVExportSession exportSession) {
|
|
|
|
super("Operation In Progress", "");
|
|
|
|
|
|
|
|
this.exportSession = exportSession;
|
|
|
|
thisCard = this;
|
|
|
|
|
|
|
|
VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer();
|
|
|
|
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
|
|
|
|
|
|
|
|
final FlexTable description = new FlexTable();
|
2014-02-28 16:22:22 +01:00
|
|
|
// FlexCellFormatter cellFormatter = description.getFlexCellFormatter();
|
2013-12-02 17:45:23 +01:00
|
|
|
description.setCellSpacing(10);
|
|
|
|
description.setCellPadding(4);
|
|
|
|
description.setBorderWidth(0);
|
|
|
|
|
|
|
|
// display:block;vertical-align:text-top;
|
|
|
|
description.setHTML(0, 0,
|
|
|
|
"<span style=\"font-weight:bold;\";>Destination: </span>");
|
|
|
|
description.setText(0, 1, exportSession.getDestination().getName());
|
|
|
|
description.setHTML(1, 0,
|
|
|
|
"<span style=\"font-weight:bold;\";>File Name: </span>");
|
|
|
|
description.setText(1, 1, exportSession.getFileName());
|
|
|
|
|
|
|
|
description.setHTML(2, 0,
|
|
|
|
"<span style=\"font-weight:bold;\";>File Description: </span>");
|
|
|
|
description.setText(2, 1, exportSession.getFileDescription());
|
|
|
|
|
|
|
|
FramedPanel summary = new FramedPanel();
|
|
|
|
summary.setHeadingText("Export Summary");
|
|
|
|
summary.setWidth(400);
|
|
|
|
summary.add(description);
|
|
|
|
operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20,
|
|
|
|
5, 10, 5)));
|
|
|
|
|
|
|
|
ProgressBar progressBar = new ProgressBar();
|
|
|
|
operationInProgressPanel.add(progressBar, new BoxLayoutData(
|
|
|
|
new Margins(10, 5, 10, 5)));
|
|
|
|
|
|
|
|
progressUpdater = new CSVExportProgressUpdater();
|
2014-02-28 16:22:22 +01:00
|
|
|
progressUpdater
|
|
|
|
.addListener(new CSVExportProgressBarUpdater(progressBar));
|
2013-12-02 17:45:23 +01:00
|
|
|
|
|
|
|
progressUpdater.addListener(this);
|
|
|
|
|
|
|
|
setContent(operationInProgressPanel);
|
|
|
|
|
|
|
|
}
|
2014-02-28 16:22:22 +01:00
|
|
|
|
|
|
|
// columnToImportMask
|
2013-12-02 17:45:23 +01:00
|
|
|
|
|
|
|
public void exportCSV() {
|
2014-02-28 16:22:22 +01:00
|
|
|
TDGWTServiceAsync.INSTANCE.startCSVExport(exportSession,
|
|
|
|
new AsyncCallback<Void>() {
|
2013-12-02 17:45:23 +01:00
|
|
|
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-02-28 16:22:22 +01:00
|
|
|
showErrorAndHide(
|
|
|
|
"Error in exportCSV",
|
|
|
|
"An error occured in exportCSV: "
|
|
|
|
+ caught.getLocalizedMessage(), caught
|
|
|
|
.getStackTrace().toString(), caught);
|
2013-12-02 17:45:23 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setup() {
|
|
|
|
getWizardWindow().setEnableBackButton(false);
|
|
|
|
setBackButtonVisible(false);
|
|
|
|
setNextButtonVisible(false);
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
getWizardWindow().setNextButtonToFinish();
|
|
|
|
exportCSV();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void operationInitializing() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void operationUpdate(float elaborated) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void operationComplete() {
|
|
|
|
// final String tableId,final String tableResourceId) {
|
|
|
|
|
|
|
|
Command sayComplete = new Command() {
|
|
|
|
public void execute() {
|
|
|
|
try {
|
|
|
|
getWizardWindow().close(false);
|
|
|
|
Log.info("fire Complete: tableId");
|
|
|
|
|
|
|
|
getWizardWindow().fireCompleted(null);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.error("fire Complete :" + e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getWizardWindow().setNextButtonCommand(sayComplete);
|
|
|
|
|
|
|
|
setNextButtonVisible(true);
|
|
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void operationFailed(Throwable caught, String reason,
|
|
|
|
String failureDetails) {
|
2014-02-11 14:59:13 +01:00
|
|
|
AlertMessageBox d = new AlertMessageBox("Error in CSV Export", reason);
|
|
|
|
d.addHideHandler(new HideHandler() {
|
|
|
|
public void onHide(HideEvent event) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
d.show();
|
2013-12-02 17:45:23 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 16:22:22 +01:00
|
|
|
@Override
|
|
|
|
public void operationStopped(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: tableId");
|
|
|
|
|
|
|
|
getWizardWindow().fireCompleted(null);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.error("fire Complete :" + e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getWizardWindow().setNextButtonCommand(sayComplete);
|
|
|
|
|
|
|
|
setNextButtonVisible(true);
|
|
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-02 17:45:23 +01:00
|
|
|
}
|