Skip to main content



      Home
Home » Eclipse Projects » NatTable » How to show a tooltip over a sorting triangle image at a column header?
How to show a tooltip over a sorting triangle image at a column header? [message #1767663] Sat, 08 July 2017 15:42 Go to next message
Eclipse UserFriend
Could anybody give an idea/example how to show a tooltip when hovering over a given area inside a cell?

For example over a sorting triangle image at a column header:
index.php/fa/29897/0/


Re: How to show a tooltip over a sorting triangle image at a column header? [message #1767698 is a reply to message #1767663] Mon, 10 July 2017 02:35 Go to previous messageGo to next message
Eclipse UserFriend
You need to inspect the ICellPainter at the hovered position. This can be done by extending NatTableContentTooltip and override getText() similar to the following snippet:

new NatTableContentTooltip(natTable, GridRegion.COLUMN_HEADER) {

    @Override
    protected String getText(Event event) {
        int col = this.natTable.getColumnPositionByX(event.x);
        int row = this.natTable.getRowPositionByY(event.y);

        ILayerCell cell = this.natTable.getCellByPosition(col, row);
        if (cell != null) {
            ICellPainter painter = this.natTable.getConfigRegistry().getConfigAttribute(
                    CellConfigAttributes.CELL_PAINTER,
                    DisplayMode.NORMAL,
                    cell.getConfigLabels().getLabels());
            if (isSortHeaderPainter(painter)) {
                GC gc = new GC(this.natTable.getDisplay());
                try {
                    Rectangle adjustedCellBounds = this.natTable.getLayerPainter().adjustCellBounds(col, row, cell.getBounds());

                    ICellPainter hoveredPainter = painter.getCellPainterAt(
                            event.x, event.y, cell, gc, adjustedCellBounds, configRegistry);
                    if (hoveredPainter != null) {
                        if (isSortIconDecorator(hoveredPainter)) {
                            if (cell.getConfigLabels().hasLabel(DefaultSortConfiguration.SORT_UP_CONFIG_TYPE)) {
                                return "ascending";
                            } else if (cell.getConfigLabels().hasLabel(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE)) {
                                return "descending";
                            }
                        }
                    }
                } finally {
                    gc.dispose();
                }
            }
        }
        return null;
    }

    private boolean isSortHeaderPainter(ICellPainter painter) {
        if (painter instanceof SortableHeaderTextPainter) {
            return true;
        } else if (painter instanceof CellPainterWrapper) {
            return isSortHeaderPainter(((CellPainterWrapper) painter).getWrappedPainter());
        }
        return false;
    }

    private boolean isSortIconDecorator(ICellPainter painter) {
        if (painter instanceof SortIconPainter) {
            return true;
        } else if (painter instanceof CellPainterDecorator) {
            return isSortIconDecorator(((CellPainterDecorator) painter).getDecoratorCellPainter());
        }
        return false;
    }
};
Re: How to show a tooltip over a sorting triangle image at a column header? [message #1767741 is a reply to message #1767698] Mon, 10 July 2017 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Thank you, Dirk. It works as desired even without GC instance (used null instead).
Therefore a question for understanding: what's the purpose of GC instance in painter.getCellPainterAt()?
Can I always omit GC instance?
Re: How to show a tooltip over a sorting triangle image at a column header? [message #1767778 is a reply to message #1767741] Tue, 11 July 2017 01:07 Go to previous messageGo to next message
Eclipse UserFriend
It is needed to calculate the painter bounds, especially when CellPainterDecorator are used. In the default configuration you are in the lucky position that the dimensions of the painters are derived from the cell dimensions (BeveledBorderDecorator) and the Image in the SortIconPainter. If a TextPainter would be involved it would need the GC to calculate the dimensions, which would lead to a NPE.
Re: How to show a tooltip over a sorting triangle image at a column header? [message #1767901 is a reply to message #1767778] Wed, 12 July 2017 01:34 Go to previous messageGo to next message
Eclipse UserFriend
You mean if TextPainter would be involved in CellPainterDecorator.getCellPainterAt() using computations in getDecoratorCellPainterBounds/getBaseCellPainterBounds, right? Because it's the only place I see any computations with gc. In TextPainter itself getCellPainterAt() returns this. Thank you for clarifying!
Re: How to show a tooltip over a sorting triangle image at a column header? [message #1767905 is a reply to message #1767901] Wed, 12 July 2017 01:59 Go to previous message
Eclipse UserFriend
Yes it is needed only in such cases
Previous Topic:How check a cell which only display part of content?
Next Topic:Make column unmovable while scrolling horizontally
Goto Forum:
  


Current Time: Wed Jul 23 19:26:13 EDT 2025

Powered by FUDForum. Page generated in 0.04622 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top