Search in sources :

Example 61 with DBNDatabaseNode

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

the class DefaultNavigatorNodeRenderer method paintNodeDetails.

public void paintNodeDetails(DBNNode node, Tree tree, GC gc, Event event) {
    Color conColor = null;
    Object element = event.item.getData();
    if (element instanceof DBNDatabaseNode) {
        DBPDataSourceContainer ds = ((DBNDatabaseNode) element).getDataSourceContainer();
        conColor = UIUtils.getConnectionColor(ds.getConnectionConfiguration());
    }
    if (conColor != null) {
        gc.setForeground(conColor);
        if (element instanceof DBNDataSource) {
        // int boxSize = event.height - 4;
        // gc.setLineWidth(2);
        // gc.setLineStyle(SWT.LINE_SOLID);
        // gc.fillRectangle(0, event.y + 2, textSize.x, textSize.y);
        // gc.drawRectangle(0, event.y + 2, textSize.x - 1, textSize.y - 1);
        // gc.drawRectangle(event.x - 2, event.y + 1, event.width + 3, event.height - 2/*, event.height / 2, event.height / 2*/);
        // gc.drawLine(event.x, event.y, event.x + event.width, event.y);
        // gc.drawLine(10, event.y + event.height - 1, event.x + event.width, event.y + event.height - 1);
        // gc.drawLine(event.x, event.y + event.height - 1, event.x + event.width, event.y + event.height - 1);
        } else {
            int oldLineWidth = gc.getLineWidth();
            gc.setForeground(conColor);
            gc.setLineWidth(3);
            if (((TreeItem) event.item).getItemCount() > 0) {
                gc.drawLine(event.x - 20, event.y - 1, event.x - 20, event.y + event.height + 1);
            } else {
                gc.drawLine(event.x - 4, event.y - 1, event.x - 4, event.y + event.height + 1);
            }
            gc.setLineWidth(oldLineWidth);
        }
    }
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Color(org.eclipse.swt.graphics.Color) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 62 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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 63 with DBNDatabaseNode

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

the class StatisticsNavigatorNodeRenderer method renderObjectStatistics.

// /////////////////////////////////////////////////////////////////
// Statistics renderer
private void renderObjectStatistics(DBNDatabaseNode element, Tree tree, GC gc, Event event) {
    DBSObject object = element.getObject();
    if (object instanceof DBPObjectStatistics) {
        String sizeText;
        int percentFull;
        boolean statsWasRead = false;
        DBNNode parentNode = getParentItem(element);
        DBSObject parentObject = parentNode instanceof DBNDatabaseNode ? DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject()) : null;
        if (parentObject instanceof DBPObjectStatisticsCollector) {
            // && !((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected()
            statsWasRead = ((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected();
        } else {
            // If there is no stats collector then do not check for stats presence
            // Because it will trigger stats read job which won't read any statistics (as there is no way to load it for individual object).
            // ((DBPObjectStatistics) object).hasStatistics();
            statsWasRead = true;
        }
        long maxObjectSize = statsWasRead ? getMaxObjectSize((TreeItem) event.item) : -1;
        if (statsWasRead && maxObjectSize >= 0) {
            long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
            if (statObjectSize <= 0) {
                // Empty or no size - nothing to show
                return;
            }
            percentFull = maxObjectSize == 0 ? 0 : (int) (statObjectSize * 100 / maxObjectSize);
            if (percentFull < 0 || percentFull > 100) {
                log.debug("Object stat > 100%!");
                percentFull = 100;
            }
            Format format;
            synchronized (classFormatMap) {
                format = classFormatMap.get(object.getClass().getName());
                if (format == null) {
                    try {
                        Method getStatObjectSizeMethod = object.getClass().getMethod("getStatObjectSize");
                        Property propAnnotation = getStatObjectSizeMethod.getAnnotation(Property.class);
                        if (propAnnotation != null) {
                            Class<? extends Format> formatterClass = propAnnotation.formatter();
                            if (formatterClass != Format.class) {
                                format = formatterClass.getConstructor().newInstance();
                            }
                        }
                    } catch (Exception e) {
                        log.debug(e);
                    }
                    if (format == null) {
                        format = numberFormat;
                    }
                    classFormatMap.put(object.getClass().getName(), format);
                }
            }
            sizeText = format.format(statObjectSize);
        } else {
            sizeText = "...";
            percentFull = 0;
            if (parentNode instanceof DBNDatabaseNode) {
                DBSObject realParentObject = DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject());
                if (!readObjectStatistics(element.getParentNode(), realParentObject, ((TreeItem) event.item).getParentItem())) {
                    return;
                }
            }
        }
        Point textSize = gc.stringExtent(sizeText);
        textSize.x += 4;
        // int caWidth = tree.getClientArea().width;
        int occupiedWidth = event.x + event.width + 4;
        int xWidth = getTreeWidth(tree);
        if (xWidth - occupiedWidth > Math.max(PERCENT_FILL_WIDTH, textSize.x)) {
            {
                CTabFolder tabFolder = UIUtils.getParentOfType(tree, CTabFolder.class);
                Color fillColor = tabFolder == null ? UIStyles.getDefaultWidgetBackground() : tabFolder.getBackground();
                gc.setBackground(fillColor);
                int fillWidth = PERCENT_FILL_WIDTH * percentFull / 100 + 1;
                int x = xWidth - fillWidth - 2;
                gc.fillRectangle(x, event.y + 2, fillWidth, event.height - 4);
            }
            gc.setForeground(tree.getForeground());
            int x = xWidth - textSize.x - 2;
            Font oldFont = gc.getFont();
            gc.setFont(tree.getFont());
            gc.drawText(sizeText, x + 2, event.y + (event.height - textSize.y) / 2, true);
            gc.setFont(oldFont);
        }
    }
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) TreeItem(org.eclipse.swt.widgets.TreeItem) Method(java.lang.reflect.Method) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Format(java.text.Format) ByteNumberFormat(org.jkiss.utils.ByteNumberFormat) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) Property(org.jkiss.dbeaver.model.meta.Property)

Example 64 with DBNDatabaseNode

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

the class NNAHDataSourceTunnel method handleNodeAction.

@Override
public void handleNodeAction(INavigatorModelView view, DBNNode node, Event event, boolean defaultAction) {
    if (node instanceof DBNDatabaseNode) {
        DBPDataSourceContainer dataSourceContainer = ((DBNDatabaseNode) node).getDataSourceContainer();
        UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
        if (serviceConnections != null) {
            serviceConnections.openConnectionEditor(dataSourceContainer, "ConnectionPageNetworkHandler.ssh_tunnel");
        }
    }
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Example 65 with DBNDatabaseNode

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

the class CompareObjectsExecutor method compareChildren.

private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
    // Compare children
    int nodeCount = nodes.size();
    List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
    // Use submonitor to avoid huge number of tasks
    DBRProgressMonitor subMonitor = new SubTaskProgressMonitor(monitor);
    for (int i = 0; i < nodeCount; i++) {
        DBNDatabaseNode node = nodes.get(i);
        // Cache structure if possible
        if (node.getObject() instanceof DBSObjectContainer) {
            ((DBSObjectContainer) node.getObject()).cacheStructure(subMonitor, DBSObjectContainer.STRUCT_ALL);
        }
        try {
            DBNDatabaseNode[] children = node.getChildren(subMonitor);
            allChildren.add(children);
        } catch (Exception e) {
            log.warn("Error reading child nodes for compare", e);
            allChildren.add(null);
        }
    }
    Set<String> allChildNames = new LinkedHashSet<>();
    for (DBNDatabaseNode[] childList : allChildren) {
        if (childList == null)
            continue;
        for (DBNDatabaseNode child : childList) {
            DBXTreeNode meta = child.getMeta();
            if (meta.isVirtual()) {
                // Skip virtual nodes
                continue;
            }
            if (settings.isSkipSystemObjects() && DBUtils.isSystemObject(child.getObject())) {
                // Skip system objects
                continue;
            }
            allChildNames.add(child.getNodeName());
        }
    }
    for (String childName : allChildNames) {
        int[] childIndexes = new int[nodeCount];
        for (int i = 0; i < nodeCount; i++) {
            childIndexes[i] = -1;
            DBNDatabaseNode[] childList = allChildren.get(i);
            if (childList == null)
                continue;
            for (int k = 0; k < childList.length; k++) {
                DBNDatabaseNode child = childList[k];
                if (child.getNodeName().equals(childName)) {
                    childIndexes[i] = k;
                    break;
                }
            }
        }
        List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
        for (int i = 0; i < nodeCount; i++) {
            if (childIndexes[i] == -1) {
            // Missing
            } else {
                for (int k = 0; k < nodeCount; k++) {
                    if (k != i && childIndexes[k] != childIndexes[i]) {
                        // Wrong index - add to report
                        break;
                    }
                }
                final DBNDatabaseNode[] childList = allChildren.get(i);
                if (childList != null) {
                    nodesToCompare.add(childList[childIndexes[i]]);
                }
            }
        }
        // Compare children recursively
        compareNodes(monitor, nodesToCompare);
    }
}
Also used : SubTaskProgressMonitor(org.jkiss.dbeaver.model.runtime.SubTaskProgressMonitor) DBException(org.jkiss.dbeaver.DBException) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

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