|
|
|
|
|
|
|
|
|
|
|
Re: Tooltips [message #897221 is a reply to message #897217] |
Mon, 23 July 2012 09:19 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
Hi Domenic,
sorry, I thought you are using the NatTable sources and not ready to use builds.
We are currently working on a stable version under Nebula. If you want to benefit from enhancements and bugfixes without relying to stable versions, you need to checkout the sources from Git and build a SNAPSHOT version yourself.
As the NatTableContentTooltip also works with a 2.3.2 Sourceforge version of NatTable, I post the code here so you can use it by adding it into your application. This way you don't have to checkout the sources and build NatTable yourself until a stable Nebula NatTable version is released.
public class NatTableContentTooltip extends DefaultToolTip {
/**
* The {@link NatTable} instance for which this {@link ToolTip} is used.
*/
private NatTable natTable;
/**
* The regions of the {@link NatTable} for which this {@link ToolTip} is
* active.
*/
private String[] tooltipRegions;
/**
* Creates a new {@link ToolTip} object, attaches it to the given {@link NatTable}
* instance and configures and activates it.
* @param natTable The {@link NatTable} instance for which this {@link ToolTip} is used.
* @param tooltipRegions The regions of the {@link NatTable} for which this {@link ToolTip} is
* active. If none are given, the tooltip will be active for all regions.
*/
public NatTableContentTooltip(NatTable natTable, String... tooltipRegions) {
super(natTable, ToolTip.NO_RECREATE, false);
setPopupDelay(500);
setShift(new Point(10, 10));
activate();
this.natTable = natTable;
this.tooltipRegions = tooltipRegions;
}
/**
* {@inheritDoc}
*
* <p>Implementation here means the tooltip is not redrawn unless mouse hover moves outside of the
* current cell (the combination of ToolTip.NO_RECREATE style and override of this method).
*/
protected Object getToolTipArea(Event event) {
int col = natTable.getColumnPositionByX(event.x);
int row = natTable.getRowPositionByY(event.y);
return new Point(col, row);
}
/**
* {@inheritDoc}
*
* <p>Evaluates the cell for which the tooltip should be rendered and checks the
* display value. If the display value is empty <code>null</code> will be returned
* which will result in not showing a tooltip.
*/
@Override
protected String getText(Event event) {
int col = natTable.getColumnPositionByX(event.x);
int row = natTable.getRowPositionByY(event.y);
ILayerCell cell = natTable.getCellByPosition(col, row);
if (cell != null) {
String tooltipValue = CellDisplayConversionUtils.convertDataType(
cell,
natTable.getConfigRegistry());
if (tooltipValue.length() > 0) {
return tooltipValue;
}
}
return null;
}
/**
* {@inheritDoc}
*
* <p>Will only display a tooltip if the value of the cell for which the tooltip
* should be rendered is not empty.
* <p>If there are regions configured for which the tooltip should be visible, it
* is also checked if the the region for which the tooltip should be rendered is
* in one of the configured tooltip regions.
*/
@Override
protected boolean shouldCreateToolTip(Event event) {
//check the region?
boolean regionCheckPassed = false;
if (this.tooltipRegions.length > 0) {
LabelStack regionLabels = natTable.getRegionLabelsByXY(event.x, event.y);
if (regionLabels != null) {
for (String label : this.tooltipRegions) {
if (regionLabels.hasLabel(label)) {
regionCheckPassed = true;
break;
}
}
}
}
else {
regionCheckPassed = true;
}
if (regionCheckPassed && getText(event) != null) {
return super.shouldCreateToolTip(event);
}
return false;
}
}
Hope this helps!
Greez,
Dirk
|
|
|
|
Powered by
FUDForum. Page generated in 0.03965 seconds