Search in sources :

Example 1 with JDBCTable

use of org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable in project dbeaver by serge-rider.

the class PostgreBackupWizardPageObjects method loadTables.

private void loadTables(final PostgreSchema catalog) {
    if (catalog != null) {
        curSchema = catalog;
    }
    if (curSchema == null) {
        return;
    }
    final boolean isCatalogChecked = isChecked(curSchema);
    final Set<PostgreTableBase> checkedObjects = this.checkedObjects.get(curSchema);
    new AbstractJob("Load '" + curSchema.getName() + "' tables") {

        {
            setUser(true);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            monitor.beginTask("Collect tables", 1);
            try {
                monitor.subTask("Collect tables to dump");
                final List<PostgreTableBase> objects = new ArrayList<>();
                for (JDBCTable table : curSchema.getTables(monitor)) {
                    if (table instanceof PostgreTableBase) {
                        objects.add((PostgreTableBase) table);
                    }
                }
                if (wizard.getSettings().isShowViews()) {
                    objects.addAll(curSchema.getViews(monitor));
                }
                objects.sort(DBUtils.nameComparator());
                UIUtils.syncExec(() -> {
                    tablesTable.removeAll();
                    for (PostgreTableBase table : objects) {
                        TableItem item = new TableItem(tablesTable, SWT.NONE);
                        item.setImage(DBeaverIcons.getImage(table.isView() ? DBIcon.TREE_VIEW : DBIcon.TREE_TABLE));
                        item.setText(0, table.getName());
                        item.setData(table);
                        item.setChecked(isCatalogChecked && (checkedObjects == null || checkedObjects.contains(table)));
                    }
                });
            } catch (DBException e) {
                DBWorkbench.getPlatformUI().showError("Table list", "Can't read table list", e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) JDBCTable(org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 2 with JDBCTable

use of org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable in project dbeaver by dbeaver.

the class PostgreBackupWizardPageObjects method loadTables.

private void loadTables(final PostgreSchema catalog) {
    if (catalog != null) {
        curSchema = catalog;
    }
    if (curSchema == null) {
        return;
    }
    final boolean isCatalogChecked = isChecked(curSchema);
    final Set<PostgreTableBase> checkedObjects = this.checkedObjects.get(curSchema);
    new AbstractJob("Load '" + curSchema.getName() + "' tables") {

        {
            setUser(true);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            monitor.beginTask("Collect tables", 1);
            try {
                monitor.subTask("Collect tables to dump");
                final List<PostgreTableBase> objects = new ArrayList<>();
                for (JDBCTable table : curSchema.getTables(monitor)) {
                    if (table instanceof PostgreTableBase) {
                        objects.add((PostgreTableBase) table);
                    }
                }
                if (wizard.getSettings().isShowViews()) {
                    objects.addAll(curSchema.getViews(monitor));
                }
                objects.sort(DBUtils.nameComparator());
                UIUtils.syncExec(() -> {
                    tablesTable.removeAll();
                    for (PostgreTableBase table : objects) {
                        TableItem item = new TableItem(tablesTable, SWT.NONE);
                        item.setImage(DBeaverIcons.getImage(table.isView() ? DBIcon.TREE_VIEW : DBIcon.TREE_TABLE));
                        item.setText(0, table.getName());
                        item.setData(table);
                        item.setChecked(isCatalogChecked && (checkedObjects == null || checkedObjects.contains(table)));
                    }
                });
            } catch (DBException e) {
                DBWorkbench.getPlatformUI().showError("Table list", "Can't read table list", e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) JDBCTable(org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 DBException (org.jkiss.dbeaver.DBException)2 PostgreTableBase (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase)2 JDBCTable (org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2