Search in sources :

Example 1 with PostgreDataSource

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

the class PostgreSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer(this, parent, new PostgreSessionManager((PostgreDataSource) executionContext.getDataSource())) {

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            terminateQueryAction.setEnabled(session != null && !CommonUtils.isEmpty(session.getActiveQuery()));
        }
    };
}
Also used : SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) PostgreSessionManager(org.jkiss.dbeaver.ext.postgresql.model.session.PostgreSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 2 with PostgreDataSource

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource 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)

Aggregations

PostgreDataSource (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource)2 IContributionManager (org.eclipse.jface.action.IContributionManager)1 Separator (org.eclipse.jface.action.Separator)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 DBException (org.jkiss.dbeaver.DBException)1 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)1 PostgreTableBase (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase)1 PostgreSessionManager (org.jkiss.dbeaver.ext.postgresql.model.session.PostgreSessionManager)1 DBAServerSession (org.jkiss.dbeaver.model.admin.sessions.DBAServerSession)1 DBAServerSessionManager (org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 CustomSashForm (org.jkiss.dbeaver.ui.controls.CustomSashForm)1 SessionManagerViewer (org.jkiss.dbeaver.ui.views.session.SessionManagerViewer)1