- /*\r
- @VaadinApache2LicenseForJavaFiles@\r
- */\r
- package com.vaadin.terminal.gwt.client;\r
- \r
- import java.util.Collection;\r
- import java.util.Collections;\r
- import java.util.HashMap;\r
- import java.util.HashSet;\r
- import java.util.Iterator;\r
- import java.util.Map;\r
- import java.util.Set;\r
- \r
- import com.google.gwt.core.client.GWT;\r
- import com.google.gwt.user.client.Element;\r
- import com.google.gwt.user.client.ui.HasWidgets;\r
- import com.google.gwt.user.client.ui.Widget;\r
- import com.vaadin.terminal.Paintable;\r
- import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;\r
- import com.vaadin.terminal.gwt.client.RenderInformation.Size;\r
- \r
- public class VPaintableMap {\r
- \r
- private Map<String, VPaintable> idToPaintable = new HashMap<String, VPaintable>();\r
- private Map<VPaintable, String> paintableToId = new HashMap<VPaintable, String>();\r
- \r
- public static VPaintableMap get(ApplicationConnection applicationConnection) {\r
- return applicationConnection.getPaintableMap();\r
- }\r
- \r
- @Deprecated\r
- private final ComponentDetailMap idToComponentDetail = ComponentDetailMap\r
- .create();\r
- \r
- private Set<String> unregistryBag = new HashSet<String>();\r
- \r
- /**\r
- * Returns a Paintable by its paintable id\r
- * \r
- * @param id\r
- * The Paintable id\r
- */\r
- public VPaintable getPaintable(String pid) {\r
- return idToPaintable.get(pid);\r
- }\r
- \r
- /**\r
- * Returns a Paintable element by its root element\r
- * \r
- * @param element\r
- * Root element of the paintable\r
- */\r
- public VPaintableWidget getPaintable(Element element) {\r
- return (VPaintableWidget) getPaintable(getPid(element));\r
- }\r
- \r
- /**\r
- * FIXME: What does this even do and why?\r
- * \r
- * @param pid\r
- * @return\r
- */\r
- public boolean isDragAndDropPaintable(String pid) {\r
- return (pid.startsWith("DD"));\r
- }\r
- \r
- /**\r
- * Checks if a paintable with the given paintable id has been registered.\r
- * \r
- * @param pid\r
- * The paintable id to check for\r
- * @return true if a paintable has been registered with the given paintable\r
- * id, false otherwise\r
- */\r
- public boolean hasPaintable(String pid) {\r
- return idToPaintable.containsKey(pid);\r
- }\r
- \r
- /**\r
- * Removes all registered paintable ids\r
- */\r
- public void clear() {\r
- idToPaintable.clear();\r
- paintableToId.clear();\r
- idToComponentDetail.clear();\r
- }\r
- \r
- @Deprecated\r
- public Widget getWidget(VPaintableWidget paintable) {\r
- return paintable.getWidgetForPaintable();\r
- }\r
- \r
- @Deprecated\r
- public VPaintableWidget getPaintable(Widget widget) {\r
- return getPaintable(widget.getElement());\r
- }\r
- \r
- public void registerPaintable(String pid, VPaintable paintable) {\r
- ComponentDetail componentDetail = GWT.create(ComponentDetail.class);\r
- idToComponentDetail.put(pid, componentDetail);\r
- idToPaintable.put(pid, paintable);\r
- paintableToId.put(paintable, pid);\r
- if (paintable instanceof VPaintableWidget) {\r
- VPaintableWidget pw = (VPaintableWidget) paintable;\r
- setPid(pw.getWidgetForPaintable().getElement(), pid);\r
- }\r
- }\r
- \r
- private native void setPid(Element el, String pid)\r
- /*-{\r
- el.tkPid = pid;\r
- }-*/;\r
- \r
- /**\r
- * Gets the paintableId for a specific paintable.\r
- * <p>\r
- * The paintableId is used in the UIDL to identify a specific widget\r
- * instance, effectively linking the widget with it's server side Component.\r
- * </p>\r
- * \r
- * @param paintable\r
- * the paintable who's id is needed\r
- * @return the id for the given paintable or null if the paintable could not\r
- * be found\r
- */\r
- public String getPid(VPaintable paintable) {\r
- if (paintable == null) {\r
- return null;\r
- }\r
- return paintableToId.get(paintable);\r
- }\r
- \r
- @Deprecated\r
- public String getPid(Widget widget) {\r
- return getPid(widget.getElement());\r
- }\r
- \r
- /**\r
- * Gets the paintableId using a DOM element - the element should be the main\r
- * element for a paintable otherwise no id will be found. Use\r
- * {@link #getPid(Paintable)} instead whenever possible.\r
- * \r
- * @see #getPid(Paintable)\r
- * @param el\r
- * element of the paintable whose pid is desired\r
- * @return the pid of the element's paintable, if it's a paintable\r
- */\r
- native String getPid(Element el)\r
- /*-{\r
- return el.tkPid;\r
- }-*/;\r
- \r
- /**\r
- * Gets the main element for the paintable with the given id. The revers of\r
- * {@link #getPid(Element)}.\r
- * \r
- * @param pid\r
- * the pid of the widget whose element is desired\r
- * @return the element for the paintable corresponding to the pid\r
- */\r
- public Element getElement(String pid) {\r
- VPaintable p = getPaintable(pid);\r
- if (p instanceof VPaintableWidget) {\r
- return ((VPaintableWidget) p).getWidgetForPaintable().getElement();\r
- }\r
- \r
- return null;\r
- }\r
- \r
- /**\r
- * Unregisters the given paintable; always use after removing a paintable.\r
- * This method does not remove the paintable from the DOM, but marks the\r
- * paintable so that ApplicationConnection may clean up its references to\r
- * it. Removing the widget from DOM is component containers responsibility.\r
- * \r
- * @param p\r
- * the paintable to remove\r
- */\r
- public void unregisterPaintable(VPaintable p) {\r
- \r
- // add to unregistry que\r
- \r
- if (p == null) {\r
- VConsole.error("WARN: Trying to unregister null paintable");\r
- return;\r
- }\r
- String id = getPid(p);\r
- Widget widget = null;\r
- if (p instanceof VPaintableWidget) {\r
- widget = ((VPaintableWidget) p).getWidgetForPaintable();\r
- }\r
- \r
- if (id == null) {\r
- /*\r
- * Uncomment the following to debug unregistring components. No\r
- * paintables with null id should end here. At least one exception\r
- * is our VScrollTableRow, that is hacked to fake it self as a\r
- * Paintable to build support for sizing easier.\r
- */\r
- // if (!(p instanceof VScrollTableRow)) {\r
- // VConsole.log("Trying to unregister Paintable not created by Application Connection.");\r
- // }\r
- } else {\r
- unregistryBag.add(id);\r
- }\r
- if (widget != null && widget instanceof HasWidgets) {\r
- unregisterChildPaintables((HasWidgets) widget);\r
- }\r
- \r
- }\r
- \r
- void purgeUnregistryBag(boolean unregisterPaintables) {\r
- if (unregisterPaintables) {\r
- for (String pid : unregistryBag) {\r
- VPaintable paintable = getPaintable(pid);\r
- if (paintable == null) {\r
- /*\r
- * this should never happen, but it does :-( See e.g.\r
- * com.vaadin.tests.components.accordion.RemoveTabs (with\r
- * test script)\r
- */\r
- VConsole.error("Tried to unregister component (id="\r
- + pid\r
- + ") that is never registered (or already unregistered)");\r
- continue;\r
- }\r
- Widget widget = null;\r
- if (paintable instanceof VPaintableWidget) {\r
- widget = ((VPaintableWidget) paintable)\r
- .getWidgetForPaintable();\r
- }\r
- \r
- // check if can be cleaned\r
- if (widget == null || !widget.isAttached()) {\r
- // clean reference to paintable\r
- idToComponentDetail.remove(pid);\r
- idToPaintable.remove(pid);\r
- paintableToId.remove(paintable);\r
- // TODO purge shared state for pid\r
- }\r
- /*\r
- * else NOP : same component has been reattached to another\r
- * parent or replaced by another component implementation.\r
- */\r
- }\r
- }\r
- \r
- unregistryBag.clear();\r
- }\r
- \r
- /**\r
- * Unregisters a paintable and all it's child paintables recursively. Use\r
- * when after removing a paintable that contains other paintables. Does not\r
- * unregister the given container itself. Does not actually remove the\r
- * paintable from the DOM.\r
- * \r
- * @see #unregisterPaintable(Paintable)\r
- * @param container\r
- */\r
- public void unregisterChildPaintables(HasWidgets container) {\r
- // FIXME: This should be based on the paintable hierarchy\r
- final Iterator<Widget> it = container.iterator();\r
- while (it.hasNext()) {\r
- final Widget w = it.next();\r
- VPaintableWidget p = getPaintable(w);\r
- if (p != null) {\r
- // This will unregister the paintable and all its children\r
- unregisterPaintable(p);\r
- } else if (w instanceof HasWidgets) {\r
- // For normal widget containers, unregister the children\r
- unregisterChildPaintables((HasWidgets) w);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param pid\r
- * @param uidl\r
- */\r
- @Deprecated\r
- public void registerEventListenersFromUIDL(String pid, UIDL uidl) {\r
- ComponentDetail cd = idToComponentDetail.get(pid);\r
- if (cd == null) {\r
- throw new IllegalArgumentException("Pid must not be null");\r
- }\r
- \r
- cd.registerEventListenersFromUIDL(uidl);\r
- \r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public Size getOffsetSize(VPaintableWidget paintable) {\r
- return getComponentDetail(paintable).getOffsetSize();\r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public FloatSize getRelativeSize(VPaintableWidget paintable) {\r
- return getComponentDetail(paintable).getRelativeSize();\r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public void setOffsetSize(VPaintableWidget paintable, Size newSize) {\r
- getComponentDetail(paintable).setOffsetSize(newSize);\r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public void setRelativeSize(VPaintableWidget paintable,\r
- FloatSize relativeSize) {\r
- getComponentDetail(paintable).setRelativeSize(relativeSize);\r
- \r
- }\r
- \r
- private ComponentDetail getComponentDetail(VPaintableWidget paintable) {\r
- return idToComponentDetail.get(getPid(paintable));\r
- }\r
- \r
- public int size() {\r
- return idToPaintable.size();\r
- }\r
- \r
- /**\r
- * FIXME: Should be moved to VAbstractPaintableWidget\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public TooltipInfo getTooltipInfo(VPaintableWidget paintable, Object key) {\r
- return getComponentDetail(paintable).getTooltipInfo(key);\r
- }\r
- \r
- @Deprecated\r
- public TooltipInfo getWidgetTooltipInfo(Widget widget, Object key) {\r
- return getTooltipInfo(getPaintable(widget), key);\r
- }\r
- \r
- public Collection<? extends VPaintable> getPaintables() {\r
- return Collections.unmodifiableCollection(paintableToId.keySet());\r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public void registerTooltip(VPaintableWidget paintable, Object key,\r
- TooltipInfo tooltip) {\r
- getComponentDetail(paintable).putAdditionalTooltip(key, tooltip);\r
- \r
- }\r
- \r
- /**\r
- * FIXME: Should not be here\r
- * \r
- * @param paintable\r
- * @return\r
- */\r
- @Deprecated\r
- public boolean hasEventListeners(VPaintableWidget paintable,\r
- String eventIdentifier) {\r
- return getComponentDetail(paintable).hasEventListeners(eventIdentifier);\r
- }\r
- \r
- /**\r
- * Tests if the widget is the root widget of a VPaintableWidget.\r
- * \r
- * @param widget\r
- * The widget to test\r
- * @return true if the widget is the root widget of a VPaintableWidget,\r
- * false otherwise\r
- */\r
- public boolean isPaintable(Widget w) {\r
- return getPid(w) != null;\r
- }\r
- \r
- }\r
+ /*
+ @VaadinApache2LicenseForJavaFiles@
+ */
+ package com.vaadin.terminal.gwt.client;
+
+ import java.util.Collection;
+ import java.util.Collections;
+ import java.util.HashMap;
+ import java.util.HashSet;
+ import java.util.Iterator;
+ import java.util.Map;
+ import java.util.Set;
+
+ import com.google.gwt.core.client.GWT;
+ import com.google.gwt.user.client.Element;
+ import com.google.gwt.user.client.ui.HasWidgets;
+ import com.google.gwt.user.client.ui.Widget;
+ import com.vaadin.terminal.Paintable;
+ import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
+ import com.vaadin.terminal.gwt.client.RenderInformation.Size;
+
+ public class VPaintableMap {
+
+ private Map<String, VPaintable> idToPaintable = new HashMap<String, VPaintable>();
+ private Map<VPaintable, String> paintableToId = new HashMap<VPaintable, String>();
+
+ public static VPaintableMap get(ApplicationConnection applicationConnection) {
+ return applicationConnection.getPaintableMap();
+ }
+
+ @Deprecated
+ private final ComponentDetailMap idToComponentDetail = ComponentDetailMap
+ .create();
+
+ private Set<String> unregistryBag = new HashSet<String>();
+
+ /**
+ * Returns a Paintable by its paintable id
+ *
+ * @param id
+ * The Paintable id
+ */
+ public VPaintable getPaintable(String pid) {
+ return idToPaintable.get(pid);
+ }
+
+ /**
+ * Returns a Paintable element by its root element
+ *
+ * @param element
+ * Root element of the paintable
+ */
+ public VPaintableWidget getPaintable(Element element) {
+ return (VPaintableWidget) getPaintable(getPid(element));
+ }
+
+ /**
+ * FIXME: What does this even do and why?
+ *
+ * @param pid
+ * @return
+ */
+ public boolean isDragAndDropPaintable(String pid) {
+ return (pid.startsWith("DD"));
+ }
+
+ /**
+ * Checks if a paintable with the given paintable id has been registered.
+ *
+ * @param pid
+ * The paintable id to check for
+ * @return true if a paintable has been registered with the given paintable
+ * id, false otherwise
+ */
+ public boolean hasPaintable(String pid) {
+ return idToPaintable.containsKey(pid);
+ }
+
+ /**
+ * Removes all registered paintable ids
+ */
+ public void clear() {
+ idToPaintable.clear();
+ paintableToId.clear();
+ idToComponentDetail.clear();
+ }
+
+ @Deprecated
+ public Widget getWidget(VPaintableWidget paintable) {
+ return paintable.getWidgetForPaintable();
+ }
+
+ @Deprecated
+ public VPaintableWidget getPaintable(Widget widget) {
+ return getPaintable(widget.getElement());
+ }
+
+ public void registerPaintable(String pid, VPaintable paintable) {
+ ComponentDetail componentDetail = GWT.create(ComponentDetail.class);
+ idToComponentDetail.put(pid, componentDetail);
+ idToPaintable.put(pid, paintable);
+ paintableToId.put(paintable, pid);
+ if (paintable instanceof VPaintableWidget) {
+ VPaintableWidget pw = (VPaintableWidget) paintable;
+ setPid(pw.getWidgetForPaintable().getElement(), pid);
+ }
+ }
+
+ private native void setPid(Element el, String pid)
+ /*-{
+ el.tkPid = pid;
+ }-*/;
+
+ /**
+ * Gets the paintableId for a specific paintable.
+ * <p>
+ * The paintableId is used in the UIDL to identify a specific widget
+ * instance, effectively linking the widget with it's server side Component.
+ * </p>
+ *
+ * @param paintable
+ * the paintable who's id is needed
+ * @return the id for the given paintable or null if the paintable could not
+ * be found
+ */
+ public String getPid(VPaintable paintable) {
+ if (paintable == null) {
+ return null;
+ }
+ return paintableToId.get(paintable);
+ }
+
+ @Deprecated
+ public String getPid(Widget widget) {
+ return getPid(widget.getElement());
+ }
+
+ /**
+ * Gets the paintableId using a DOM element - the element should be the main
+ * element for a paintable otherwise no id will be found. Use
+ * {@link #getPid(Paintable)} instead whenever possible.
+ *
+ * @see #getPid(Paintable)
+ * @param el
+ * element of the paintable whose pid is desired
+ * @return the pid of the element's paintable, if it's a paintable
+ */
+ native String getPid(Element el)
+ /*-{
+ return el.tkPid;
+ }-*/;
+
+ /**
+ * Gets the main element for the paintable with the given id. The revers of
+ * {@link #getPid(Element)}.
+ *
+ * @param pid
+ * the pid of the widget whose element is desired
+ * @return the element for the paintable corresponding to the pid
+ */
+ public Element getElement(String pid) {
+ VPaintable p = getPaintable(pid);
+ if (p instanceof VPaintableWidget) {
+ return ((VPaintableWidget) p).getWidgetForPaintable().getElement();
+ }
+
+ return null;
+ }
+
+ /**
+ * Unregisters the given paintable; always use after removing a paintable.
+ * This method does not remove the paintable from the DOM, but marks the
+ * paintable so that ApplicationConnection may clean up its references to
+ * it. Removing the widget from DOM is component containers responsibility.
+ *
+ * @param p
+ * the paintable to remove
+ */
+ public void unregisterPaintable(VPaintable p) {
+
+ // add to unregistry que
+
+ if (p == null) {
+ VConsole.error("WARN: Trying to unregister null paintable");
+ return;
+ }
+ String id = getPid(p);
+ Widget widget = null;
+ if (p instanceof VPaintableWidget) {
+ widget = ((VPaintableWidget) p).getWidgetForPaintable();
+ }
+
+ if (id == null) {
+ /*
+ * Uncomment the following to debug unregistring components. No
+ * paintables with null id should end here. At least one exception
+ * is our VScrollTableRow, that is hacked to fake it self as a
+ * Paintable to build support for sizing easier.
+ */
+ // if (!(p instanceof VScrollTableRow)) {
+ // VConsole.log("Trying to unregister Paintable not created by Application Connection.");
+ // }
+ } else {
+ unregistryBag.add(id);
+ }
+ if (widget != null && widget instanceof HasWidgets) {
+ unregisterChildPaintables((HasWidgets) widget);
+ }
+
+ }
+
+ void purgeUnregistryBag(boolean unregisterPaintables) {
+ if (unregisterPaintables) {
+ for (String pid : unregistryBag) {
++ // TODO purge shared state for pid
+ VPaintable paintable = getPaintable(pid);
+ if (paintable == null) {
+ /*
+ * this should never happen, but it does :-( See e.g.
+ * com.vaadin.tests.components.accordion.RemoveTabs (with
+ * test script)
+ */
+ VConsole.error("Tried to unregister component (id="
+ + pid
+ + ") that is never registered (or already unregistered)");
+ continue;
+ }
+ Widget widget = null;
+ if (paintable instanceof VPaintableWidget) {
+ widget = ((VPaintableWidget) paintable)
+ .getWidgetForPaintable();
+ }
+
+ // check if can be cleaned
+ if (widget == null || !widget.isAttached()) {
+ // clean reference to paintable
+ idToComponentDetail.remove(pid);
+ idToPaintable.remove(pid);
+ paintableToId.remove(paintable);
+ }
+ /*
+ * else NOP : same component has been reattached to another
+ * parent or replaced by another component implementation.
+ */
+ }
+ }
+
+ unregistryBag.clear();
+ }
+
+ /**
+ * Unregisters a paintable and all it's child paintables recursively. Use
+ * when after removing a paintable that contains other paintables. Does not
+ * unregister the given container itself. Does not actually remove the
+ * paintable from the DOM.
+ *
+ * @see #unregisterPaintable(Paintable)
+ * @param container
+ */
+ public void unregisterChildPaintables(HasWidgets container) {
+ // FIXME: This should be based on the paintable hierarchy
+ final Iterator<Widget> it = container.iterator();
+ while (it.hasNext()) {
+ final Widget w = it.next();
+ VPaintableWidget p = getPaintable(w);
+ if (p != null) {
+ // This will unregister the paintable and all its children
+ unregisterPaintable(p);
+ } else if (w instanceof HasWidgets) {
+ // For normal widget containers, unregister the children
+ unregisterChildPaintables((HasWidgets) w);
+ }
+ }
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param pid
+ * @param uidl
+ */
+ @Deprecated
+ public void registerEventListenersFromUIDL(String pid, UIDL uidl) {
+ ComponentDetail cd = idToComponentDetail.get(pid);
+ if (cd == null) {
+ throw new IllegalArgumentException("Pid must not be null");
+ }
+
+ cd.registerEventListenersFromUIDL(uidl);
+
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public Size getOffsetSize(VPaintableWidget paintable) {
+ return getComponentDetail(paintable).getOffsetSize();
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public FloatSize getRelativeSize(VPaintableWidget paintable) {
+ return getComponentDetail(paintable).getRelativeSize();
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public void setOffsetSize(VPaintableWidget paintable, Size newSize) {
+ getComponentDetail(paintable).setOffsetSize(newSize);
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public void setRelativeSize(VPaintableWidget paintable,
+ FloatSize relativeSize) {
+ getComponentDetail(paintable).setRelativeSize(relativeSize);
+
+ }
+
+ private ComponentDetail getComponentDetail(VPaintableWidget paintable) {
+ return idToComponentDetail.get(getPid(paintable));
+ }
+
+ public int size() {
+ return idToPaintable.size();
+ }
+
+ /**
+ * FIXME: Should be moved to VAbstractPaintableWidget
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public TooltipInfo getTooltipInfo(VPaintableWidget paintable, Object key) {
+ return getComponentDetail(paintable).getTooltipInfo(key);
+ }
+
+ @Deprecated
+ public TooltipInfo getWidgetTooltipInfo(Widget widget, Object key) {
+ return getTooltipInfo(getPaintable(widget), key);
+ }
+
+ public Collection<? extends VPaintable> getPaintables() {
+ return Collections.unmodifiableCollection(paintableToId.keySet());
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public void registerTooltip(VPaintableWidget paintable, Object key,
+ TooltipInfo tooltip) {
+ getComponentDetail(paintable).putAdditionalTooltip(key, tooltip);
+
+ }
+
+ /**
+ * FIXME: Should not be here
+ *
+ * @param paintable
+ * @return
+ */
+ @Deprecated
+ public boolean hasEventListeners(VPaintableWidget paintable,
+ String eventIdentifier) {
+ return getComponentDetail(paintable).hasEventListeners(eventIdentifier);
+ }
+
+ /**
+ * Tests if the widget is the root widget of a VPaintableWidget.
+ *
+ * @param widget
+ * The widget to test
+ * @return true if the widget is the root widget of a VPaintableWidget,
+ * false otherwise
+ */
+ public boolean isPaintable(Widget w) {
+ return getPid(w) != null;
+ }
+
+ }