Search in sources :

Example 51 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class DBXTreeFolder method getChildren.

@NotNull
@Override
public List<DBXTreeNode> getChildren(DBNNode context) {
    List<DBXTreeNode> children = super.getChildren(context);
    if (!CommonUtils.isEmpty(contributedCategories) && context instanceof DBNDatabaseNode) {
        // Add contributed editors
        List<DBXTreeNode> childrenWithContributions = new ArrayList<>(children);
        DBPDataSourceProviderRegistry dspRegistry = DBWorkbench.getPlatform().getDataSourceProviderRegistry();
        DBPDataSourceContainer dataSource = ((DBNDatabaseNode) context).getDataSourceContainer();
        for (String category : contributedCategories) {
            DBPEditorContribution[] editors = dspRegistry.getContributedEditors(category, dataSource);
            for (DBPEditorContribution editor : editors) {
                DBXTreeObject editorNode = new DBXTreeObject(getSource(), // No parent - otherwise we'll have dups after each call
                null, null, null, editor.getLabel(), editor.getDescription(), editor.getEditorId());
                editorNode.setDefaultIcon(editor.getIcon());
                childrenWithContributions.add(editorNode);
            }
        }
        return childrenWithContributions;
    }
    return children;
}
Also used : DBPDataSourceProviderRegistry(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderRegistry) DBPEditorContribution(org.jkiss.dbeaver.model.connection.DBPEditorContribution) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) NotNull(org.jkiss.code.NotNull)

Example 52 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class SQLToolTaskWizard method refreshOnFinish.

private void refreshOnFinish() throws Exception {
    try {
        getContainer().run(true, true, monitor -> {
            monitor.beginTask("Object refreshing", objectList.size());
            for (DBSObject object : objectList) {
                try {
                    DBNDatabaseNode objectNode = DBNUtils.getNodeByObject(object);
                    if (objectNode != null) {
                        objectNode.refreshNode(new DefaultProgressMonitor(monitor), DBNEvent.FORCE_REFRESH);
                        if (monitor.isCanceled()) {
                            break;
                        }
                        monitor.worked(1);
                    }
                } catch (Exception e) {
                    log.error("Error refreshing object '" + object.getName() + "'", e);
                }
            }
            monitor.done();
        });
    } catch (InvocationTargetException e) {
        throw new DBCException("Refresh error", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 53 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class AbstractDataEditor method openNewContainer.

@Override
public void openNewContainer(DBRProgressMonitor monitor, @NotNull DBSDataContainer dataContainer, @NotNull DBDDataFilter newFilter) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext == null) {
        log.error("Can't open new container - not execution context found");
        return;
    }
    final DBNDatabaseNode targetNode = executionContext.getDataSource().getContainer().getPlatform().getNavigatorModel().getNodeByObject(monitor, dataContainer, false);
    if (targetNode == null) {
        UIUtils.showMessageBox(null, "Open link", "Can't navigate to '" + DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.UI) + "' - navigator node not found", SWT.ICON_ERROR);
        return;
    }
    openNewDataEditor(targetNode, newFilter);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 54 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class CursorViewComposite method openNewContainer.

@Override
public void openNewContainer(DBRProgressMonitor monitor, @NotNull DBSDataContainer dataContainer, @NotNull DBDDataFilter newFilter) {
    DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext == null) {
        return;
    }
    final DBNDatabaseNode targetNode = executionContext.getDataSource().getContainer().getPlatform().getNavigatorModel().getNodeByObject(monitor, dataContainer, false);
    if (targetNode == null) {
        UIUtils.showMessageBox(null, "Open link", "Can't navigate to '" + DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.UI) + "' - navigator node not found", SWT.ICON_ERROR);
        return;
    }
    AbstractDataEditor.openNewDataEditor(targetNode, newFilter);
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 55 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class ToggleProcedureBreakpointTarget method toggleLineBreakpoints.

@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    IEditorPart editorPart = (IEditorPart) part;
    IResource resource = extractResource(editorPart, selection);
    if (resource == null) {
        return;
    }
    DBSObject databaseObject = DebugUI.extractDatabaseObject(editorPart);
    if (databaseObject == null) {
        return;
    }
    DBNDatabaseNode node = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(new VoidProgressMonitor(), databaseObject, false);
    if (node == null) {
        return;
    }
    String nodeItemPath = node.getNodeItemPath();
    ITextSelection textSelection = (ITextSelection) selection;
    int lineNumber = textSelection.getStartLine();
    IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DBGConstants.MODEL_IDENTIFIER_DATABASE);
    for (IBreakpoint breakpoint : breakpoints) {
        if (breakpoint instanceof IDatabaseBreakpoint) {
            IDatabaseBreakpoint databaseBreakpoint = (IDatabaseBreakpoint) breakpoint;
            if (nodeItemPath.equals(databaseBreakpoint.getNodePath())) {
                if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
                    DebugUITools.deleteBreakpoints(new IBreakpoint[] { breakpoint }, part.getSite().getShell(), null);
                    return;
                }
            }
        }
    }
    int charstart = -1, charend = -1;
    DBGBreakpointDescriptor breakpointDescriptor = GeneralUtils.adapt(databaseObject, DBGBreakpointDescriptor.class);
    if (breakpointDescriptor == null) {
        throw new CoreException(GeneralUtils.makeErrorStatus("Object '" + DBUtils.getObjectFullName(databaseObject, DBPEvaluationContext.UI) + "' doesn't support breakpoints"));
    }
    // create line breakpoint (doc line numbers start at 0)
    new DatabaseLineBreakpoint(databaseObject, node, resource, breakpointDescriptor, lineNumber + 1, charstart, charend, true);
}
Also used : DatabaseLineBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.DatabaseLineBreakpoint) IDatabaseBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.IDatabaseBreakpoint) IEditorPart(org.eclipse.ui.IEditorPart) DBGBreakpointDescriptor(org.jkiss.dbeaver.debug.DBGBreakpointDescriptor) ITextSelection(org.eclipse.jface.text.ITextSelection) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) DatabaseLineBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.DatabaseLineBreakpoint) IDatabaseBreakpoint(org.jkiss.dbeaver.debug.core.breakpoints.IDatabaseBreakpoint) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) CoreException(org.eclipse.core.runtime.CoreException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IResource(org.eclipse.core.resources.IResource)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)222 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)85 DBException (org.jkiss.dbeaver.DBException)83 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)81 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 ArrayList (java.util.ArrayList)44 GridData (org.eclipse.swt.layout.GridData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)29 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)28 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)27 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)26 ISelection (org.eclipse.jface.viewers.ISelection)21 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)21 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)19 Collection (java.util.Collection)18 List (java.util.List)17 Composite (org.eclipse.swt.widgets.Composite)17 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)17 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)17 SWT (org.eclipse.swt.SWT)15