Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 19:42 Go to next message
Bel Razom is currently offline Bel RazomFriend
Messages: 10
Registered: May 2017
Junior Member
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 06:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
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 13:50 Go to previous messageGo to next message
Bel Razom is currently offline Bel RazomFriend
Messages: 10
Registered: May 2017
Junior Member
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 05:07 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
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 05:34 Go to previous messageGo to next message
Bel Razom is currently offline Bel RazomFriend
Messages: 10
Registered: May 2017
Junior Member
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 05:59 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
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 Sep 19 20:14:07 GMT 2018

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

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

Back to the top