Search in sources :

Example 11 with AbstractJob

use of org.jkiss.dbeaver.model.runtime.AbstractJob 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 12 with AbstractJob

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

the class RuntimeUtils method runTask.

public static boolean runTask(final DBRRunnableWithProgress task, String taskName, final long waitTime) {
    final MonitoringTask monitoringTask = new MonitoringTask(task);
    Job monitorJob = new AbstractJob(taskName) {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                monitoringTask.run(monitor);
            } catch (InvocationTargetException e) {
                log.error(getName() + " - error", e.getTargetException());
                return Status.OK_STATUS;
            } catch (InterruptedException e) {
            // do nothing
            }
            return Status.OK_STATUS;
        }
    };
    monitorJob.schedule();
    // Wait for job to finish
    long startTime = System.currentTimeMillis();
    if (waitTime > 0) {
        while (!monitoringTask.finished && System.currentTimeMillis() - startTime < waitTime) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    return monitoringTask.finished;
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with AbstractJob

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

the class SQLEditor method runPostExecuteActions.

private void runPostExecuteActions(@Nullable SQLQueryResult result) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        final DBPDataSource dataSource = executionContext.getDataSource();
        // Dump server output
        DBCServerOutputReader outputReader = DBUtils.getAdapter(DBCServerOutputReader.class, dataSource);
        if (outputReader == null && result != null) {
            outputReader = new DefaultServerOutputReader(result);
        }
        if (outputReader != null && outputReader.isServerOutputEnabled()) {
            dumpServerOutput(executionContext, outputReader);
        }
        // Refresh active object
        if (result == null || !result.hasError() && getActivePreferenceStore().getBoolean(SQLPreferenceConstants.REFRESH_DEFAULTS_AFTER_EXECUTE)) {
            final DBSObjectSelector objectSelector = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
            if (objectSelector != null) {
                new AbstractJob("Refresh default object") {

                    @Override
                    protected IStatus run(DBRProgressMonitor monitor) {
                        try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Refresh default object")) {
                            objectSelector.refreshDefaultObject(session);
                        } catch (Exception e) {
                            log.error(e);
                        }
                        return Status.OK_STATUS;
                    }
                }.schedule();
            }
        }
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Aggregations

AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)13 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)12 DBException (org.jkiss.dbeaver.DBException)9 IStatus (org.eclipse.core.runtime.IStatus)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 List (java.util.List)4 ArrayList (java.util.ArrayList)2 Job (org.eclipse.core.runtime.jobs.Job)2 DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)2 Collection (java.util.Collection)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CTabItem (org.eclipse.swt.custom.CTabItem)1