tabular-data-csv-export-widget/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVOperationInProgressCard....

151 lines
4.6 KiB
Java

/**
*
*/
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;
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;
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;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVOperationInProgressCard extends WizardCard implements
CSVExportProgressListener {
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();
//FlexCellFormatter cellFormatter = description.getFlexCellFormatter();
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();
progressUpdater.addListener(new CSVExportProgressBarUpdater(progressBar));
progressUpdater.addListener(this);
setContent(operationInProgressPanel);
}
//columnToImportMask
public void exportCSV() {
TDGWTServiceAsync.INSTANCE.startCSVExport(exportSession, new AsyncCallback<Void>() {
public void onSuccess(Void result) {
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
}
public void onFailure(Throwable caught) {
showErrorAndHide("Error in exportCSV",
"An error occured in exportCSV: "+caught.getLocalizedMessage(), caught.getStackTrace().toString(), caught);
}
});
}
@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) {
}
}