Search in sources :

Example 21 with EnterTextDialog

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

the class GetXMLDataDialog method getLoopPathList.

private void getLoopPathList() {
    try {
        GetXMLDataMeta meta = new GetXMLDataMeta();
        getInfo(meta);
        if (meta.isInFields()) {
            if (meta.isReadUrl()) {
                // Read URL
                String url = XMLSource;
                if (url == null) {
                    EnterStringDialog d = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Message"));
                    url = d.open();
                }
                populateLoopPaths(meta, url, true, true);
            } 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();
                    }
                    populateLoopPaths(meta, str, false, false);
                }
            } 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();
                }
                populateLoopPaths(meta, xml, true, false);
            }
        } else {
            FileInputList fileinputList = meta.getFiles(transMeta);
            if (fileinputList.nrOfFiles() > 0) {
                if (fileinputList.getFile(0).exists()) {
                    populateLoopPaths(meta, KettleVFS.getFilename(fileinputList.getFile(0)), false, false);
                } else {
                    // The file not exists !
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLDataDialog.Exception.FileDoesNotExist", KettleVFS.getFilename(fileinputList.getFile(0))));
                }
            } else {
                // No file specified
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "GetXMLDataDialog.FilesMissing.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
                mb.open();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) GetXMLDataMeta(org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta) 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)

Example 22 with EnterTextDialog

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

the class XMLInputStreamDialog method preview.

// Preview the data
private void preview() {
    // execute a complete preview transformation in the background.
    // This is how we do it...
    // 
    XMLInputStreamMeta oneMeta = new XMLInputStreamMeta();
    getInfo(oneMeta);
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "XMLInputStreamDialog.Dialog.EnterPreviewSize.Title"), BaseMessages.getString(PKG, "XMLInputStreamDialog.Dialog.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();
    }
}
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) XMLInputStreamMeta(org.pentaho.di.trans.steps.xmlinputstream.XMLInputStreamMeta) Trans(org.pentaho.di.trans.Trans)

Example 23 with EnterTextDialog

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

the class Translator2 method saveFiles.

protected boolean saveFiles() {
    java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
    if (changedMessagesStores.size() > 0) {
        StringBuilder msg = new StringBuilder();
        for (MessagesStore messagesStore : changedMessagesStores) {
            String filename = messagesStore.getSaveFilename(messagesStore.getSourceFolder());
            messagesStore.setFilename(filename);
            msg.append(messagesStore.getFilename());
            if (!new File(filename).exists()) {
                msg.append(" (NEW!)");
            }
            msg.append(Const.CR);
        }
        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "i18nDialog.ChangedFiles"), BaseMessages.getString(PKG, "i18nDialog.ChangedMessagesFiles"), msg.toString());
        if (dialog.open() != null) {
            try {
                for (MessagesStore messagesStore : changedMessagesStores) {
                    messagesStore.write();
                    log.logBasic(BaseMessages.getString(PKG, "i18n.Log.SavedMessagesFile", messagesStore.getFilename()));
                }
            } catch (KettleException e) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
                return false;
            }
            return true;
        } else {
            return false;
        }
    } else {
        // TODO: disable the button if nothing changed.
        return true;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) File(java.io.File) MessagesStore(org.pentaho.di.ui.i18n.MessagesStore)

Example 24 with EnterTextDialog

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

the class SalesforceInputDialog method preview.

// Preview the data
private void preview() {
    try {
        SalesforceInputMeta oneMeta = new SalesforceInputMeta();
        getInfo(oneMeta);
        // check if the path is given
        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.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.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();
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans)

Example 25 with EnterTextDialog

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

the class S3CsvInputDialog method getCSV.

// Get the data layout
private void getCSV() {
    InputStream inputStream = null;
    try {
        S3CsvInputMeta meta = new S3CsvInputMeta();
        getInfo(meta);
        String filename = transMeta.environmentSubstitute(meta.getFilename());
        String bucketname = transMeta.environmentSubstitute(meta.getBucket());
        int maxLineSize = Const.toInt(transMeta.environmentSubstitute(meta.getMaxLineSize()), 2000);
        wFields.table.removeAll();
        S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
        S3Bucket s3bucket = s3ObjProvider.getBucket(bucketname);
        if (s3bucket == null) {
            throw new Exception(Messages.getString("S3DefaultService.Exception.UnableToFindBucket.Message", bucketname));
        }
        // 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 = Messages.getString("S3CsvInputDialog.LinesToSample.DialogTitle");
        String lineText = Messages.getString("S3CsvInputDialog.LinesToSample.DialogMessage");
        EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
        int samples = end.open();
        if (samples < 0) {
            return;
        }
        // Only get the first lines, not the complete file
        // And grab an input stream to the data...
        inputStream = s3ObjProvider.getS3Object(s3bucket, filename, 0L, (long) samples * (long) maxLineSize).getDataInputStream();
        InputStreamReader reader = new InputStreamReader(inputStream);
        // Read a line of data to determine the number of rows...
        // 
        String line = TextFileInput.getLine(log, reader, TextFileInputMeta.FILE_FORMAT_MIXED, new StringBuilder(1000));
        // Split the string, header or data into parts...
        // 
        String[] fieldNames = Const.splitString(line, meta.getDelimiter());
        if (!meta.isHeaderPresent()) {
            // Don't use field names from the header...
            // Generate field names F1 ... F10
            // 
            // $NON-NLS-1$
            DecimalFormat df = new DecimalFormat("000");
            for (int i = 0; i < fieldNames.length; i++) {
                // $NON-NLS-1$
                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, ValueMeta.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
        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);
            wFields.removeEmptyRows();
            wFields.setRowNums();
            wFields.optWidth(true);
            EnterTextDialog etd = new EnterTextDialog(shell, Messages.getString("S3CsvInputDialog.ScanResults.DialogTitle"), Messages.getString("S3CsvInputDialog.ScanResults.DialogMessage"), message, true);
            etd.setReadOnly();
            etd.open();
        }
    } catch (IOException e) {
        new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.IOError.DialogTitle"), Messages.getString("S3CsvInputDialog.IOError.DialogMessage"), e);
    } catch (Exception e) {
        new ErrorDialog(shell, Messages.getString("System.Dialog.Error.Title"), Messages.getString("S3CsvInputDialog.ErrorGettingFileDesc.DialogMessage"), e);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (Exception e) {
            log.logError(stepname, "Error closing s3 data input stream", e);
        }
    }
}
Also used : TextFileCSVImportProgressDialog(org.pentaho.di.ui.trans.steps.textfileinput.TextFileCSVImportProgressDialog) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DecimalFormat(java.text.DecimalFormat) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IOException(java.io.IOException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IOException(java.io.IOException) S3Bucket(org.jets3t.service.model.S3Bucket) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog)

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