tabular-data-sdmx-export-wi.../src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXOperationInProgressCard...

210 lines
6.2 KiB
Java

/**
*
*/
package org.gcube.portlets.user.td.sdmxexportwidget.client;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession;
import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressBarUpdater;
import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressListener;
import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressUpdater;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
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.box.AlertMessageBox;
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;
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 SDMXOperationInProgressCard extends WizardCard implements
SDMXExportProgressListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected SDMXOperationInProgressCard thisCard;
protected SDMXExportSession exportSession;
protected SDMXExportProgressUpdater progressUpdater;
public SDMXOperationInProgressCard(final SDMXExportSession exportSession) {
super("Operation In Progress", "");
this.exportSession = exportSession;
thisCard = this;
String urlRegistry;
if (exportSession.getRegistryBaseUrl() == null
|| exportSession.getRegistryBaseUrl().isEmpty()) {
urlRegistry = "Internal";
} else {
urlRegistry = exportSession.getRegistryBaseUrl();
}
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.getSource().getName());
description.setHTML(1, 0,
"<span style=\"font-weight:bold;\";>Id: </span>");
description.setText(1, 1, exportSession.getId());
description.setHTML(2, 0,
"<span style=\"font-weight:bold;\";>Agency: </span>");
description.setText(2, 1, exportSession.getAgencyName());
description.setHTML(3, 0,
"<span style=\"font-weight:bold;\";>Registry: </span>");
description.setText(3, 1, urlRegistry);
description.setHTML(4, 0,
"<span style=\"font-weight:bold;\";>Version: </span>");
description.setText(4, 1, exportSession.getVersion());
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 SDMXExportProgressUpdater();
progressUpdater.addListener(new SDMXExportProgressBarUpdater(
progressBar));
progressUpdater.addListener(this);
setContent(operationInProgressPanel);
}
// columnToImportMask
public void exportSDMX() {
TDGWTServiceAsync.INSTANCE.startSDMXExport(exportSession,
new AsyncCallback<Void>() {
public void onSuccess(Void result) {
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
}
public void onFailure(Throwable caught) {
showErrorAndHide(
"Error in exportSDMX",
"An error occured in exportSDMX: "
+ caught.getLocalizedMessage(), caught
.getStackTrace().toString(), caught);
}
});
}
@Override
public void setup() {
getWizardWindow().setEnableBackButton(false);
setBackButtonVisible(false);
setNextButtonVisible(false);
getWizardWindow().setEnableNextButton(false);
getWizardWindow().setNextButtonToFinish();
exportSDMX();
}
@Override
public void operationInitializing() {
}
@Override
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");
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) {
AlertMessageBox d = new AlertMessageBox("Error in SDMX Export", reason);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
d.show();
}
@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");
getWizardWindow().fireCompleted(null);
} catch (Exception e) {
Log.error("fire Complete :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setNextButtonCommand(sayComplete);
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
}
@Override
public void operationGeneratingView() {
// TODO Auto-generated method stub
}
}