Search in sources :

Example 1 with INavigatorNodeActionHandler

use of org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler in project dbeaver by serge-rider.

the class StatisticsNavigatorNodeRenderer method renderDataSourceNodeActions.

// /////////////////////////////////////////////////////////////////
// Node actions
private int renderDataSourceNodeActions(DBNDatabaseNode element, Tree tree, GC gc, Event event) {
    List<INavigatorNodeActionHandler> nodeActions = NavigatorExtensionsRegistry.getInstance().getNodeActions(getView(), element);
    int xWidth = getTreeWidth(tree);
    int xPos = xWidth;
    int widthOccupied = 0;
    for (INavigatorNodeActionHandler nah : nodeActions) {
        if (!nah.isSticky(view, element)) {
            // Non-sticky buttons are active only for selected or hovered items
            boolean isSelected = (event.stateMask & SWT.SELECTED) != 0;
            boolean isHover = false;
            if (!isSelected && !isHover) {
                return widthOccupied;
            }
        }
        // Margin
        widthOccupied += 2;
        DBPImage icon = nah.getNodeActionIcon(getView(), element);
        if (icon != null) {
            Image image = DBeaverIcons.getImage(icon);
            Rectangle imageBounds = image.getBounds();
            int imageSize = imageBounds.height;
            // event.height * 2 / 3;
            xPos -= imageSize;
            widthOccupied += imageSize;
            Point mousePos = tree.getDisplay().getCursorLocation();
            Point itemPos = tree.toDisplay(xPos, event.y + (event.height - imageSize) / 2);
            if (PAINT_ACTION_HOVER) {
                if (mousePos.x >= itemPos.x - 1 && mousePos.x <= itemPos.x + imageBounds.width + 2 && mousePos.y > itemPos.y - 1 && mousePos.y < itemPos.y + imageBounds.height + 2) {
                    Color oldBackground = gc.getBackground();
                    Color overBG = UIUtils.getSharedColor(new RGB(200, 200, 255));
                    gc.setBackground(overBG);
                    gc.fillRoundRectangle(xPos - 1, event.y + (event.height - imageSize) / 2 - 1, imageBounds.width + 2, imageBounds.height + 2, 2, 2);
                    gc.setBackground(oldBackground);
                }
            }
            gc.drawImage(image, xPos, event.y + (event.height - imageSize) / 2);
        // gc.drawImage(image,
        // 0, 0, imageBounds.width, imageBounds.height,
        // xPos, event.y + (event.height - imageSize) / 2, imageBounds.width, imageBounds.height);
        }
    // gc.setForeground(tree.getForeground());
    // int x = xWidth - textSize.x - 2;
    // gc.drawText(sizeText, x + 2, event.y, true);
    }
    // System.out.println(nodeActions);
    return widthOccupied;
}
Also used : INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler)

Example 2 with INavigatorNodeActionHandler

use of org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler in project dbeaver by dbeaver.

the class StatisticsNavigatorNodeRenderer method getActionButtonFor.

private INavigatorNodeActionHandler getActionButtonFor(DBNNode element, Tree tree, Event event) {
    List<INavigatorNodeActionHandler> nodeActions = NavigatorExtensionsRegistry.getInstance().getNodeActions(getView(), element);
    ScrollBar horizontalScrollBar = tree.getHorizontalBar();
    if (horizontalScrollBar != null && horizontalScrollBar.isVisible()) {
        return null;
    }
    int widthOccupied = 0;
    for (INavigatorNodeActionHandler nah : nodeActions) {
        if (!nah.isSticky(view, element)) {
            // Non-sticky buttons are active only for selected or hovered items
            boolean isSelected = (event.stateMask & SWT.SELECTED) != 0;
            boolean isHover = false;
            if (!isSelected && !isHover) {
                return null;
            }
        }
        // Margin
        widthOccupied += 2;
        DBPImage icon = nah.getNodeActionIcon(getView(), element);
        if (icon != null) {
            Image image = DBeaverIcons.getImage(icon);
            Rectangle imageBounds = image.getBounds();
            int imageSize = imageBounds.height;
            widthOccupied += imageSize;
            if (event.x > tree.getClientArea().width - widthOccupied) {
                return nah;
            }
        }
    }
    return null;
}
Also used : INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 3 with INavigatorNodeActionHandler

use of org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler in project dbeaver by dbeaver.

the class StatisticsNavigatorNodeRenderer method renderDataSourceNodeActions.

// /////////////////////////////////////////////////////////////////
// Node actions
private int renderDataSourceNodeActions(DBNDatabaseNode element, Tree tree, GC gc, Event event) {
    List<INavigatorNodeActionHandler> nodeActions = NavigatorExtensionsRegistry.getInstance().getNodeActions(getView(), element);
    int xWidth = getTreeWidth(tree);
    int xPos = xWidth;
    int widthOccupied = 0;
    for (INavigatorNodeActionHandler nah : nodeActions) {
        if (!nah.isSticky(view, element)) {
            // Non-sticky buttons are active only for selected or hovered items
            boolean isSelected = (event.stateMask & SWT.SELECTED) != 0;
            boolean isHover = false;
            if (!isSelected && !isHover) {
                return widthOccupied;
            }
        }
        // Margin
        widthOccupied += 2;
        DBPImage icon = nah.getNodeActionIcon(getView(), element);
        if (icon != null) {
            Image image = DBeaverIcons.getImage(icon);
            Rectangle imageBounds = image.getBounds();
            int imageSize = imageBounds.height;
            // event.height * 2 / 3;
            xPos -= imageSize;
            widthOccupied += imageSize;
            Point mousePos = tree.getDisplay().getCursorLocation();
            Point itemPos = tree.toDisplay(xPos, event.y + (event.height - imageSize) / 2);
            if (PAINT_ACTION_HOVER) {
                if (mousePos.x >= itemPos.x - 1 && mousePos.x <= itemPos.x + imageBounds.width + 2 && mousePos.y > itemPos.y - 1 && mousePos.y < itemPos.y + imageBounds.height + 2) {
                    Color oldBackground = gc.getBackground();
                    Color overBG = UIUtils.getSharedColor(new RGB(200, 200, 255));
                    gc.setBackground(overBG);
                    gc.fillRoundRectangle(xPos - 1, event.y + (event.height - imageSize) / 2 - 1, imageBounds.width + 2, imageBounds.height + 2, 2, 2);
                    gc.setBackground(oldBackground);
                }
            }
            gc.drawImage(image, xPos, event.y + (event.height - imageSize) / 2);
        // gc.drawImage(image,
        // 0, 0, imageBounds.width, imageBounds.height,
        // xPos, event.y + (event.height - imageSize) / 2, imageBounds.width, imageBounds.height);
        }
    // gc.setForeground(tree.getForeground());
    // int x = xWidth - textSize.x - 2;
    // gc.drawText(sizeText, x + 2, event.y, true);
    }
    // System.out.println(nodeActions);
    return widthOccupied;
}
Also used : INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler)

Example 4 with INavigatorNodeActionHandler

use of org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler in project dbeaver by serge-rider.

the class StatisticsNavigatorNodeRenderer method getActionButtonFor.

private INavigatorNodeActionHandler getActionButtonFor(DBNNode element, Tree tree, Event event) {
    List<INavigatorNodeActionHandler> nodeActions = NavigatorExtensionsRegistry.getInstance().getNodeActions(getView(), element);
    ScrollBar horizontalScrollBar = tree.getHorizontalBar();
    if (horizontalScrollBar != null && horizontalScrollBar.isVisible()) {
        return null;
    }
    int widthOccupied = 0;
    for (INavigatorNodeActionHandler nah : nodeActions) {
        if (!nah.isSticky(view, element)) {
            // Non-sticky buttons are active only for selected or hovered items
            boolean isSelected = (event.stateMask & SWT.SELECTED) != 0;
            boolean isHover = false;
            if (!isSelected && !isHover) {
                return null;
            }
        }
        // Margin
        widthOccupied += 2;
        DBPImage icon = nah.getNodeActionIcon(getView(), element);
        if (icon != null) {
            Image image = DBeaverIcons.getImage(icon);
            Rectangle imageBounds = image.getBounds();
            int imageSize = imageBounds.height;
            widthOccupied += imageSize;
            if (event.x > tree.getClientArea().width - widthOccupied) {
                return nah;
            }
        }
    }
    return null;
}
Also used : INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 5 with INavigatorNodeActionHandler

use of org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler in project dbeaver by serge-rider.

the class StatisticsNavigatorNodeRenderer method getDetailsTipText.

private String getDetailsTipText(DBNNode element, Tree tree, Event event) {
    if (element instanceof DBNDatabaseNode) {
        if (element instanceof DBNDataSource) {
            if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS)) {
                // Detect active action
                INavigatorNodeActionHandler overActionButton = getActionButtonFor(element, tree, event);
                if (overActionButton != null) {
                    return overActionButton.getNodeActionToolTip(view, element);
                }
            }
            if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME)) {
                return DataSourceUtils.getDataSourceAddressText(((DBNDataSource) element).getDataSourceContainer());
            }
            return null;
        }
        if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO)) {
            if (event.x > getTreeWidth(tree) - PERCENT_FILL_WIDTH) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBPObjectStatistics && ((DBPObjectStatistics) object).hasStatistics()) {
                    long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
                    if (statObjectSize > 0) {
                        String formattedSize;
                        try {
                            DBDDataFormatter formatter = object.getDataSource().getContainer().getDataFormatterProfile().createFormatter(DBDDataFormatter.TYPE_NAME_NUMBER, null);
                            formattedSize = formatter.formatValue(statObjectSize);
                        } catch (Exception e) {
                            formattedSize = String.valueOf(statObjectSize);
                        }
                        return "Object size on disk: " + formattedSize + " bytes";
                    }
                }
            }
        // renderObjectStatistics((DBNDatabaseNode) element, tree, gc, event);
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBDDataFormatter(org.jkiss.dbeaver.model.data.DBDDataFormatter) INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBException(org.jkiss.dbeaver.DBException)

Aggregations

INavigatorNodeActionHandler (org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler)6 ScrollBar (org.eclipse.swt.widgets.ScrollBar)2 DBException (org.jkiss.dbeaver.DBException)2 DBDDataFormatter (org.jkiss.dbeaver.model.data.DBDDataFormatter)2 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2