Search in sources :

Example 46 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class NavigatorHandlerSetActiveObject method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (element instanceof DBNDatabaseNode) {
            final DBNDatabaseNode databaseNode = (DBNDatabaseNode) element;
            final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
            if (activeContainer != null) {
                TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            activeContainer.setDefaultObject(monitor, databaseNode.getObject());
                        } catch (DBException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) ISelection(org.eclipse.jface.viewers.ISelection) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 47 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class TasksJob method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    monitor.beginTask(getName(), tasks.size());
    boolean ignoreErrors = false;
    for (int i = 0; i < tasks.size(); ) {
        DBRRunnableWithProgress task = tasks.get(i);
        if (monitor.isCanceled()) {
            break;
        }
        try {
            task.run(monitor);
        } catch (InvocationTargetException e) {
            if (tasks.size() == 1) {
                DBUserInterface.getInstance().showError(getName(), null, e.getTargetException());
            } else if (!ignoreErrors) {
                boolean keepRunning = true;
                switch(ExecutionQueueErrorJob.showError(getName(), e.getTargetException(), true)) {
                    case STOP:
                        keepRunning = false;
                        break;
                    case RETRY:
                        // just make it again
                        continue;
                    case IGNORE:
                        // Just do nothing
                        break;
                    case IGNORE_ALL:
                        ignoreErrors = true;
                        break;
                }
                if (!keepRunning) {
                    break;
                }
            }
        } catch (InterruptedException e) {
        // Ignore
        }
        monitor.worked(1);
        i++;
    }
    monitor.done();
    return Status.OK_STATUS;
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 48 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class CompareObjectsWizard method performFinish.

@Override
public boolean performFinish() {
    // Save settings
    getSettings().saveTo(getDialogSettings());
    showError(null);
    // Compare
    final CompareObjectsExecutor executor = new CompareObjectsExecutor(settings);
    try {
        DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    CompareReport report = generateReport(monitor, executor);
                    renderReport(monitor, report);
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
        UIUtils.showMessageBox(getShell(), "Objects compare", "Objects compare finished", SWT.ICON_INFORMATION);
    } catch (InvocationTargetException e) {
        if (executor.getInitializeError() != null) {
            showError(executor.getInitializeError().getMessage());
        } else {
            log.error(e.getTargetException());
            showError(e.getTargetException().getMessage());
        }
        return false;
    } catch (InterruptedException e) {
        showError("Compare interrupted");
        return false;
    } finally {
        executor.dispose();
    }
    // Done
    return true;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 49 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class ObjectPropertiesEditor method makeDatabaseEditorTabs.

private void makeDatabaseEditorTabs(final IDatabaseEditor part, final List<TabbedFolderInfo> tabList) {
    final DBNDatabaseNode node = part.getEditorInput().getNavigatorNode();
    if (node == null) {
        return;
    }
    final DBSObject object = node.getObject();
    if (!node.getMeta().isStandaloneNode()) {
        // Collect tabs from navigator tree model
        DBRRunnableWithProgress tabsCollector = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) {
                collectNavigatorTabs(monitor, part, node, tabList);
            }
        };
        try {
            if (node.needsInitialization()) {
                DBeaverUI.runInProgressService(tabsCollector);
            } else {
                tabsCollector.run(new VoidProgressMonitor());
            }
        } catch (InvocationTargetException e) {
            log.error(e.getTargetException());
        } catch (InterruptedException e) {
        // just go further
        }
    }
    // Query for entity editors
    List<EntityEditorDescriptor> editors = EntityEditorsRegistry.getInstance().getEntityEditors(object, this, null);
    if (!CommonUtils.isEmpty(editors)) {
        for (EntityEditorDescriptor descriptor : editors) {
            if (descriptor.getType() == EntityEditorDescriptor.Type.folder) {
                tabList.add(new TabbedFolderInfo(descriptor.getId(), descriptor.getName(), descriptor.getIcon(), descriptor.getDescription(), descriptor.isEmbeddable(), new TabbedFolderPageEditor(this, descriptor)));
            }
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 50 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class AttributesSelectorPage method fillAttributes.

protected void fillAttributes(final DBSEntity entity) {
    // Collect attributes
    final List<DBSEntityAttribute> attributes = new ArrayList<>();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
                        if (!DBUtils.isHiddenObject(attr)) {
                            attributes.add(attr);
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_columns_select_error_load_columns_title, CoreMessages.dialog_struct_columns_select_error_load_columns_message, e.getTargetException());
    } catch (InterruptedException e) {
    // do nothing
    }
    for (DBSEntityAttribute attribute : attributes) {
        TableItem columnItem = new TableItem(columnsTable, SWT.NONE);
        AttributeInfo col = new AttributeInfo(attribute);
        this.attributes.add(col);
        DBNDatabaseNode attributeNode = DBeaverCore.getInstance().getNavigatorModel().findNode(attribute);
        if (attributeNode != null) {
            columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon()));
        }
        fillAttributeColumns(attribute, col, columnItem);
        columnItem.setData(col);
        if (isColumnSelected(attribute)) {
            columnItem.setChecked(true);
            handleItemSelect(columnItem, false);
        }
    }
    UIUtils.packColumns(columnsTable);
    updateToggleButton();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)64 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)58 DBException (org.jkiss.dbeaver.DBException)36 ArrayList (java.util.ArrayList)11 IFile (org.eclipse.core.resources.IFile)11 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)11 CoreException (org.eclipse.core.runtime.CoreException)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)10 List (java.util.List)9 NotNull (org.jkiss.code.NotNull)9 Nullable (org.jkiss.code.Nullable)9 CommonUtils (org.jkiss.utils.CommonUtils)8 File (java.io.File)7 Collection (java.util.Collection)7 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)7 Log (org.jkiss.dbeaver.Log)6 InputStream (java.io.InputStream)5 IResource (org.eclipse.core.resources.IResource)5 SWT (org.eclipse.swt.SWT)5