use of org.talend.metadata.managment.ui.preview.StoppablePreviewLoader in project tdi-studio-se by Talend.
the class JSONFileStep2Form method refreshPreview.
/**
* refreshPreview use ShadowProcess to refresh the preview.
*/
void refreshPreview() {
clearPreview();
// if no file, the process don't be executed
if (getConnection().getJSONFilePath() == null || !(new File(getConnection().getJSONFilePath()).exists()) && JSONUtil.tempJSONXsdPath == null) {
previewInformationLabel.setText(" " + "The file path must be specified");
return;
}
// if incomplete settings, , the process don't be executed
if (!checkFieldsValue()) {
previewInformationLabel.setText(" " + "The settings must be completed to show the preview");
return;
}
// set row limit
if (jsonXPathLoopDescriptor.getLimitBoucle() > 0 && jsonXPathLoopDescriptor.getLimitBoucle() < XmlArray.getRowLimit()) {
XmlArray.setRowLimit(jsonXPathLoopDescriptor.getLimitBoucle());
}
previewInformationLabel.setText(" " + "Preview in progress...");
String shadowProcessType = null;
if (EJsonReadbyMode.JSONPATH.getValue().equals(getConnection().getReadbyMode())) {
//$NON-NLS-1$
shadowProcessType = "FILE_JSON";
}
final String finalShadowProcessType = shadowProcessType;
AsynchronousPreviewHandler<CsvArray> previewHandler = null;
try {
previewHandler = ShadowProcessHelper.createPreviewHandler(finalShadowProcessType);
} catch (CoreException e) {
previewInError(e);
return;
}
StoppablePreviewLoader previewLoader = new StoppablePreviewLoader<CsvArray>(previewHandler, previewInformationLabel) {
/*
* (non-Javadoc)
*
* @see
* org.talend.repository.ui.wizards.metadata.connection.files.JSON.StoppablePreviewLoader#previewEnded(java
* .lang.Object)
*/
@Override
protected void previewEnded(CsvArray result) {
jsonFilePreview.refreshTablePreview(result, false, (getConnection().getSchema().get(0)).getSchemaTargets());
if (jsonFilePreview.isCsvRowsEmpty()) {
clearPreview();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
handleErrorOutput(outputComposite, tabFolder, outputTabItem);
}
});
log.error("No result for this settings");
previewButton.setEnabled(true);
}
}
@Override
public void previewInError(CoreException e) {
JSONFileStep2Form.this.previewInError(e);
}
@Override
protected String getShadowProcessType() {
if (finalShadowProcessType != null && !finalShadowProcessType.isEmpty()) {
return finalShadowProcessType;
} else {
return super.getShadowProcessType();
}
}
};
previewLoader.load(getProcessDescription(false));
}
Aggregations