Tooltips for GWT tree: adding mouseovers to nodes?

A TreeItem can contains a Widget object. So add a MouseOverHandler and a MouseOutHandler on a widget (i.e. A Label) and put the widget inside the TreeItem to add.

A TreeItem can contains a Widget object. So add a MouseOverHandler and a MouseOutHandler on a widget (i.e. A Label) and put the widget inside the TreeItem to add : Label myItemContent = new Label("My content"); myItemContent.

AddMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { // construct and/or open your tooltip } }); myItemContent. AddMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { // close your tooltip } }); //put your Label inside a TreeItem TreeItem myItem = new TreeItem(myItemContent); // let's assume that parentNode is an ItemTree parentNode. AddItem(myItem); An other solution can be to use GwtQuery.

GwtQuery allows to bind event handler to any DOM element : import static com.google.gwt.query.client.GQuery. $; ... TreeItem myItem = new TreeItem("My content"); $(myItem.getElement()). Hover(new Function() { //method called on mouse over public void f(Element e) { // construct and/or open your tooltip } }, new Function() { //method called on mouse out public void f(Element e) { //close your tooltip } }); parentNode.

AddItem(myItem); Julien.

That's precisely what I was looking for. Thanks Julien! – Goren Apr 14 at 17:59.

I'm going to stick my neck out a bit here since I haven't actually used a Tree in GWT yet, but I see that the TreeItem class is a subclass of UIObject. Any UIObject can have its setTitle() method called. Under the hood, this method sets the standard HTML title attribute to be whatever string you pass into setTitle().

This should give you the tooltip behavior you seek. As an added bonus, the browser does all of the mouse event handling for you: import com.google.gwt.user.client.ui. Composite; import com.google.gwt.user.client.ui.

Tree; import com.google.gwt.user.client.ui. TreeItem; public class TreeTest extends Composite { public TreeTest() { Tree root = new Tree(); initWidget(root); TreeItem dogs = new TreeItem("canines"); dogs. AddItem("Fido").

SetTitle("faithful"); dogs. AddItem("Lassie"). SetTitle("starlet"); dogs.

AddItem("Touser"). SetTitle("ruthless killer"); root. AddItem(dogs); TreeItem cats = new TreeItem("felines"); cats.

AddItem("Boots"). SetTitle("needy"); cats. AddItem("Fabio").

SetTitle("aloof"); cats. AddItem("Mandu"). SetTitle("bob seger"); root.

AddItem(cats); } } Edit: Now let's imagine that you don't want to use the browser's built-in tool-tip mechanism described above, and that you would like to handle the mouse events yourself. TreeItem might look, on the surface, as a non-starter. After all, it inherits directly from UIObject and not from Widget.(The key difference that a Widget adds to UIObject is, after all, the ability to handle events.So one would think that we cannot add handlers to the TreeItem!

) While this is strictly true, notice that TreeItem gives us the following constructor: public TreeItem(Widget widget) When we make each instance, then, we can pass a real Widget into it (such as a Label, perhaps, or maybe your own class MyWidget extends Composite) and we can add event handlers directly to that: import com.google.gwt.core.client. GWT; import com.google.gwt.event.dom.client. MouseOutEvent; import com.google.gwt.event.dom.client.

MouseOutHandler; import com.google.gwt.event.dom.client. MouseOverEvent; import com.google.gwt.event.dom.client. MouseOverHandler; import com.google.gwt.user.client.ui.

Composite; import com.google.gwt.user.client.ui. Label; import com.google.gwt.user.client.ui. Tree; import com.google.gwt.user.client.ui.

TreeItem; public class AnotherTreeTest extends Composite { public AnotherTreeTest() { Tree root = new Tree(); initWidget(root); TreeItem dogs = new TreeItem("canines"); makeItem(dogs,"Fido","faithful"); makeItem(dogs,"Lassie","starlet"); makeItem(dogs,"Touser","ruthless killer"); root. AddItem(dogs); TreeItem cats = new TreeItem("felines"); makeItem(cats,"Boots","needy"); makeItem(cats,"Fabio","aloof"); makeItem(cats,"Mandu","bob seger"); root. AddItem(cats); } private void makeItem(TreeItem parent, String name, final String tip) { Label label = new Label(name); TreeItem animal = new TreeItem(label); label.

AddMouseOverHandler(new MouseOverHandler() { @Override public void onMouseOver(MouseOverEvent event) { GWT. Log("mouse over " + tip); // do something better here } }); label. AddMouseOutHandler(new MouseOutHandler() { @Override public void onMouseOut(MouseOutEvent event) { GWT.

Log("mouse out " + tip); // do something better here } }); parent. AddItem(animal); } } Note that there may be other ways to accomplish this that are less expensive. If you have an enormous tree, then creating a Widget for each node can get expensive.

Then you might want to explore a more sophisticated way of dealing with your mouse events, perhaps by having one handler that checks to see which element it is in.

While that's definitely helpful, I'm looking to have different tooltips for each different node in the tree. This gives one tooltip for the entire tree, correct? – Goren Apr 13 at 14:32 1 No, I'm pretty sure that a TreeItem is used to represent each node, so you should be able to call setTitle() on each one to give each a distinct tooltip.

Note that pretty much everything in GWT eventually inherits from UIObject, so this is a pretty universal rule. Whenever you want a tooltip, go look at the Javadoc -- if you see UIObject in the chain of superclasses, you're good to go. – pohl Apr 13 at 15:00 Ah thanks.

Any idea about the main part of the question regarding mouse listeners? – Goren Apr 13 at 16:07 I added another idea above for event handling. – pohl Apr 13 at 21:28.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions