Search in sources :

Example 1 with SQLScriptStatusDialog

use of org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog in project dbeaver by serge-rider.

the class OracleMaintenanceDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<T> getScriptListener() {
    return new SQLScriptStatusDialog<T>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull T object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
        }

        @Override
        public void endObjectProcessing(@NotNull T object, Exception error) {
            super.endObjectProcessing(object, error);
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                treeItem.setText(1, error == null ? "Done" : error.getMessage());
            }
        }
    };
}
Also used : SWT(org.eclipse.swt.SWT) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) Nullable(org.jkiss.code.Nullable) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 2 with SQLScriptStatusDialog

use of org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog in project dbeaver by serge-rider.

the class DB2BaseTableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<DB2Table> getScriptListener() {
    final int nbExtraColumns = getNumberExtraResultingColumns();
    return new SQLScriptStatusDialog<DB2Table>(getShell(), getTitle() + " " + DB2Messages.dialog_table_tools_progress, null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText(DB2Messages.dialog_table_tools_result);
            for (int i = 0; i < nbExtraColumns; i++) {
                new TreeColumn(objectTree, SWT.NONE);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull DB2Table db2Table, Exception exception) {
            TreeItem treeItem = getTreeItem(db2Table);
            if (exception == null) {
                treeItem.setText(1, DB2Messages.dialog_table_tools_success_title);
            } else {
                treeItem.setText(1, exception.getMessage());
            }
            UIUtils.packColumns(treeItem.getParent(), false, null);
        }

        // DF: This method is for tools that return resultsets
        @Override
        public void processObjectResults(@NotNull DB2Table db2Table, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            // Retrive column names
            JDBCResultSetMetaDataImpl rsMetaData = (JDBCResultSetMetaDataImpl) resultSet.getMeta();
            try {
                TreeItem treeItem = getTreeItem(db2Table);
                Font f = UIUtils.makeBoldFont(treeItem.getFont());
                if (treeItem != null) {
                    // Display the column names
                    TreeItem subItem = null;
                    subItem = new TreeItem(treeItem, SWT.NONE);
                    subItem.setFont(f);
                    for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
                        subItem.setText(i, rsMetaData.getColumnName(i + 1));
                        subItem.setGrayed(true);
                    }
                    // Display the data for each row
                    while (resultSet.nextRow()) {
                        subItem = new TreeItem(treeItem, SWT.NONE);
                        for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
                            subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
                        }
                    }
                    treeItem.setExpanded(true);
                }
            } catch (SQLException e) {
                throw new DBCException(e.getMessage());
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCResultSetMetaDataImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCResultSetMetaDataImpl) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) Font(org.eclipse.swt.graphics.Font) DB2Table(org.jkiss.dbeaver.ext.db2.model.DB2Table) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 3 with SQLScriptStatusDialog

use of org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog in project dbeaver by serge-rider.

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<MySQLTable> getScriptListener() {
    return new SQLScriptStatusDialog<MySQLTable>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull MySQLTable object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            Map<String, String> statusMap = new LinkedHashMap<>();
            while (resultSet.nextRow()) {
                statusMap.put(CommonUtils.toString(resultSet.getAttributeValue("Msg_type")), CommonUtils.toString(resultSet.getAttributeValue("Msg_text")));
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null && !statusMap.isEmpty()) {
                if (statusMap.size() == 1) {
                    treeItem.setText(1, statusMap.values().iterator().next());
                } else {
                    String statusText = statusMap.get("status");
                    if (!CommonUtils.isEmpty(statusText)) {
                        treeItem.setText(1, statusText);
                    }
                    for (Map.Entry<String, String> status : statusMap.entrySet()) {
                        if (!status.getKey().equals("status")) {
                            TreeItem subItem = new TreeItem(treeItem, SWT.NONE);
                            subItem.setText(0, status.getKey());
                            subItem.setText(1, status.getValue());
                        }
                    }
                    treeItem.setExpanded(true);
                }
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) MySQLTable(org.jkiss.dbeaver.ext.mysql.model.MySQLTable) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) LinkedHashMap(java.util.LinkedHashMap) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Nullable(org.jkiss.code.Nullable)

Example 4 with SQLScriptStatusDialog

use of org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog in project dbeaver by serge-rider.

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
    return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (statement == null) {
                return;
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                try {
                    int warnNum = 0;
                    SQLWarning warning = ((JDBCStatement) statement).getWarnings();
                    while (warning != null) {
                        if (warnNum == 0) {
                            treeItem.setText(1, warning.getMessage());
                        } else {
                            TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
                            warnItem.setText(0, "");
                            warnItem.setText(1, warning.getMessage());
                        }
                        warnNum++;
                        warning = warning.getNextWarning();
                    }
                    if (warnNum == 0) {
                        treeItem.setText(1, "Done");
                    }
                } catch (SQLException e) {
                // ignore
                }
                treeItem.setExpanded(true);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
            super.endObjectProcessing(object, error);
            if (error != null) {
                TreeItem treeItem = getTreeItem(object);
                if (treeItem != null) {
                    treeItem.setText(1, error.getMessage());
                }
            }
        }
    };
}
Also used : SQLWarning(java.sql.SQLWarning) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 5 with SQLScriptStatusDialog

use of org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog in project dbeaver by serge-rider.

the class ExasolBaseTableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<ExasolTableBase> getScriptListener() {
    final int nbExtraColumns = getNumberExtraResultingColumns();
    return new SQLScriptStatusDialog<ExasolTableBase>(getShell(), getTitle() + " " + ExasolMessages.dialog_table_tools_progress, null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText(ExasolMessages.dialog_table_tools_result);
            for (int i = 0; i < nbExtraColumns; i++) {
                new TreeColumn(objectTree, SWT.NONE);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull ExasolTableBase exasolTable, Exception exception) {
            TreeItem treeItem = getTreeItem(exasolTable);
            if (exception == null) {
                treeItem.setText(1, ExasolMessages.dialog_table_tools_success_title);
            } else {
                treeItem.setText(1, exception.getMessage());
            }
            UIUtils.packColumns(treeItem.getParent(), false, null);
        }

        // DF: This method is for tools that return resultsets
        @Override
        public void processObjectResults(@NotNull ExasolTableBase exasolTable, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            // Retrieve column names
            DBCResultSetMetaData rsMetaData = resultSet.getMeta();
            try {
                TreeItem treeItem = getTreeItem(exasolTable);
                Font f = UIUtils.makeBoldFont(treeItem.getFont());
                if (treeItem != null) {
                    // Display the column names
                    TreeItem subItem = null;
                    subItem = new TreeItem(treeItem, SWT.NONE);
                    subItem.setFont(f);
                    for (DBCAttributeMetaData column : rsMetaData.getAttributes()) {
                        subItem.setText(column.getOrdinalPosition(), column.getName());
                        subItem.setGrayed(true);
                    }
                    // Display the data for each row
                    while (resultSet.nextRow()) {
                        subItem = new TreeItem(treeItem, SWT.NONE);
                        for (int i = 0; i < rsMetaData.getAttributes().size(); i++) {
                            subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
                            i++;
                        }
                    }
                    treeItem.setExpanded(true);
                }
            } catch (Exception e) {
                throw new DBCException(e.getMessage());
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) NotNull(org.jkiss.code.NotNull) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) Font(org.eclipse.swt.graphics.Font) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) Nullable(org.jkiss.code.Nullable)

Aggregations

Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 Nullable (org.jkiss.code.Nullable)5 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)5 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)4 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)3 SQLException (java.sql.SQLException)2 Font (org.eclipse.swt.graphics.Font)2 SQLWarning (java.sql.SQLWarning)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SWT (org.eclipse.swt.SWT)1 DB2Table (org.jkiss.dbeaver.ext.db2.model.DB2Table)1 ExasolTableBase (org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase)1 MySQLTable (org.jkiss.dbeaver.ext.mysql.model.MySQLTable)1 PostgreObject (org.jkiss.dbeaver.ext.postgresql.model.PostgreObject)1 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)1