Search in sources :

Example 11 with DBNDataSource

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

the class StatisticsNavigatorNodeRenderer method paintNodeDetails.

public void paintNodeDetails(DBNNode node, Tree tree, GC gc, Event event) {
    super.paintNodeDetails(node, tree, gc, event);
    ScrollBar hSB = tree.getHorizontalBar();
    boolean scrollEnabled = (hSB != null && hSB.isVisible());
    Object element = event.item.getData();
    if (element instanceof DBNDatabaseNode) {
        if (element instanceof DBNDataSource) {
            int widthOccupied = 0;
            if (!scrollEnabled && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS)) {
                widthOccupied += renderDataSourceNodeActions((DBNDatabaseNode) element, tree, gc, event);
            }
            if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME)) {
                renderDataSourceHostName((DBNDataSource) element, tree, gc, event, widthOccupied);
            }
        }
        if (!scrollEnabled && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO)) {
            renderObjectStatistics((DBNDatabaseNode) element, tree, gc, event);
        }
    }
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 12 with DBNDataSource

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

the class TargetPrefPage method setElement.

@Override
public void setElement(IAdaptable element) {
    this.element = element;
    if (this.element == null) {
        return;
    }
    dataSourceContainer = element instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) element : null;
    containerNode = element.getAdapter(DBNDataSource.class);
    if (containerNode == null) {
        final DBPDataSourceContainer dsContainer = element.getAdapter(DBPDataSourceContainer.class);
        if (dsContainer != null) {
            containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode(dsContainer);
        } else {
            IDatabaseEditorInput dbInput = element.getAdapter(IDatabaseEditorInput.class);
            if (dbInput != null) {
                DBNNode dbNode = dbInput.getNavigatorNode();
                if (dbNode instanceof DBNDataSource) {
                    containerNode = (DBNDataSource) dbNode;
                }
            } else if (element instanceof DBPContextProvider) {
                DBCExecutionContext context = ((DBPContextProvider) element).getExecutionContext();
                if (context != null) {
                    containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode(context.getDataSource().getContainer());
                }
            } else if (element instanceof DBPDataSourceContainer) {
                containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode((DBPDataSourceContainer) element);
            }
        }
    }
    if (dataSourceContainer == null && containerNode != null) {
        dataSourceContainer = containerNode.getDataSourceContainer();
    }
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 13 with DBNDataSource

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

the class NNAHDataSourceTunnel method getNodeActionToolTip.

@Override
public String getNodeActionToolTip(INavigatorModelView view, DBNNode node) {
    StringBuilder tip = new StringBuilder("Network handlers enabled:");
    for (DBWHandlerConfiguration handler : ((DBNDataSource) node).getDataSourceContainer().getConnectionConfiguration().getHandlers()) {
        if (handler.isEnabled()) {
            tip.append("\n  -").append(handler.getHandlerDescriptor().getLabel());
            String hostName = handler.getStringProperty(DBWHandlerConfiguration.PROP_HOST);
            if (!CommonUtils.isEmpty(hostName)) {
                tip.append(": ").append(hostName);
            }
        }
    }
    return tip.toString();
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource)

Example 14 with DBNDataSource

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

the class DatabaseNavigatorLabelProvider method getForeground.

@Override
public Color getForeground(Object element) {
    if (element instanceof DBNNode) {
        DBNNode node = (DBNNode) element;
        if (node instanceof DBNDataSource) {
            DBPDataSourceContainer ds = ((DBNDataSource) element).getDataSourceContainer();
            Color bgColor = UIUtils.getConnectionColor(ds.getConnectionConfiguration());
            return bgColor == null ? null : UIUtils.getContrastColor(bgColor);
        }
        if (node.isLocked()) {
            return lockedForeground;
        }
        if (node instanceof DBSWrapper && ((DBSWrapper) node).getObject() != null && !((DBSWrapper) node).getObject().isPersisted()) {
            return transientForeground;
        }
    }
    return null;
}
Also used : DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 15 with DBNDataSource

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

the class DatabaseLazyEditorInput method initializeRealInput.

public IDatabaseEditorInput initializeRealInput(final DBRProgressMonitor monitor) throws DBException {
    // Get the node path.
    if (project != null) {
        dataSourceContainer = project.getDataSourceRegistry().getDataSource(dataSourceId);
    }
    if (dataSourceContainer == null) {
        // $NON-NLS-2$
        log.error("Can't find data source '" + dataSourceId + "'");
        return null;
    }
    if (project == null) {
        project = dataSourceContainer.getRegistry().getProject();
    }
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    navigatorModel.ensureProjectLoaded(project);
    // dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId
    DBPDataSource dataSource;
    while (!dataSourceContainer.isConnected()) {
        try {
            dataSourceContainer.connect(monitor, true, true);
        } catch (final DBException e) {
            // Connection error
            final Integer result = new UITask<Integer>() {

                @Override
                protected Integer runTask() {
                    ConnectionLostDialog clDialog = new ConnectionLostDialog(UIUtils.getActiveWorkbenchShell(), dataSourceContainer, e, "Close");
                    return clDialog.open();
                }
            }.execute();
            if (result == IDialogConstants.STOP_ID) {
                // Close editor
                return null;
            } else if (result == IDialogConstants.RETRY_ID) {
                continue;
            } else {
                return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
            }
        }
        break;
    }
    try {
        dataSource = dataSourceContainer.getDataSource();
        if (dataSource == null) {
            throw new DBException("Connection to '" + dataSourceContainer.getName() + "' canceled");
        }
        final DBNNode[] editorNodeResult = new DBNNode[1];
        DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
            try {
                DBNDataSource dsNode = (DBNDataSource) navigatorModel.getNodeByObject(monitor, this.dataSourceContainer, true);
                if (dsNode == null) {
                    throw new DBException("Datasource '" + this.dataSourceContainer.getName() + "' navigator node not found");
                }
                dsNode.initializeNode(monitor, null);
                editorNodeResult[0] = navigatorModel.getNodeByPath(monitor, project, nodePath);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        });
        DBNNode node = editorNodeResult[0];
        if (node == null) {
            throw new DBException("Navigator node '" + nodePath + "' not found");
        }
        if (node instanceof DBNDatabaseNode) {
            DatabaseNodeEditorInput realInput = new DatabaseNodeEditorInput((DBNDatabaseNode) node);
            realInput.setDefaultFolderId(activeFolderId);
            realInput.setDefaultPageId(activePageId);
            return realInput;
        } else {
            throw new DBException("Database node has bad type: " + node.getClass().getName());
        }
    } catch (DBException e) {
        return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) UITask(org.jkiss.dbeaver.ui.UITask) ConnectionLostDialog(org.jkiss.dbeaver.ui.dialogs.ConnectionLostDialog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)59 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)26 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)17 DBException (org.jkiss.dbeaver.DBException)15 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)13 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)12 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)10 ArrayList (java.util.ArrayList)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)8 IFile (org.eclipse.core.resources.IFile)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6 SQLScriptExecuteSettings (org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings)6 GridData (org.eclipse.swt.layout.GridData)5 IResource (org.eclipse.core.resources.IResource)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4