Search in sources :

Example 1 with DBNEmptyNode

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

the class DatabaseBrowserView method getNodeFromSecondaryId.

public static DBNNode getNodeFromSecondaryId(String id) throws DBException {
    int divPos = id.indexOf('|');
    if (divPos == -1) {
        throw new DBException("Bad secondary ID: " + id);
    }
    String projectName = id.substring(0, divPos);
    String nodePath = id.substring(divPos + 1).replace("~", ":");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null) {
        throw new DBException("Project '" + projectName + "' not found");
    }
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    DBNNode node = null;
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
    if (projectMeta != null) {
        navigatorModel.ensureProjectLoaded(projectMeta);
        node = navigatorModel.getNodeByPath(new VoidProgressMonitor(), projectMeta, nodePath);
    }
    if (node == null) {
        log.error("Node " + nodePath + " not found for browse view");
        node = new DBNEmptyNode();
    }
    return node;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNEmptyNode(org.jkiss.dbeaver.model.navigator.DBNEmptyNode) IProject(org.eclipse.core.resources.IProject) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 2 with DBNEmptyNode

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

the class DatabaseBrowserView method getRootNode.

@Override
public DBNNode getRootNode() {
    String secondaryId = getViewSite().getSecondaryId();
    if (!CommonUtils.isEmpty(secondaryId)) {
        try {
            return getNodeFromSecondaryId(secondaryId);
        } catch (DBException e) {
            DBWorkbench.getPlatformUI().showError("Open database browser", "Can't find database navigator node", e);
        }
    }
    DBNProject projectNode = getModel().getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject());
    return projectNode == null ? new DBNEmptyNode() : projectNode.getDatabases();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBNEmptyNode(org.jkiss.dbeaver.model.navigator.DBNEmptyNode)

Aggregations

DBException (org.jkiss.dbeaver.DBException)2 DBNEmptyNode (org.jkiss.dbeaver.model.navigator.DBNEmptyNode)2 IProject (org.eclipse.core.resources.IProject)1 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)1 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)1 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)1