Search in sources :

Example 16 with EnterTextDialog

use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.

the class GetSubFoldersDialog method preview.

// Preview the data
private void preview() {
    // Create the XML input step
    GetSubFoldersMeta oneMeta = new GetSubFoldersMeta();
    getInfo(oneMeta);
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "GetSubFoldersDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "GetSubFoldersDialog.PreviewSize.DialogMessage"));
    int previewSize = numberDialog.open();
    if (previewSize > 0) {
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
        progressDialog.open();
        if (!progressDialog.isCancelled()) {
            Trans trans = progressDialog.getTrans();
            String loggingText = progressDialog.getLoggingText();
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "GetSubFoldersDialog.ErrorInPreview.DialogMessage"), 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();
        }
    }
}
Also used : TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) GetSubFoldersMeta(org.pentaho.di.trans.steps.getsubfolders.GetSubFoldersMeta) Trans(org.pentaho.di.trans.Trans)

Example 17 with EnterTextDialog

use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.

the class TextFileInputDialog method preview.

// Preview the data
private void preview() {
    // Create the XML input step
    TextFileInputMeta oneMeta = new TextFileInputMeta();
    getInfo(oneMeta, true);
    if (oneMeta.inputFiles.acceptingFilenames) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.Dialog.SpecifyASampleFile.Message"));
        mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.Dialog.SpecifyASampleFile.Title"));
        mb.open();
        return;
    }
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "TextFileInputDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.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();
    }
}
Also used : TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 18 with EnterTextDialog

use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.

the class TextFileInputDialog method getCSV.

// Get the data layout
private void getCSV() {
    TextFileInputMeta meta = new TextFileInputMeta();
    getInfo(meta, true);
    // CSV without separator defined
    if (meta.content.fileType.equalsIgnoreCase("CSV") && (meta.content.separator == null || meta.content.separator.isEmpty())) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "TextFileInput.Exception.NoSeparator"));
        mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.DialogTitle"));
        mb.open();
        return;
    }
    TextFileInputMeta previousMeta = (TextFileInputMeta) meta.clone();
    FileInputList textFileList = meta.getFileInputList(transMeta);
    InputStream fileInputStream;
    CompressionInputStream inputStream = null;
    StringBuilder lineStringBuilder = new StringBuilder(256);
    int fileFormatType = meta.getFileFormatTypeNr();
    String delimiter = transMeta.environmentSubstitute(meta.content.separator);
    String enclosure = transMeta.environmentSubstitute(meta.content.enclosure);
    String escapeCharacter = transMeta.environmentSubstitute(meta.content.escapeCharacter);
    if (textFileList.nrOfFiles() > 0) {
        int clearFields = meta.content.header ? SWT.YES : SWT.NO;
        int nrInputFields = meta.inputFields.length;
        if (nrInputFields > 0) {
            MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.ClearFieldList.DialogMessage"));
            mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.ClearFieldList.DialogTitle"));
            clearFields = mb.open();
            if (clearFields == SWT.CANCEL) {
                return;
            }
        }
        try {
            wFields.table.removeAll();
            FileObject fileObject = textFileList.getFile(0);
            fileInputStream = KettleVFS.getInputStream(fileObject);
            Table table = wFields.table;
            CompressionProvider provider = CompressionProviderFactory.getInstance().createCompressionProviderInstance(meta.content.fileCompression);
            inputStream = provider.createInputStream(fileInputStream);
            InputStreamReader reader;
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                reader = new InputStreamReader(inputStream, meta.getEncoding());
            } else {
                reader = new InputStreamReader(inputStream);
            }
            EncodingType encodingType = EncodingType.guessEncodingType(reader.getEncoding());
            // Scan the header-line, determine fields...
            String line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
            if (line != null) {
                // Estimate the number of input fields...
                // Chop up the line using the delimiter
                String[] fields = TextFileInputUtils.guessStringsFromLine(transMeta, log, line, meta, delimiter, enclosure, escapeCharacter);
                for (int i = 0; i < fields.length; i++) {
                    String field = fields[i];
                    if (field == null || field.length() == 0 || !meta.content.header) {
                        field = "Field" + (i + 1);
                    } else {
                        // Trim the field
                        field = Const.trim(field);
                        // Replace all spaces & - with underscore _
                        field = Const.replace(field, " ", "_");
                        field = Const.replace(field, "-", "_");
                    }
                    TableItem item = new TableItem(table, SWT.NONE);
                    item.setText(1, field);
                    // The default type is String...
                    item.setText(2, "String");
                }
                wFields.setRowNums();
                wFields.optWidth(true);
                // Copy it...
                getInfo(meta, true);
                // Sample a few lines to determine the correct type of the fields...
                String shellText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToSample.DialogTitle");
                String lineText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToSample.DialogMessage");
                EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
                int samples = end.open();
                if (samples >= 0) {
                    getInfo(meta, true);
                    TextFileCSVImportProgressDialog pd = new TextFileCSVImportProgressDialog(shell, meta, transMeta, reader, samples, clearFields == SWT.YES);
                    String message = pd.open();
                    if (message != null) {
                        wFields.removeAll();
                        // OK, what's the result of our search?
                        getData(meta);
                        // 
                        if (clearFields == SWT.NO) {
                            getFieldsData(previousMeta, true);
                            wFields.table.setSelection(previousMeta.inputFields.length, wFields.table.getItemCount() - 1);
                        }
                        wFields.removeEmptyRows();
                        wFields.setRowNums();
                        wFields.optWidth(true);
                        EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ScanResults.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ScanResults.DialogMessage"), message, true);
                        etd.setReadOnly();
                        etd.open();
                    }
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.UnableToReadHeaderLine.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
                mb.open();
            }
        } catch (IOException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.IOError.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.IOError.DialogMessage"), e);
        } catch (KettleException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorGettingFileDesc.DialogMessage"), e);
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
            // Ignore errors
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.NoValidFileFound.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Table(org.eclipse.swt.widgets.Table) InputStreamReader(java.io.InputStreamReader) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) InputStream(java.io.InputStream) TableItem(org.eclipse.swt.widgets.TableItem) EncodingType(org.pentaho.di.trans.steps.fileinput.text.EncodingType) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IOException(java.io.IOException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) CompressionProvider(org.pentaho.di.core.compress.CompressionProvider) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) FileObject(org.apache.commons.vfs2.FileObject) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 19 with EnterTextDialog

use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.

the class XulDatabaseExplorerController method dataProfile.

public void dataProfile() {
    if (model.getTable() == null) {
        return;
    }
    Shell dbShell = (Shell) dbExplorerDialog.getRootObject();
    try {
        TransProfileFactory profileFactory = new TransProfileFactory(this.model.getDatabaseMeta(), getSchemaAndTable(this.model));
        TransMeta transMeta = profileFactory.generateTransformation(new LoggingObject(model.getTable()));
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(dbShell, transMeta, new String[] { TransProfileFactory.RESULT_STEP_NAME }, new int[] { 25000 });
        progressDialog.open();
        if (!progressDialog.isCancelled()) {
            Trans trans = progressDialog.getTrans();
            String loggingText = progressDialog.getLoggingText();
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(dbShell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            }
            PreviewRowsDialog prd = new PreviewRowsDialog(dbShell, transMeta, SWT.NONE, TransProfileFactory.RESULT_STEP_NAME, progressDialog.getPreviewRowsMeta(TransProfileFactory.RESULT_STEP_NAME), progressDialog.getPreviewRows(TransProfileFactory.RESULT_STEP_NAME), loggingText);
            prd.open();
        }
    } catch (Exception e) {
        new ErrorDialog(this.dbExplorerDialog.getShell(), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Title"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Message"), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) TransProfileFactory(org.pentaho.di.trans.TransProfileFactory) LoggingObject(org.pentaho.di.core.logging.LoggingObject) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) Trans(org.pentaho.di.trans.Trans) XulException(org.pentaho.ui.xul.XulException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 20 with EnterTextDialog

use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.

the class GetXMLDataDialog method get.

private void get() {
    InputStream is = null;
    try {
        GetXMLDataMeta meta = new GetXMLDataMeta();
        getInfo(meta);
        // check if the path is given
        if (!checkLoopXPath(meta)) {
            return;
        }
        int clearFields = SWT.YES;
        if (wFields.nrNonEmpty() > 0) {
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            messageBox.setMessage(BaseMessages.getString(PKG, "GetXMLDataDialog.ClearFieldList.DialogMessage"));
            messageBox.setText(BaseMessages.getString(PKG, "GetXMLDataDialog.ClearFieldList.DialogTitle"));
            clearFields = messageBox.open();
            if (clearFields == SWT.CANCEL) {
                return;
            }
        }
        if (meta.isInFields()) {
            if (meta.isReadUrl()) {
                // Read URL
                String url = XMLSource;
                if (url == null) {
                    EnterStringDialog enterStringDialog = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"));
                    url = enterStringDialog.open();
                }
                populateFields(meta, url, true, true, clearFields);
            } else if (meta.getIsAFile()) {
                // Read file
                String str = XMLSource;
                if (str == null) {
                    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                    dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" });
                    dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.XMLFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
                    if (dialog.open() != null) {
                        str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    }
                }
                populateFields(meta, str, false, false, clearFields);
            } else {
                // Read xml
                String xml = XMLSource;
                if (xml == null) {
                    EnterTextDialog d = new EnterTextDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Message"), null);
                    xml = d.open();
                }
                populateFields(meta, xml, true, false, clearFields);
            }
        } else {
            FileInputList inputList = meta.getFiles(transMeta);
            if (inputList.getFiles().size() > 0) {
                populateFields(meta, KettleVFS.getFilename(inputList.getFile(0)), false, false, clearFields);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorParsingData.DialogTitle"), BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorParsingData.DialogMessage"), e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (Exception e) {
        /* Ignore */
        }
    }
}
Also used : GetXMLDataMeta(org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta) InputStream(java.io.InputStream) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)70 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)48 Trans (org.pentaho.di.trans.Trans)47 TransMeta (org.pentaho.di.trans.TransMeta)47 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)47 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)47 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)44 KettleException (org.pentaho.di.core.exception.KettleException)35 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)17 MessageBox (org.eclipse.swt.widgets.MessageBox)15 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 FileObject (org.apache.commons.vfs2.FileObject)6 InputStreamReader (java.io.InputStreamReader)5 Point (org.eclipse.swt.graphics.Point)5 TableItem (org.eclipse.swt.widgets.TableItem)5 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)5 FileDialog (org.eclipse.swt.widgets.FileDialog)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 DecimalFormat (java.text.DecimalFormat)3