use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class CsvInputDialog method getCSV.
// Get the data layout
private void getCSV() {
InputStream inputStream = null;
try {
CsvInputMeta meta = new CsvInputMeta();
getInfo(meta);
String filename = transMeta.environmentSubstitute(meta.getFilename());
String delimiter = transMeta.environmentSubstitute(meta.getDelimiter());
String enclosure = transMeta.environmentSubstitute(meta.getEnclosure());
FileObject fileObject = KettleVFS.getFileObject(filename);
if (!(fileObject instanceof LocalFile)) {
//
throw new KettleException(BaseMessages.getString(PKG, "CsvInput.Log.OnlyLocalFilesAreSupported"));
}
wFields.table.removeAll();
inputStream = KettleVFS.getInputStream(fileObject);
String realEncoding = transMeta.environmentSubstitute(meta.getEncoding());
InputStreamReader reader;
if (Utils.isEmpty(realEncoding)) {
reader = new InputStreamReader(inputStream);
} else {
reader = new InputStreamReader(inputStream, realEncoding);
}
EncodingType encodingType = EncodingType.guessEncodingType(reader.getEncoding());
// Read a line of data to determine the number of rows...
//
String line = TextFileInput.getLine(log, reader, encodingType, TextFileInputMeta.FILE_FORMAT_UNIX, new StringBuilder(1000));
// Split the string, header or data into parts...
//
String[] fieldNames = CsvInput.guessStringsFromLine(log, line, delimiter, enclosure, meta.getEscapeCharacter());
if (!meta.isHeaderPresent()) {
// Don't use field names from the header...
// Generate field names F1 ... F10
//
DecimalFormat df = new DecimalFormat("000");
for (int i = 0; i < fieldNames.length; i++) {
fieldNames[i] = "Field_" + df.format(i);
}
} else {
if (!Utils.isEmpty(meta.getEnclosure())) {
for (int i = 0; i < fieldNames.length; i++) {
if (fieldNames[i].startsWith(meta.getEnclosure()) && fieldNames[i].endsWith(meta.getEnclosure()) && fieldNames[i].length() > 1) {
fieldNames[i] = fieldNames[i].substring(1, fieldNames[i].length() - 1);
}
}
}
}
//
for (int i = 0; i < fieldNames.length; i++) {
fieldNames[i] = Const.trim(fieldNames[i]);
}
//
for (int i = 0; i < fieldNames.length; i++) {
TableItem item = new TableItem(wFields.table, SWT.NONE);
item.setText(1, fieldNames[i]);
item.setText(2, ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING));
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
// Now we can continue reading the rows of data and we can guess the
// Sample a few lines to determine the correct type of the fields...
//
String shellText = BaseMessages.getString(PKG, "CsvInputDialog.LinesToSample.DialogTitle");
String lineText = BaseMessages.getString(PKG, "CsvInputDialog.LinesToSample.DialogMessage");
EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
int samples = end.open();
if (samples >= 0) {
getInfo(meta);
TextFileCSVImportProgressDialog pd = new TextFileCSVImportProgressDialog(shell, meta, transMeta, reader, samples, true);
String message = pd.open();
if (message != null) {
wFields.removeAll();
// OK, what's the result of our search?
getData(meta, false);
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "CsvInputDialog.ScanResults.DialogTitle"), BaseMessages.getString(PKG, "CsvInputDialog.ScanResults.DialogMessage"), message, true);
etd.setReadOnly();
etd.open();
// asyncUpdatePreview();
}
}
} catch (IOException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "CsvInputDialog.IOError.DialogTitle"), BaseMessages.getString(PKG, "CsvInputDialog.IOError.DialogMessage"), e);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "CsvInputDialog.ErrorGettingFileDesc.DialogMessage"), e);
} finally {
try {
inputStream.close();
} catch (Exception e) {
// Ignore close errors
}
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class CsvInputDialog method preview.
// Preview the data
private synchronized void preview() {
// Create the XML input step
CsvInputMeta oneMeta = new CsvInputMeta();
getInfo(oneMeta);
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
transMeta.getVariable("Internal.Transformation.Filename.Directory");
previewMeta.getVariable("Internal.Transformation.Filename.Directory");
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogMessage"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class JobGraph method editEntryDescription.
public void editEntryDescription() {
String title = BaseMessages.getString(PKG, "JobGraph.Dialog.EditDescription.Title");
String message = BaseMessages.getString(PKG, "JobGraph.Dialog.EditDescription.Message");
EnterTextDialog dd = new EnterTextDialog(shell, title, message, getJobEntry().getDescription());
String des = dd.open();
if (des != null) {
jobEntry.setDescription(des);
jobEntry.setChanged();
spoon.setShellText();
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class TransGraph method editDescription.
public void editDescription(StepMeta stepMeta) {
String title = BaseMessages.getString(PKG, "TransGraph.Dialog.StepDescription.Title");
String message = BaseMessages.getString(PKG, "TransGraph.Dialog.StepDescription.Message");
EnterTextDialog dd = new EnterTextDialog(shell, title, message, stepMeta.getDescription());
String d = dd.open();
if (d != null) {
stepMeta.setDescription(d);
stepMeta.setChanged();
spoon.setShellText();
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class DataGridDialog method preview.
/**
* Preview the data generated by this step. This generates a transformation using this step & a dummy and previews it.
*/
private void preview() {
// Create the table input reader step...
DataGridMeta oneMeta = new DataGridMeta();
getInfo(oneMeta);
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "DataGridDialog.EnterPreviewSize.Title"), BaseMessages.getString(PKG, "DataGridDialog.EnterPreviewSize.Message"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
Aggregations