|
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 |
Dirk Fauth Messages: 2902 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;
}
};
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04620 seconds