diff --git a/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVOperationInProgressCard.java b/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVOperationInProgressCard.java new file mode 100644 index 0000000..5f64b56 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVOperationInProgressCard.java @@ -0,0 +1,155 @@ +/** + * + */ +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" g.panichi@isti.cnr.it + * + */ +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, + "Destination: "); + description.setText(0, 1, exportSession.getDestination().getName()); + description.setHTML(1, 0, + "File Name: "); + description.setText(1, 1, exportSession.getFileName()); + + description.setHTML(2, 0, + "File Description: "); + 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() { + + @Override + public void onSuccess(Void result) { + progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY); + } + + @Override + 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(); + } + + @Override + public void operationInitializing() { + + } + + @Override + public void operationUpdate(float elaborated) { + + } + + @Override + 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); + } + + @Override + public void operationFailed(Throwable caught, String reason, + String failureDetails) { + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVWorkSpaceSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVWorkSpaceSelectionCard.java index 182cd0a..30fef1c 100644 --- a/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVWorkSpaceSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/csvexportwidget/client/CSVWorkSpaceSelectionCard.java @@ -71,7 +71,7 @@ public class CSVWorkSpaceSelectionCard extends WizardCard { Log.debug("Set Workspace Panel"); wpanel = new WorkspacePanel(); wpanel.setSpWidth("410px"); - wpanel.setSpHeight("356px"); + wpanel.setSpHeight("330px"); List lItemType = new ArrayList(); lItemType.add(ItemType.ROOT); lItemType.add(ItemType.FOLDER); @@ -125,7 +125,7 @@ public class CSVWorkSpaceSelectionCard extends WizardCard { if (exportSession.getItemId() != null) { exportSession.setFileName(fileName.getCurrentValue()); exportSession.setFileDescription(fileDescription.getCurrentValue()); - getFileFromWorkspace(); + goNext(); } else { d = new AlertMessageBox("AttecheckExportDatantion", "No folder selected"); @@ -184,35 +184,12 @@ public class CSVWorkSpaceSelectionCard extends WizardCard { } - protected void getFileFromWorkspace() { - TDGWTServiceAsync tdGwtServiceAsync = TDGWTServiceAsync.INSTANCE; - /* - * tdGwtServiceAsync.setFileInWorkspace(exportSession, new - * AsyncCallback(){ - * - * @Override public void onFailure(Throwable caught) { - * wpanel.endWaiting(); thisCard.showErrorAndHide("Error", - * "Error retrieving the file from the workspace: " - * +caught.getLocalizedMessage(), caught.toString(), caught); - * - * } - * - * @Override public void onSuccess(Void result) { wpanel.endWaiting(); - * goForward(); - * - * } - * - * }); - */ - } - - protected void goForward() { - /* - * CSVConfigCard csvConfigCard = new CSVConfigCard(importSession); - * getWizardWindow().addCard(csvConfigCard); - * Log.info("NextCard CSVConfigCard"); getWizardWindow().nextCard(); - */ - + protected void goNext() { + CSVOperationInProgressCard csvOperationInProgressCard = new CSVOperationInProgressCard(exportSession); + getWizardWindow().addCard(csvOperationInProgressCard); + Log.info("NextCard CSVOperationInProgressCard"); + getWizardWindow().nextCard(); + } }