Search in sources :

Example 6 with AbstractJob

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

the class SQLEditor method dumpServerOutput.

private void dumpServerOutput(@NotNull final DBCExecutionContext executionContext, @NotNull final DBCServerOutputReader outputReader) {
    new AbstractJob("Dump server output") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            final StringWriter dump = new StringWriter();
            try {
                outputReader.readServerOutput(monitor, executionContext, new PrintWriter(dump, true));
                final String dumpString = dump.toString();
                if (!dumpString.isEmpty()) {
                    DBeaverUI.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (outputViewer.isDisposed()) {
                                return;
                            }
                            try {
                                IOUtils.copyText(new StringReader(dumpString), outputViewer.getOutputWriter());
                            } catch (IOException e) {
                                log.error(e);
                            }
                            if (outputViewer.isHasNewOutput()) {
                                outputViewer.scrollToEnd();
                                CTabItem outputItem = UIUtils.getTabItem(resultTabs, outputViewer);
                                if (outputItem != null && outputItem != resultTabs.getSelection()) {
                                    outputItem.setImage(IMG_OUTPUT_ALERT);
                                } else {
                                    toolOutputItem.setImage(IMG_OUTPUT_ALERT);
                                }
                            }
                        }
                    });
                }
            } catch (Exception e) {
                log.error(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) CTabItem(org.eclipse.swt.custom.CTabItem) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 7 with AbstractJob

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

the class NavigatorHandlerRefresh method refreshNavigator.

public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
    Job refreshJob = new AbstractJob("Refresh navigator object(s)") {

        public Throwable error;

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (error != null) {
                        UIUtils.showErrorDialog(null, "Refresh", "Error refreshing node", error);
                    }
                }
            });
            Set<DBNNode> refreshedSet = new HashSet<>();
            for (DBNNode node : refreshObjects) {
                if (node.isDisposed() || node.isLocked()) {
                    // Skip locked nodes
                    continue;
                }
                // Check this node was already refreshed
                if (!refreshedSet.isEmpty()) {
                    boolean skip = false;
                    for (DBNNode refreshed : refreshedSet) {
                        if (node == refreshed || node.isChildOf(refreshed)) {
                            skip = true;
                            break;
                        }
                    }
                    if (skip) {
                        continue;
                    }
                }
                setName("Refresh '" + node.getNodeName() + "'...");
                try {
                    DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
                    if (refreshed != null) {
                        refreshedSet.add(refreshed);
                    }
                } catch (Throwable ex) {
                    error = ex;
                }
            }
            return Status.OK_STATUS;
        }
    };
    refreshJob.setUser(true);
    refreshJob.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob)

Example 8 with AbstractJob

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

the class SpreadsheetPresentation method navigateLink.

///////////////////////////////////////////////
// Links
public void navigateLink(@NotNull GridCell cell, final int state) {
    boolean recordMode = controller.isRecordMode();
    final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
    final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
    Object value = controller.getModel().getCellValue(attr, row);
    if (DBUtils.isNullValue(value)) {
        log.warn("Can't navigate to NULL value");
        return;
    }
    if (!CommonUtils.isEmpty(attr.getReferrers())) {
        // Navigate association
        new AbstractJob("Navigate association") {

            @Override
            protected IStatus run(DBRProgressMonitor monitor) {
                try {
                    boolean ctrlPressed = (state & SWT.CTRL) == SWT.CTRL;
                    controller.navigateAssociation(monitor, attr, row, ctrlPressed);
                } catch (DBException e) {
                    return GeneralUtils.makeExceptionStatus(e);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    } else {
        // Navigate hyperlink
        String strValue = attr.getValueHandler().getValueDisplayString(attr, value, DBDDisplayFormat.UI);
        UIUtils.launchProgram(strValue);
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 9 with AbstractJob

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

the class MySQLExportWizardPageObjects method loadTables.

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

        {
            setUser(true);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                final List<MySQLTableBase> objects = new ArrayList<>();
                objects.addAll(curCatalog.getTables(monitor));
                if (wizard.showViews) {
                    objects.addAll(curCatalog.getViews(monitor));
                }
                Collections.sort(objects, DBUtils.nameComparator());
                DBeaverUI.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        tablesTable.removeAll();
                        for (MySQLTableBase 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) MySQLTableBase(org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 10 with AbstractJob

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

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