Search in sources :

Example 26 with DatabaseExplorerDialog

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

the class DimensionLookupDialog method getTableName.

private void getTableName() {
    int connr = wConnection.getSelectionIndex();
    if (connr < 0) {
        return;
    }
    DatabaseMeta inf = transMeta.getDatabase(connr);
    logDebug(BaseMessages.getString(PKG, "DimensionLookupDialog.Log.LookingAtConnection") + inf.toString());
    DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
    std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
    if (std.open()) {
        wSchema.setText(Const.NVL(std.getSchemaName(), ""));
        wTable.setText(Const.NVL(std.getTableName(), ""));
        setTableFieldCombo();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)

Example 27 with DatabaseExplorerDialog

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

the class JobEntryEvalTableContentDialog method getTableName.

private void getTableName() {
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) {
        DatabaseMeta inf = jobMeta.getDatabase(connr);
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, jobMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchemaname.getText(), wTablename.getText());
        if (std.open()) {
            wTablename.setText(Const.NVL(std.getTableName(), ""));
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ConnectionError2.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 28 with DatabaseExplorerDialog

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

the class LucidDBBulkLoaderDialog method getTableName.

private void getTableName() {
    DatabaseMeta inf = null;
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) {
        inf = transMeta.getDatabase(connr);
    }
    if (inf != null) {
        logDebug(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.Log.LookingAtConnection") + inf.toString());
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
        if (std.open()) {
            wSchema.setText(Const.NVL(std.getSchemaName(), ""));
            wTable.setText(Const.NVL(std.getTableName(), ""));
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogTitle"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 29 with DatabaseExplorerDialog

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

the class TableInputDialog method getSQL.

private void getSQL() {
    DatabaseMeta inf = transMeta.findDatabase(wConnection.getText());
    if (inf != null) {
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
        if (std.open()) {
            String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
            wSQL.setText(sql);
            MessageBox yn = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            yn.setMessage(BaseMessages.getString(PKG, "TableInputDialog.IncludeFieldNamesInSQL"));
            yn.setText(BaseMessages.getString(PKG, "TableInputDialog.DialogCaptionQuestion"));
            int id = yn.open();
            switch(id) {
                case SWT.CANCEL:
                    break;
                case SWT.NO:
                    wSQL.setText(sql);
                    break;
                case SWT.YES:
                    Database db = new Database(loggingObject, inf);
                    db.shareVariablesWith(transMeta);
                    try {
                        db.connect();
                        RowMetaInterface fields = db.getQueryFields(sql, false);
                        if (fields != null) {
                            sql = "SELECT" + Const.CR;
                            for (int i = 0; i < fields.size(); i++) {
                                ValueMetaInterface field = fields.getValueMeta(i);
                                if (i == 0) {
                                    sql += "  ";
                                } else {
                                    sql += ", ";
                                }
                                sql += inf.quoteField(field.getName()) + Const.CR;
                            }
                            sql += "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
                            wSQL.setText(sql);
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                            mb.setMessage(BaseMessages.getString(PKG, "TableInputDialog.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "TableInputDialog.PerhapsNoPermissions"));
                            mb.setText(BaseMessages.getString(PKG, "TableInputDialog.DialogCaptionError2"));
                            mb.open();
                        }
                    } catch (KettleException e) {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                        mb.setText(BaseMessages.getString(PKG, "TableInputDialog.DialogCaptionError3"));
                        mb.setMessage(BaseMessages.getString(PKG, "TableInputDialog.AnErrorOccurred") + Const.CR + e.getMessage());
                        mb.open();
                    } finally {
                        db.disconnect();
                    }
                    break;
                default:
                    break;
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "TableInputDialog.ConnectionNoLongerAvailable"));
        mb.setText(BaseMessages.getString(PKG, "TableInputDialog.DialogCaptionError4"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 MessageBox (org.eclipse.swt.widgets.MessageBox)27 Database (org.pentaho.di.core.database.Database)3 KettleException (org.pentaho.di.core.exception.KettleException)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 HasDatabasesInterface (org.pentaho.di.trans.HasDatabasesInterface)1