Search in sources :

Example 1 with DBRProgressMonitor

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

the class NavigatorHandlerObjectOpen method refreshDatabaseNode.

private static void refreshDatabaseNode(@NotNull DBNDatabaseNode selectedNode) throws InvocationTargetException, InterruptedException {
    final DBNDatabaseNode nodeToRefresh = selectedNode;
    DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                nodeToRefresh.refreshNode(monitor, nodeToRefresh);
            } catch (DBException e) {
                log.error("Error refreshing database object", e);
            }
        }
    });
}
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 2 with DBRProgressMonitor

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

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

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView) {
        if (activeEditor instanceof SQLEditor) {
            IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
            if (file != null) {
                showResourceInNavigator(navigatorView, file);
            }
        } else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
            IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
            showResourceInNavigator(navigatorView, editorFile);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull final DBSObject activeObject;
        if (dsContainer != null) {
            DBPDataSource dataSource = dsContainer.getDataSource();
            if (dataSource != null) {
                activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
            } else {
                activeObject = dsContainer;
            }
            final NavigatorViewBase view = navigatorView;
            DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    DBSObject showObject = activeObject;
                    if (showObject instanceof DBPDataSource) {
                        showObject = ((DBPDataSource) showObject).getContainer();
                    }
                    DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                    if (objectNode != null) {
                        view.showNode(objectNode);
                    }
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 4 with DBRProgressMonitor

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

the class NavigatorHandlerObjectCreateCopy method pasteResource.

private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
    final IResource resource = resourceNode.getResource();
    final IResource targetResource = toFolder.getResource();
    assert resource != null;
    assert targetResource != null;
    final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    copyResource(monitor, resource, targetFolder);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with DBRProgressMonitor

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

the class NavigatorActionSetActiveObject method run.

@Override
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
        if (selectedNode instanceof DBNDatabaseNode) {
            final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
            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);
                        }
                    }
                });
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) 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)

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