Search in sources :

Example 26 with DBNDatabaseNode

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

the class CheckboxTreeManager method updateCheckStates.

public void updateCheckStates() {
    Set<DBNDatabaseNode> parentList = new LinkedHashSet<>();
    for (Object element : viewer.getCheckedElements()) {
        for (DBNNode node = ((DBNDatabaseNode) element).getParentNode(); node != null; node = node.getParentNode()) {
            if (node instanceof DBNDatabaseNode) {
                parentList.add((DBNDatabaseNode) node);
                viewer.setChecked(node, true);
            }
        }
    }
    updateElementsCheck(parentList.toArray(), true, false);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 27 with DBNDatabaseNode

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

the class DatabaseNavigatorContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parent) {
    if (parent instanceof TreeLoadNode) {
        return null;
    }
    if (!(parent instanceof DBNNode)) {
        log.error("Bad parent type: " + parent);
        return null;
    }
    // view.getNavigatorModel().findNode(parent);
    final DBNNode parentNode = (DBNNode) parent;
    /*
        if (parentNode == null) {
            log.error("Can't find parent node '" + ((DBSObject) parent).getName() + "' in model");
            return EMPTY_CHILDREN;
        }
*/
    if (!parentNode.hasChildren(true)) {
        return EMPTY_CHILDREN;
    }
    if (parentNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentNode).needsInitialization()) {
        return TreeLoadVisualizer.expandChildren(navigatorTree.getViewer(), new TreeLoadService("Loading", ((DBNDatabaseNode) parentNode)));
    } else {
        try {
            // Read children with null monitor cos' it's not a lazy node
            // and no blocking process will occur
            DBNNode[] children = NavigatorUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), parentNode, true);
            if (ArrayUtils.isEmpty(children)) {
                return EMPTY_CHILDREN;
            } else {
                return children;
            }
        } catch (Throwable ex) {
            DBUserInterface.getInstance().showError("Navigator error", ex.getMessage(), ex);
            // Collapse this item
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    navigatorTree.getViewer().collapseToLevel(parent, 1);
                    navigatorTree.getViewer().refresh(parent);
                }
            });
            return EMPTY_CHILDREN;
        }
    }
}
Also used : TreeLoadNode(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) TreeLoadService(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 28 with DBNDatabaseNode

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

the class EntityEditor method saveCommandContext.

private boolean saveCommandContext(final DBRProgressMonitor monitor, Map<String, Object> options) {
    monitor.beginTask("Save entity", 1);
    Throwable error = null;
    final DBECommandContext commandContext = getCommandContext();
    if (commandContext == null) {
        log.warn("Null command context");
        return true;
    }
    try {
        commandContext.saveChanges(monitor, options);
    } catch (DBException e) {
        error = e;
    }
    if (getDatabaseObject() instanceof DBPStatefulObject) {
        try {
            ((DBPStatefulObject) getDatabaseObject()).refreshObjectState(monitor);
        } catch (DBCException e) {
            // Just report an error
            log.error(e);
        }
    }
    if (error == null) {
        // Refresh underlying node
        // It'll refresh database object and all it's descendants
        // So we'll get actual data from database
        final DBNDatabaseNode treeNode = getEditorInput().getNavigatorNode();
        try {
            DBeaverUI.runInProgressService(monitor1 -> {
                try {
                    treeNode.refreshNode(monitor1, DBNEvent.FORCE_REFRESH);
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (InvocationTargetException e) {
            error = e.getTargetException();
        } catch (InterruptedException e) {
        // ok
        }
    }
    monitor.done();
    if (error == null) {
        return true;
    } else {
        // Try to handle error in nested editors
        final Throwable vError = error;
        DBeaverUI.syncExec(() -> {
            final IErrorVisualizer errorVisualizer = getAdapter(IErrorVisualizer.class);
            if (errorVisualizer != null) {
                errorVisualizer.visualizeError(monitor, vError);
            }
        });
        // Show error dialog
        DBeaverUI.asyncExec(() -> DBUserInterface.getInstance().showError("Can't save '" + getDatabaseObject().getName() + "'", null, vError));
        return false;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 29 with DBNDatabaseNode

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

the class EntityEditor method createTopRightControl.

@Override
protected Control createTopRightControl(Composite composite) {
    // Path
    ToolBar breadcrumbsPanel = new ToolBar(composite, SWT.HORIZONTAL | SWT.RIGHT);
    breadcrumbsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Make base node path
    DBNDatabaseNode node = getEditorInput().getNavigatorNode();
    List<DBNDatabaseNode> nodeList = new ArrayList<>();
    for (DBNNode n = node; n != null; n = n.getParentNode()) {
        if (n instanceof DBNDatabaseNode) {
            nodeList.add(0, (DBNDatabaseNode) n);
        }
    }
    for (final DBNDatabaseNode databaseNode : nodeList) {
        createPathRow(breadcrumbsPanel, databaseNode);
    }
    return breadcrumbsPanel;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) GridData(org.eclipse.swt.layout.GridData) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 30 with DBNDatabaseNode

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

the class TabbedFolderPageProperties method detachPropertiesPanel.

private void detachPropertiesPanel() {
    boolean attached = isAttached();
    String title = attached ? "Detach properties to top panel" : "Move properties to tab";
    if (UIUtils.confirmAction(part.getSite().getShell(), title, title + " will require to reopen editor.\nAre you sure?")) {
        DBPPreferenceStore prefs = DBeaverCore.getGlobalPreferenceStore();
        prefs.setValue(DBeaverPreferences.ENTITY_EDITOR_DETACH_INFO, attached);
        IEditorPart editor;
        if (part.getSite() instanceof MultiPageEditorSite) {
            editor = ((MultiPageEditorSite) part.getSite()).getMultiPageEditor();
        } else {
            editor = (IEditorPart) part;
        }
        if (editor != null) {
            DBNDatabaseNode node = null;
            if (editor.getEditorInput() instanceof DatabaseEditorInput) {
                node = ((DatabaseEditorInput) editor.getEditorInput()).getNavigatorNode();
            }
            DBeaverUI.getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
            if (node != null) {
                NavigatorHandlerObjectOpen.openEntityEditor(node, null, DBeaverUI.getActiveWorkbenchWindow());
            }
        }
    }
}
Also used : DatabaseEditorInput(org.jkiss.dbeaver.ui.editors.DatabaseEditorInput) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)165 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)64 DBException (org.jkiss.dbeaver.DBException)60 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)38 ArrayList (java.util.ArrayList)29 GridData (org.eclipse.swt.layout.GridData)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)21 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)20 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)20 ISelection (org.eclipse.jface.viewers.ISelection)16 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)13 Collection (java.util.Collection)12 Composite (org.eclipse.swt.widgets.Composite)12 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)12 IEditorPart (org.eclipse.ui.IEditorPart)11