diff options
author | John Alhroos <john.ahlroos@itmill.com> | 2011-08-16 11:57:04 +0000 |
---|---|---|
committer | John Alhroos <john.ahlroos@itmill.com> | 2011-08-16 11:57:04 +0000 |
commit | 2d518450045c8df937cf1f5d2557c1a4673667b1 (patch) | |
tree | ee1f11b06a370b9cbfb2aedd8ea7d632a33cc498 /src | |
parent | 3e2524d2d0a45e2571c643f7e173acaff640088d (diff) | |
download | vaadin-framework-2d518450045c8df937cf1f5d2557c1a4673667b1.tar.gz vaadin-framework-2d518450045c8df937cf1f5d2557c1a4673667b1.zip |
Tooltips for Tree + Testbech test for them #6637
svn changeset:20415/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VTree.java | 18 | ||||
-rw-r--r-- | src/com/vaadin/ui/Tree.java | 35 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index a8974aa5bc..a1647c2c52 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -41,8 +41,10 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.dd.DDUtil; import com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler; import com.vaadin.terminal.gwt.client.ui.dd.VAcceptCallback; @@ -760,6 +762,11 @@ public class VTree extends FocusElementPanel implements Paintable, if (disabled) { return; } + + if (target == nodeCaptionSpan) { + client.handleTooltipEvent(event, VTree.this, key); + } + final boolean inCaption = target == nodeCaptionSpan || (icon != null && target == icon.getElement()); if (inCaption @@ -932,6 +939,7 @@ public class VTree extends FocusElementPanel implements Paintable, + "-caption"); Element wrapper = DOM.createDiv(); nodeCaptionSpan = DOM.createSpan(); + DOM.sinkEvents(nodeCaptionSpan, VTooltip.TOOLTIP_EVENTS); DOM.appendChild(getElement(), nodeCaptionDiv); DOM.appendChild(nodeCaptionDiv, wrapper); DOM.appendChild(wrapper, nodeCaptionSpan); @@ -977,6 +985,16 @@ public class VTree extends FocusElementPanel implements Paintable, + uidl.getStringAttribute("style")); } + String description = uidl.getStringAttribute("descr"); + if (description != null && client != null) { + // Set tooltip + TooltipInfo info = new TooltipInfo(description); + client.registerTooltip(VTree.this, key, info); + } else { + // Remove possible previous tooltip + client.registerTooltip(VTree.this, key, null); + } + if (uidl.getBooleanAttribute("expanded") && !getState()) { setState(true, false); } diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 3e6d62033e..ede37f2c60 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -104,6 +104,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, private boolean initialPaint = true; /** + * Item tooltip generator + */ + private ItemDescriptionGenerator itemDescriptionGenerator; + + /** * Supported drag modes for Tree. */ public enum TreeDragMode { @@ -608,6 +613,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } } + if (itemDescriptionGenerator != null) { + String description = itemDescriptionGenerator + .generateDescription(this, itemId, null); + if (description != null && !description.equals("")) { + target.addAttribute("descr", description); + } + } + // Adds the attributes target.addAttribute("caption", getItemCaption(itemId)); final Resource icon = getItemIcon(itemId); @@ -1562,4 +1575,26 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } + /** + * Set the item description generator which generates tooltips for the tree + * items + * + * @param generator + * The generator to use or null to disable + */ + public void setItemDescriptionGenerator(ItemDescriptionGenerator generator) { + if (generator != itemDescriptionGenerator) { + itemDescriptionGenerator = generator; + requestRepaint(); + } + } + + /** + * Get the item description generator which generates tooltips for tree + * items + */ + public ItemDescriptionGenerator getItemDescriptionGenerator() { + return itemDescriptionGenerator; + } + } |