Search in sources :

Example 1 with PostgreTableBase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase 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) {
            try {
                final List<PostgreTableBase> objects = new ArrayList<>();
                objects.addAll(curSchema.getTables(monitor));
                if (wizard.showViews) {
                    objects.addAll(curSchema.getViews(monitor));
                }
                Collections.sort(objects, DBUtils.nameComparator());
                DBeaverUI.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        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) {
                UIUtils.showErrorDialog(null, "Table list", "Can't read table list", e);
            }
            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) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 2 with PostgreTableBase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase in project dbeaver by serge-rider.

the class PostgreBackupWizard method fillProcessParameters.

@Override
public void fillProcessParameters(List<String> cmd, PostgreDatabaseBackupInfo arg) throws IOException {
    super.fillProcessParameters(cmd, arg);
    cmd.add("--format=" + format.getId());
    if (!CommonUtils.isEmpty(compression)) {
        cmd.add("--compress=" + compression);
    }
    if (!CommonUtils.isEmpty(encoding)) {
        cmd.add("--encoding=" + encoding);
    }
    // Objects
    if (objects.isEmpty()) {
    // no dump
    } else if (!CommonUtils.isEmpty(arg.getTables())) {
        for (PostgreTableBase table : arg.getTables()) {
            cmd.add("-t");
            cmd.add(table.getFullyQualifiedName(DBPEvaluationContext.DDL));
        }
    } else if (!CommonUtils.isEmpty(arg.getSchemas())) {
        for (PostgreSchema schema : arg.getSchemas()) {
            cmd.add("-n");
            cmd.add(schema.getName());
        }
    }
}
Also used : PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 3 with PostgreTableBase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase in project dbeaver by serge-rider.

the class PostgreBackupWizardPageObjects method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1);
    Group objectsGroup = UIUtils.createControlGroup(composite, "Objects", 1, GridData.FILL_HORIZONTAL, 0);
    objectsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm sash = new CustomSashForm(objectsGroup, SWT.VERTICAL);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        Composite catPanel = UIUtils.createPlaceholder(sash, 1);
        catPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
        schemasTable = new Table(catPanel, SWT.BORDER | SWT.CHECK);
        schemasTable.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                PostgreSchema catalog = (PostgreSchema) item.getData();
                if (event.detail == SWT.CHECK) {
                    schemasTable.select(schemasTable.indexOf(item));
                    checkedObjects.remove(catalog);
                }
                loadTables(catalog);
                updateState();
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 50;
        schemasTable.setLayoutData(gd);
        Composite buttonsPanel = UIUtils.createPlaceholder(catPanel, 3, 5);
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        new Label(buttonsPanel, SWT.NONE).setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
        createCheckButtons(buttonsPanel, schemasTable);
    }
    final Button exportViewsCheck;
    {
        Composite tablesPanel = UIUtils.createPlaceholder(sash, 1);
        tablesPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
        tablesTable = new Table(tablesPanel, SWT.BORDER | SWT.CHECK);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 50;
        tablesTable.setLayoutData(gd);
        tablesTable.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event event) {
                if (event.detail == SWT.CHECK) {
                    updateCheckedTables();
                    updateState();
                }
            }
        });
        Composite buttonsPanel = UIUtils.createPlaceholder(tablesPanel, 3, 5);
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        exportViewsCheck = UIUtils.createCheckbox(buttonsPanel, "Show views", false);
        exportViewsCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                wizard.showViews = exportViewsCheck.getSelection();
                loadTables(null);
            }
        });
        exportViewsCheck.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
        createCheckButtons(buttonsPanel, tablesTable);
    }
    dataSource = null;
    Set<PostgreSchema> activeCatalogs = new LinkedHashSet<>();
    for (DBSObject object : wizard.getDatabaseObjects()) {
        if (object instanceof PostgreSchema) {
            activeCatalogs.add((PostgreSchema) object);
            dataSource = ((PostgreSchema) object).getDataSource();
        } else if (object instanceof PostgreTableBase) {
            PostgreSchema catalog = ((PostgreTableBase) object).getContainer();
            dataSource = catalog.getDataSource();
            activeCatalogs.add(catalog);
            Set<PostgreTableBase> tables = checkedObjects.get(catalog);
            if (tables == null) {
                tables = new HashSet<>();
                checkedObjects.put(catalog, tables);
            }
            tables.add((PostgreTableBase) object);
            if (((PostgreTableBase) object).isView()) {
                wizard.showViews = true;
                exportViewsCheck.setSelection(true);
            }
        } else if (object.getDataSource() instanceof PostgreDataSource) {
            dataSource = (PostgreDataSource) object.getDataSource();
        }
    }
    if (dataSource != null) {
        boolean tablesLoaded = false;
        try {
            for (PostgreSchema schema : dataSource.getDefaultInstance().getSchemas(VoidProgressMonitor.INSTANCE)) {
                if (schema.isSystem() || schema.isUtility()) {
                    continue;
                }
                TableItem item = new TableItem(schemasTable, SWT.NONE);
                item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
                item.setText(0, schema.getName());
                item.setData(schema);
                if (activeCatalogs.contains(schema)) {
                    item.setChecked(true);
                    schemasTable.select(schemasTable.indexOf(item));
                    if (!tablesLoaded) {
                        loadTables(schema);
                        tablesLoaded = true;
                    }
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
    }
    updateState();
    setControl(composite);
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SashForm(org.eclipse.swt.custom.SashForm) CustomSashForm(org.jkiss.dbeaver.ui.controls.CustomSashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) CustomSashForm(org.jkiss.dbeaver.ui.controls.CustomSashForm) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 4 with PostgreTableBase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase in project dbeaver by serge-rider.

the class PostgreBackupWizardPageObjects method saveState.

public void saveState() {
    wizard.objects.clear();
    List<PostgreSchema> schemas = new ArrayList<>();
    List<PostgreTableBase> tables = new ArrayList<>();
    for (TableItem item : schemasTable.getItems()) {
        if (item.getChecked()) {
            PostgreSchema schema = (PostgreSchema) item.getData();
            Set<PostgreTableBase> checkedTables = checkedObjects.get(schema);
            if (CommonUtils.isEmpty(checkedTables)) {
                // All tables checked
                schemas.add(schema);
            } else {
                // Only a few tables checked
                tables.addAll(checkedTables);
            }
        }
    }
    PostgreDatabaseBackupInfo info = new PostgreDatabaseBackupInfo(dataSource.getDefaultInstance(), schemas, tables);
    wizard.objects.add(info);
}
Also used : PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Aggregations

PostgreTableBase (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase)4 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)3 DBException (org.jkiss.dbeaver.DBException)2 List (java.util.List)1 IStatus (org.eclipse.core.runtime.IStatus)1 SashForm (org.eclipse.swt.custom.SashForm)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 PostgreDataSource (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource)1 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 CustomSashForm (org.jkiss.dbeaver.ui.controls.CustomSashForm)1