You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.9 KiB
Java

/**
*
*/
package org.gcube.portlets.user.td.codelistmappingimportwidget.client;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import org.gcube.portlets.user.td.codelistmappingimportwidget.client.progress.CodelistMappingImportProgressBarUpdater;
import org.gcube.portlets.user.td.codelistmappingimportwidget.client.progress.CodelistMappingImportProgressListener;
import org.gcube.portlets.user.td.codelistmappingimportwidget.client.progress.CodelistMappingImportProgressUpdater;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
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;
//import com.allen_sauer.gwt.log.client.Log;
//import com.google.gwt.user.client.Command;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CodelistMappingOperationInProgressCard extends WizardCard implements
CodelistMappingImportProgressListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected CodelistMappingOperationInProgressCard thisCard;
protected CSVImportSession importSession;
protected CodelistMappingImportProgressUpdater progressUpdater;
public CodelistMappingOperationInProgressCard(final CSVImportSession importSession) {
super("Operation In Progress", "");
this.importSession = importSession;
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;\";>Document: </span>");
description.setText(0, 1, "CSV File");
description.setHTML(1, 0,
"<span style=\"font-weight:bold;\";>Source: </span>");
description.setText(1, 1, importSession.getSource().getName());
description.setHTML(2, 0,
"<span style=\"font-weight:bold;\";>File: </span>");
description.setText(2, 1, importSession.getTabResource().getName());
FramedPanel summary = new FramedPanel();
summary.setHeadingText("Import 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 CodelistMappingImportProgressUpdater();
progressUpdater
.addListener(new CodelistMappingImportProgressBarUpdater(progressBar));
progressUpdater.addListener(this);
setContent(operationInProgressPanel);
}
// columnToImportMask
public void importCSV() {
TDGWTServiceAsync.INSTANCE.startCSVImport(importSession,
new AsyncCallback<Void>() {
public void onSuccess(Void result) {
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
}
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus()
.fireEvent(
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
showErrorAndHide(
"Error in importCSV",
"An error occured in importCSV: "
+ caught.getLocalizedMessage(),
caught.getStackTrace().toString(), caught);
}
}
});
}
@Override
public void setup() {
getWizardWindow().setEnableBackButton(false);
setBackButtonVisible(false);
setNextButtonVisible(false);
getWizardWindow().setEnableNextButton(false);
getWizardWindow().setNextButtonToFinish();
importCSV();
}
public void operationInitializing() {
}
public void operationUpdate(float elaborated) {
}
public void operationComplete(final TRId trId) {
// 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);
}
public void operationFailed(Throwable caught, String reason,
String failureDetails) {
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus()
.fireEvent(
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
AlertMessageBox d = new AlertMessageBox("Error in CSV Import",
reason);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
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);
}
@Override
public void operationGeneratingView() {
// TODO Auto-generated method stub
}
@Override
public void operationValidate(float elaborated) {
// TODO Auto-generated method stub
}
}