Dynamically changing the draw2d drawing tooltip

We are currently using Eclipse Draw2D / GEF for an information page describing the process in our application. It basically consists of a matrix of large squares, each containing a matrix of smaller squares. Initially we had all the squares as GEF objects, but due to the large volume of them it seemed that it did not scale very well and the presentation took a very long time. We then changed it so that only the large squares are shapes, and then draw the smaller squares using the graphics in paintFigure.

The problem we are facing is that we still want the tooltip to change depending on which small square you are hovering over. I tried to do this by adding a mouseMotionListener and setting the tooltip with setTooltip depending on where the mouse is. The problem is that after the tooltip is displayed, it no longer changes when setTooltip is called.

Does anyone know of an alternative way to do this? Is there a way to get the viewpart PopupHelper and use that? Any help would be appreciated.

thank

+2


source to share


2 answers


Hmnn .. interesting problem. Since you are drawing your own mesh inside the shape, I think you have two options.



  • Try posting SWT events to trick Eclipse. I would try to lose focus followed by targeted success to invoke the tooltip tools, after which you could get the coordinates and display the appropriate content.

  • Don't use the # getTooltip drawing strategy at all. Just show your own lineup.

+1


source


To dynamically change the tooltip, you can hold the tooltip instance in your parent drawing. In the parent graphic's constructor, create a new tooltip (such as a label) and use the setToolTip () method to set the tooltip to the parent graphic.

When the data model changes, the updated tooltip text / icon can be set to the tooltip. Then you call setToolTip (tooltipFigure) method again.

You can have a method like:



protected Label toolTipLabel;

protected void updateToolTip (line text, image icon) {
toolTipLabel.setText (text);
toolTipLabel.setIcon (icon);
setToolTip (toolTipLabel);
}

The updateToolTip () method can be called on the parent shape outline to initialize the tooltip. And this method can be called every time after changing the data model.

I faced the same problem in my code and solved it with this method. In my code, I called updateToolTip () in the parentFigure.paintFigure () method.

+1


source







All Articles