use of org.rstudio.studio.client.workbench.views.environment.dataimport.model.DataImportPreviewResponse in project rstudio by rstudio.
the class DataImport method previewDataImport.
private void previewDataImport() {
Operation previewDataImportOperation = new Operation() {
@Override
public void execute() {
DataImportOptions previewImportOptions = getOptions();
if (dataImportFileChooser_.getText() == "") {
gridViewer_.setData(null);
return;
}
previewImportOptions.setMaxRows(maxRows_);
progressIndicator_.onProgress("Retrieving preview data...", new Operation() {
@Override
public void execute() {
progressIndicator_.clearProgress();
cleanPreviewResources();
server_.previewDataImportAsyncAbort(new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void empty) {
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
progressIndicator_.onError(error.getMessage());
}
});
}
});
server_.previewDataImportAsync(previewImportOptions, maxCols_, maxFactors_, new ServerRequestCallback<DataImportPreviewResponse>() {
@Override
public void onResponseReceived(DataImportPreviewResponse response) {
if (response == null || response.getErrorMessage() != null) {
if (response != null) {
setGridViewerData(response);
response.setColumnDefinitions(lastSuccessfulResponse_);
progressIndicator_.onError(enhancePreviewErrorMessage(response.getErrorMessage()));
}
return;
}
// Set the column definitions to allow subsequent calls to assemble
// generate preview code based on data.
importOptions_.setBaseColumnDefinitions(response);
lastSuccessfulResponse_ = response;
dataImportOptionsUi_.setPreviewResponse(response);
if (response.getLocalFiles() != null) {
localFiles_ = response.getLocalFiles();
}
gridViewer_.setOption("status", "Previewing first " + toLocaleString(maxRows_) + " entries. " + (response.getParsingErrors() > 0 ? Integer.toString(response.getParsingErrors()) + " parsing errors." : ""));
assignColumnDefinitions(response, importOptions_.getColumnDefinitions());
setGridViewerData(response);
progressIndicator_.onCompleted();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
cleanPreviewResources();
gridViewer_.setData(null);
progressIndicator_.onError(error.getMessage());
}
});
}
};
assembleDataImport(previewDataImportOperation);
}
Aggregations