public static final String PARAM_UNLOADBURST = "onunloadburst";
+ public static final String ATTRIBUTE_DESCRIPTION = "description";
+ public static final String ATTRIBUTE_ERROR = "error";
+
private static String uidl_security_key = "init";
private final HashMap<String, String> resourcesMap = new HashMap<String, String>();
styleBuf.append(MODIFIED_CLASSNAME);
}
- TooltipInfo tooltipInfo = componentDetail.getTooltipInfo();
- if (uidl.hasAttribute("description")) {
- tooltipInfo.setTitle(uidl.getStringAttribute("description"));
+ // Update tooltip
+ if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)
+ || uidl.hasAttribute(ATTRIBUTE_ERROR)) {
+ TooltipInfo tooltipInfo = new TooltipInfo();
+
+ if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) {
+ tooltipInfo.setTitle(uidl
+ .getStringAttribute(ATTRIBUTE_DESCRIPTION));
+ }
+
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
+ tooltipInfo.setErrorUidl(uidl.getErrors());
+ }
+
+ registerTooltip(component.getElement(), tooltipInfo);
} else {
- tooltipInfo.setTitle(null);
+ registerTooltip(component.getElement(), (TooltipInfo) null);
}
// add error classname to components w/ error
- if (uidl.hasAttribute("error")) {
+ if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
styleBuf.append(" ");
styleBuf.append(primaryName);
styleBuf.append(ERROR_CLASSNAME_EXT);
-
- tooltipInfo.setErrorUidl(uidl.getErrors());
- } else {
- tooltipInfo.setErrorUidl(null);
}
// add required style to required components
*
*/
public TooltipInfo getTitleInfo(Paintable titleOwner) {
- if (null == titleOwner) {
- return null;
- }
- ComponentDetail pd = idToPaintableDetail.get(getPid(titleOwner));
- if (null != pd) {
- return pd.getTooltipInfo();
- } else {
- return null;
- }
+ return tooltip.getTooltip(((Widget) titleOwner).getElement());
}
private final VTooltip tooltip = new VTooltip(this);
return view;
}
+ public void registerTooltip(Element e, String tooltip) {
+ if (tooltip == null || tooltip.equals("")) {
+ registerTooltip(e, (TooltipInfo) null);
+ } else {
+ registerTooltip(e, new TooltipInfo(tooltip));
+ }
+ }
+
+ public void registerTooltip(Element e, TooltipInfo tooltip) {
+ this.tooltip.registerTooltip(e, tooltip);
+ }
+
}
this.component = component;
}
- /**
- * @return the tooltipInfo
- */
- TooltipInfo getTooltipInfo() {
- return tooltipInfo;
- }
-
- /**
- * @param tooltipInfo
- * the tooltipInfo to set
- */
- void setTooltipInfo(TooltipInfo tooltipInfo) {
- this.tooltipInfo = tooltipInfo;
- }
-
/**
* @return the relativeSize
*/
private UIDL errorUidl;
+ public TooltipInfo() {
+ }
+
+ public TooltipInfo(String tooltip) {
+ setTitle(tooltip);
+ }
+
public String getTitle() {
return title;
}
private int maxWidth = -1;
- private static String ATTRIBUTE_ICON = "icon";
- private static String ATTRIBUTE_CAPTION = "caption";
- private static String ATTRIBUTE_DESCRIPTION = "description";
- private static String ATTRIBUTE_REQUIRED = "required";
- private static String ATTRIBUTE_ERROR = "error";
- private static String ATTRIBUTE_HIDEERRORS = "hideErrors";
+ protected static final String ATTRIBUTE_ICON = "icon";
+ protected static final String ATTRIBUTE_CAPTION = "caption";
+ protected static final String ATTRIBUTE_DESCRIPTION = "description";
+ protected static final String ATTRIBUTE_REQUIRED = "required";
+ protected static final String ATTRIBUTE_ERROR = "error";
+ protected static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
/**
*
VErrorMessage em = new VErrorMessage();
Element description = DOM.createDiv();
private Paintable tooltipOwner;
+ private Element tooltipTargetElement;
+
private boolean closing = false;
private boolean opening = false;
private ApplicationConnection ac;
// Open next tooltip faster. Disabled after 2 sec of showTooltip-silence.
private boolean justClosed = false;
+ private TooltipInfo visibleTooltip = null;
public VTooltip(ApplicationConnection client) {
super(false, false, true);
DOM.appendChild(layout.getElement(), description);
}
+ /**
+ * Show a popup containing the information in the "info" tooltip
+ *
+ * @param info
+ */
private void show(TooltipInfo info) {
boolean hasContent = false;
if (info.getErrorUidl() != null) {
sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
}
});
+ visibleTooltip = info;
} else {
hide();
+ visibleTooltip = null;
}
}
public void showTooltip(Paintable owner, Event event) {
+ Element targetElement = event.getEventTarget().cast();
if (closing && tooltipOwner == owner) {
- // return to same tooltip, cancel closing
- closeTimer.cancel();
- closing = false;
- justClosedTimer.cancel();
- justClosed = false;
- return;
+ TooltipInfo newToolTip = getTooltip(owner, targetElement);
+ if (newToolTip == visibleTooltip) {
+ // return to same tooltip, cancel closing
+ closeTimer.cancel();
+ closing = false;
+ justClosedTimer.cancel();
+ justClosed = false;
+ return;
+ }
}
if (closing) {
showTimer.cancel();
}
tooltipOwner = owner;
+ tooltipTargetElement = targetElement;
+
+ // Schedule timer for showing the tooltip according to if it was
+ // recently closed or not.
if (justClosed) {
showTimer.schedule(QUICK_OPEN_DELAY);
} else {
private Timer showTimer = new Timer() {
@Override
public void run() {
- TooltipInfo info = ac.getTitleInfo(tooltipOwner);
+ TooltipInfo info = getTooltip(tooltipOwner, tooltipTargetElement);
if (null != info) {
show(info);
}
}
+ /**
+ * Returns the tooltip that should be shown for the element. Searches upward
+ * in the DOM tree for registered tooltips until the root of the Paintable
+ * is found. Returns null if no tooltip was found (none should be shown).
+ *
+ * @param paintable
+ * @param element
+ * @return
+ */
+ private TooltipInfo getTooltip(Paintable paintable, Element element) {
+ /* Try to find registered tooltips */
+ while (element != null) {
+ TooltipInfo info = getTooltip(element);
+ if (info != null) {
+ return info;
+ }
+
+ if (ac.getPid(element) != null) {
+ // This is the Paintable root so we stop searching
+ break;
+ }
+
+ element = DOM.getParent(element);
+ }
+
+ /*
+ * No registered tooltips found
+ */
+ return null;
+ }
+
private int tooltipEventMouseX;
private int tooltipEventMouseY;
}
}
+ native TooltipInfo getTooltip(Element e)
+ /*-{
+ return e.vaadinTooltip;
+ }-*/;
+
+ native void registerTooltip(Element e, TooltipInfo tooltipInfo)
+ /*-{
+ e.vaadinTooltip = tooltipInfo;
+ }-*/;
}