Search in sources :

Example 51 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class ProgressLoaderVisualizer method overwriteMonitor.

@Override
public DBRProgressMonitor overwriteMonitor(DBRProgressMonitor monitor) {
    DBRProgressMonitor progressMonitor = new ProxyProgressMonitor(monitor) {

        @Override
        public void subTask(String name) {
            progressMessage = name;
            super.subTask(name);
        }
    };
    return progressMonitor;
}
Also used : DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ProxyProgressMonitor(org.jkiss.dbeaver.model.runtime.ProxyProgressMonitor)

Example 52 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class DatabaseNavigatorTree method expandNodeOnLoad.

private void expandNodeOnLoad(final DBNNode node) {
    if (node instanceof DBNDataSource && DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_EXPAND_ON_CONNECT)) {
        try {
            DBRRunnableWithResult<DBNNode> runnable = new DBRRunnableWithResult<DBNNode>() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        result = findActiveNode(monitor, node);
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            DBeaverUI.runInProgressService(runnable);
            if (runnable.getResult() != null) {
                showNode(runnable.getResult());
                treeViewer.expandToLevel(runnable.getResult(), 1);
            }
        } catch (InvocationTargetException e) {
            log.error("Can't expand node", e.getTargetException());
        } catch (InterruptedException e) {
        // skip it
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 53 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class PostgreCreateSchemaDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    final Composite composite = super.createDialogArea(parent);
    final Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    final Text nameText = UIUtils.createLabelText(group, "Schema name", "");
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            name = nameText.getText();
            getButton(IDialogConstants.OK_ID).setEnabled(!name.isEmpty());
        }
    });
    final Combo userCombo = UIUtils.createLabelCombo(group, "Owner", SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    userCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            owner = allUsers.get(userCombo.getSelectionIndex());
        }
    });
    new AbstractJob("Load users") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                final List<String> userNames = new ArrayList<>();
                allUsers = new ArrayList<>(database.getUsers(monitor));
                final PostgreRole dba = database.getDBA(monitor);
                final String defUserName = dba == null ? "" : dba.getName();
                DBeaverUI.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        for (PostgreRole authId : allUsers) {
                            String name = authId.getName();
                            userCombo.add(name);
                            if (name.equals(defUserName)) {
                                owner = authId;
                            }
                        }
                        userCombo.setText(defUserName);
                    }
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return composite;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) PostgreRole(org.jkiss.dbeaver.ext.postgresql.model.PostgreRole) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 54 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class PostgresRolePrivilegesEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    this.boldFont = UIUtils.makeBoldFont(parent.getFont());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            UIUtils.dispose(boldFont);
        }
    });
    this.pageControl = new PageControl(parent);
    this.pageControl.createOrSubstituteProgressPanel(getSite());
    this.pageControl.setDoubleClickHandler(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            final ISelection selection = pageControl.getSelectionProvider().getSelection();
            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                final PostgrePermission element = (PostgrePermission) ((IStructuredSelection) selection).getFirstElement();
                new AbstractJob("Open target object") {

                    @Override
                    protected IStatus run(DBRProgressMonitor monitor) {
                        try {
                            final PostgreObject targetObject = element.getTargetObject(monitor);
                            if (targetObject != null) {
                                DBeaverUI.syncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        NavigatorHandlerObjectOpen.openEntityEditor(targetObject);
                                    }
                                });
                            }
                        } catch (DBException e) {
                            return GeneralUtils.makeExceptionStatus(e);
                        }
                        return Status.OK_STATUS;
                    }
                }.schedule();
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DBException(org.jkiss.dbeaver.DBException) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 55 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class PostgreStructureAssistant method findTableColumnsByMask.

private void findTableColumnsByMask(JDBCSession session, @Nullable final List<PostgreSchema> schema, String columnNameMask, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
    DBRProgressMonitor monitor = session.getProgressMonitor();
    // Load constraints
    try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT x.attname,x.attrelid,x.atttypid,c.relnamespace " + "FROM pg_catalog.pg_attribute x, pg_catalog.pg_class c\n" + "WHERE c.oid=x.attrelid AND x.attname " + (caseSensitive ? "LIKE" : "ILIKE") + " ? " + (CommonUtils.isEmpty(schema) ? "" : " AND c.relnamespace IN (" + SQLUtils.generateParamList(schema.size()) + ")") + " ORDER BY x.attname LIMIT " + maxResults)) {
        dbStat.setString(1, columnNameMask);
        if (!CommonUtils.isEmpty(schema)) {
            PostgreUtils.setArrayParameter(dbStat, 2, schema);
        }
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            int tableNum = maxResults;
            while (dbResult.next() && tableNum-- > 0) {
                if (monitor.isCanceled()) {
                    break;
                }
                final long schemaId = JDBCUtils.safeGetLong(dbResult, "relnamespace");
                final long tableId = JDBCUtils.safeGetLong(dbResult, "attrelid");
                final String attributeName = JDBCUtils.safeGetString(dbResult, "attname");
                final PostgreSchema constrSchema = dataSource.getDefaultInstance().getSchema(session.getProgressMonitor(), schemaId);
                if (constrSchema == null) {
                    log.debug("Schema '" + schemaId + "' not found");
                    continue;
                }
                objects.add(new AbstractObjectReference(attributeName, constrSchema, null, PostgreTableBase.class, RelationalObjectType.TYPE_TABLE) {

                    @Override
                    public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
                        final PostgreTableBase table = PostgreUtils.getObjectById(monitor, constrSchema.tableCache, constrSchema, tableId);
                        if (table == null) {
                            throw new DBException("Table '" + tableId + "' not found in schema '" + constrSchema.getName() + "'");
                        }
                        return table.getAttribute(monitor, attributeName);
                    }
                });
            }
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) AbstractObjectReference(org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)79 DBException (org.jkiss.dbeaver.DBException)45 InvocationTargetException (java.lang.reflect.InvocationTargetException)36 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)30 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 ArrayList (java.util.ArrayList)8 IStatus (org.eclipse.core.runtime.IStatus)8 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 List (java.util.List)5 NotNull (org.jkiss.code.NotNull)5 File (java.io.File)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4