Search in sources :

Example 1 with ErrorDialog

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

the class TextFileCSVImportProgressDialog method open.

public String open() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                message = doScan(monitor);
            } catch (Exception e) {
                e.printStackTrace();
                throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.Exception.ErrorScanningFile", "" + rownumber, debug, e.toString()));
            }
        }
    };
    try {
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        pmd.run(true, true, op);
    } catch (InvocationTargetException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
    } catch (InterruptedException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
    }
    return message;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleException(org.pentaho.di.core.exception.KettleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog 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 3 with ErrorDialog

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

the class Spoon method refreshDbConnectionsSubtree.

@VisibleForTesting
void refreshDbConnectionsSubtree(TreeItem tiRootName, AbstractMeta meta, GUIResource guiResource) {
    TreeItem tiDbTitle = createTreeItem(tiRootName, STRING_CONNECTIONS, guiResource.getImageFolder());
    DatabasesCollector collector = new DatabasesCollector(meta, rep);
    try {
        try {
            collector.collectDatabases();
        } catch (KettleException e) {
            if (e.getCause() instanceof KettleRepositoryLostException) {
                handleRepositoryLost((KettleRepositoryLostException) e.getCause());
                collector = new DatabasesCollector(meta, null);
                collector.collectDatabases();
            } else {
                throw e;
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.ErrorDialog.Title"), BaseMessages.getString(PKG, "Spoon.ErrorDialog.ErrorFetchingFromRepo.DbConnections"), e);
    }
    for (String dbName : collector.getDatabaseNames()) {
        if (!filterMatch(dbName)) {
            continue;
        }
        DatabaseMeta databaseMeta = collector.getMetaFor(dbName);
        TreeItem tiDb = createTreeItem(tiDbTitle, databaseMeta.getDisplayName(), guiResource.getImageConnectionTree());
        if (databaseMeta.isShared()) {
            tiDb.setFont(guiResource.getFontBold());
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TreeItem(org.eclipse.swt.widgets.TreeItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ErrorDialog

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

the class Spoon method refreshPartitionsSubtree.

@VisibleForTesting
void refreshPartitionsSubtree(TreeItem tiTransName, TransMeta transMeta, GUIResource guiResource) {
    TreeItem tiPartitionTitle = createTreeItem(tiTransName, STRING_PARTITIONS, guiResource.getImageFolder());
    List<PartitionSchema> partitionSchemas;
    try {
        partitionSchemas = pickupPartitionSchemas(transMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.ErrorDialog.Title"), BaseMessages.getString(PKG, "Spoon.ErrorDialog.ErrorFetchingFromRepo.PartitioningSchemas"), e);
        return;
    }
    // Put the steps below it.
    for (PartitionSchema partitionSchema : partitionSchemas) {
        if (!filterMatch(partitionSchema.getName())) {
            continue;
        }
        TreeItem tiPartition = createTreeItem(tiPartitionTitle, partitionSchema.getName(), guiResource.getImagePartitionSchema());
        if (partitionSchema.isShared()) {
            tiPartition.setFont(guiResource.getFontBold());
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TreeItem(org.eclipse.swt.widgets.TreeItem) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with ErrorDialog

use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-cassandra-plugin by pentaho.

the class CassandraInputDialog method popupSchemaInfo.

protected void popupSchemaInfo() {
    Connection conn = null;
    Keyspace kSpace = null;
    try {
        String hostS = transMeta.environmentSubstitute(m_hostText.getText());
        String portS = transMeta.environmentSubstitute(m_portText.getText());
        String userS = m_userText.getText();
        String passS = m_passText.getText();
        if (!Utils.isEmpty(userS) && !Utils.isEmpty(passS)) {
            userS = transMeta.environmentSubstitute(userS);
            passS = transMeta.environmentSubstitute(passS);
        }
        String keyspaceS = transMeta.environmentSubstitute(m_keyspaceText.getText());
        String cqlText = transMeta.environmentSubstitute(m_cqlText.getText());
        try {
            Map<String, String> opts = new HashMap<String, String>();
            opts.put(CassandraUtils.CQLOptions.CQLVERSION_OPTION, CassandraUtils.CQLOptions.CQL3_STRING);
            conn = CassandraUtils.getCassandraConnection(hostS, Integer.parseInt(portS), userS, passS, ConnectionFactory.Driver.BINARY_CQL3_PROTOCOL, opts);
            conn.setHosts(hostS);
            conn.setDefaultPort(Integer.parseInt(portS));
            conn.setUsername(userS);
            conn.setPassword(passS);
            kSpace = conn.getKeyspace(keyspaceS);
        } catch (Exception e) {
            logError(// $NON-NLS-1$
            BaseMessages.getString(PKG, "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message") + ":\n\n" + e.getLocalizedMessage(), // $NON-NLS-1$
            e);
            new ErrorDialog(shell, BaseMessages.getString(PKG, // $NON-NLS-1$
            "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Title"), // $NON-NLS-1$
            BaseMessages.getString(PKG, "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message") + ":\n\n" + e.getLocalizedMessage(), // $NON-NLS-1$
            e);
            return;
        }
        String table = CassandraUtils.getTableNameFromCQLSelectQuery(cqlText);
        if (Utils.isEmpty(table)) {
            // $NON-NLS-1$
            throw new Exception(BaseMessages.getString(PKG, "CassandraInput.Error.NoFromClauseInQuery"));
        }
        if (!kSpace.tableExists(table)) {
            throw new Exception(BaseMessages.getString(PKG, "CassandraInput.Error.NonExistentTable", CassandraUtils.removeQuotes(table), // $NON-NLS-1$
            keyspaceS));
        }
        String schemaDescription = kSpace.getTableMetaData(table).describe();
        ShowMessageDialog smd = new ShowMessageDialog(shell, SWT.ICON_INFORMATION | SWT.OK, "Schema info", schemaDescription, // $NON-NLS-1$
        true);
        smd.open();
    } catch (Exception e1) {
        logError(// $NON-NLS-1$
        BaseMessages.getString(PKG, "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message") + ":\n\n" + e1.getMessage(), // $NON-NLS-1$
        e1);
        new ErrorDialog(shell, // $NON-NLS-1$
        BaseMessages.getString(PKG, "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Title"), // $NON-NLS-1$
        BaseMessages.getString(PKG, "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message") + ":\n\n" + e1.getMessage(), // $NON-NLS-1$
        e1);
    } finally {
        if (conn != null) {
            try {
                conn.closeConnection();
            } catch (Exception e) {
                log.logError(e.getLocalizedMessage(), e);
            // TODO popup another error dialog
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Keyspace(org.pentaho.cassandra.spi.Keyspace) ShowMessageDialog(org.pentaho.di.ui.core.dialog.ShowMessageDialog) Connection(org.pentaho.cassandra.spi.Connection) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Aggregations

ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)527 KettleException (org.pentaho.di.core.exception.KettleException)440 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)178 MessageBox (org.eclipse.swt.widgets.MessageBox)118 TableItem (org.eclipse.swt.widgets.TableItem)97 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)76 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)63 TransMeta (org.pentaho.di.trans.TransMeta)48 Shell (org.eclipse.swt.widgets.Shell)46 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)44 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)44 ArrayList (java.util.ArrayList)43 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)40 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)39 StepMeta (org.pentaho.di.trans.step.StepMeta)38 FormData (org.eclipse.swt.layout.FormData)37 FormLayout (org.eclipse.swt.layout.FormLayout)37