From 622545764d334b60951607e163523a2b62a99225 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 20 Jan 2012 17:23:55 +0200 Subject: [PATCH] Split Paintable handling from ApplicationConnection to PaintableMap. --- .../gwt/client/ApplicationConnection.java | 382 +++++------------- .../terminal/gwt/client/ComponentDetail.java | 42 +- .../terminal/gwt/client/ComponentLocator.java | 8 +- .../terminal/gwt/client/PaintableMap.java | 356 ++++++++++++++++ src/com/vaadin/terminal/gwt/client/UIDL.java | 6 +- src/com/vaadin/terminal/gwt/client/Util.java | 12 +- .../vaadin/terminal/gwt/client/VCaption.java | 2 +- .../terminal/gwt/client/VDebugConsole.java | 4 +- .../terminal/gwt/client/VUIDLBrowser.java | 4 +- .../gwt/client/ui/ClickEventHandler.java | 4 +- .../client/ui/LayoutClickEventHandler.java | 4 +- .../gwt/client/ui/VDragAndDropWrapper.java | 3 +- .../terminal/gwt/client/ui/VMenuBar.java | 5 +- .../gwt/client/ui/VOrderedLayout.java | 3 +- .../terminal/gwt/client/ui/VScrollTable.java | 3 +- .../terminal/gwt/client/ui/VTextField.java | 2 +- .../gwt/client/ui/dd/VDragSourceIs.java | 7 +- .../terminal/gwt/client/ui/dd/VIsOverId.java | 12 +- .../terminal/gwt/client/ui/dd/VItemIdIs.java | 8 +- 19 files changed, 538 insertions(+), 329 deletions(-) create mode 100644 src/com/vaadin/terminal/gwt/client/PaintableMap.java diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 0b50c11597..04703b2dd0 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -106,9 +106,6 @@ public class ApplicationConnection { private final ArrayList pendingVariables = new ArrayList(); - private final ComponentDetailMap idToPaintableDetail = ComponentDetailMap - .create(); - private WidgetSet widgetSet; private VContextMenu contextMenu = null; @@ -149,8 +146,6 @@ public class ApplicationConnection { private Set zeroHeightComponents = null; - private Set unregistryBag = new HashSet(); - public ApplicationConnection() { view = GWT.create(VView.class); } @@ -418,7 +413,7 @@ public class ApplicationConnection { */ void highlightComponent(Paintable paintable) { String params = getRepaintAllParameters() + "&highlightComponent=" - + getPid(paintable); + + paintableMap.getPid(paintable); makeUidlRequest("", params, false); } @@ -775,7 +770,8 @@ public class ApplicationConnection { for (int i = 1; i < variableBurst.size(); i += 2) { String id = variableBurst.get(i); id = id.substring(0, id.indexOf(VAR_FIELD_SEPARATOR)); - if (!idToPaintableDetail.containsKey(id) && !id.startsWith("DD")) { + if (!getPaintableMap().hasPaintable(id) + && !getPaintableMap().isDragAndDropPaintable(id)) { // variable owner does not exist anymore variableBurst.remove(i - 1); variableBurst.remove(i - 1); @@ -932,7 +928,7 @@ public class ApplicationConnection { if (meta.containsKey("repaintAll")) { repaintAll = true; view.clear(); - idToPaintableDetail.clear(); + getPaintableMap().clear(); if (meta.containsKey("invalidLayouts")) { validatingLayouts = true; zeroWidthComponents = new HashSet(); @@ -970,16 +966,13 @@ public class ApplicationConnection { final UIDL change = changes.get(i).cast(); final UIDL uidl = change.getChildUIDL(0); // TODO optimize - final Paintable paintable = getPaintable(uidl.getId()); + final Paintable paintable = paintableMap + .getPaintable(uidl.getId()); if (paintable != null) { paintable.updateFromUIDL(uidl, ApplicationConnection.this); - // paintable may have changed during render to - // another - // implementation, use the new one for updated - // widgets map - updatedWidgets.add(idToPaintableDetail.get( - uidl.getId()).getComponent()); + + updatedWidgets.add(paintable); } else { if (!uidl.getTag().equals( configuration.getEncodedWindowTag())) { @@ -989,14 +982,13 @@ public class ApplicationConnection { + uidl.getId() + ") rendered."); } else { String pid = uidl.getId(); - if (!idToPaintableDetail.containsKey(pid)) { - registerPaintable(pid, view); + if (!paintableMap.hasPaintable(pid)) { + paintableMap.registerPaintable(pid, view); } // VView does not call updateComponent so we // register any event listeners here - ComponentDetail cd = idToPaintableDetail - .get(pid); - cd.registerEventListenersFromUIDL(uidl); + paintableMap.registerEventListenersFromUIDL( + pid, uidl); // Finally allow VView to update itself view.updateFromUIDL(uidl, @@ -1021,16 +1013,14 @@ public class ApplicationConnection { sizeUpdatedWidgets.addAll(componentCaptionSizeChanges); for (Paintable paintable : updatedWidgets) { - ComponentDetail detail = idToPaintableDetail - .get(getPid(paintable)); - Widget widget = (Widget) paintable; - Size oldSize = detail.getOffsetSize(); + Widget widget = paintableMap.getWidget(paintable); + Size oldSize = paintableMap.getOffsetSize(paintable); Size newSize = new Size(widget.getOffsetWidth(), widget.getOffsetHeight()); if (oldSize == null || !oldSize.equals(newSize)) { sizeUpdatedWidgets.add(paintable); - detail.setOffsetSize(newSize); + paintableMap.setOffsetSize(paintable, newSize); } } @@ -1084,9 +1074,9 @@ public class ApplicationConnection { * idToPaintableDetail is already cleanded at the start of * the changeset handling, bypass cleanup. */ - unregistryBag.clear(); + paintableMap.purgeUnregistryBag(false); } else { - purgeUnregistryBag(); + paintableMap.purgeUnregistryBag(true); } // TODO build profiling for widget impl loading time @@ -1096,8 +1086,7 @@ public class ApplicationConnection { VConsole.log(" Processing time was " + String.valueOf(prosessingTime) + "ms for " + jsonText.length() + " characters of JSON"); - VConsole.log("Referenced paintables: " - + idToPaintableDetail.size()); + VConsole.log("Referenced paintables: " + paintableMap.size()); endRequest(); @@ -1116,164 +1105,6 @@ public class ApplicationConnection { } }-*/; - public void registerPaintable(String pid, Paintable paintable) { - ComponentDetail componentDetail = new ComponentDetail(this, pid, - paintable); - idToPaintableDetail.put(pid, componentDetail); - setPid(((Widget) paintable).getElement(), pid); - } - - private native void setPid(Element el, String pid) - /*-{ - el.tkPid = pid; - }-*/; - - /** - * Gets the paintableId for a specific paintable (a.k.a Vaadin Widget). - *

- * The paintableId is used in the UIDL to identify a specific widget - * instance, effectively linking the widget with it's server side Component. - *

- * - * @param paintable - * the paintable who's id is needed - * @return the id for the given paintable - */ - public String getPid(Paintable paintable) { - return getPid(((Widget) paintable).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 - */ - public 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 getElementByPid(String pid) { - return ((Widget) getPaintable(pid)).getElement(); - } - - /** - * 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(Paintable p) { - - // add to unregistry que - - if (p == null) { - VConsole.error("WARN: Trying to unregister null paintable"); - return; - } - String id = getPid(p); - 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."); - // } - if (p instanceof HasWidgets) { - unregisterChildPaintables((HasWidgets) p); - } - } else { - unregistryBag.add(id); - if (p instanceof HasWidgets) { - unregisterChildPaintables((HasWidgets) p); - } - } - } - - private void purgeUnregistryBag() { - for (String id : unregistryBag) { - ComponentDetail componentDetail = idToPaintableDetail.get(id); - if (componentDetail == null) { - /* - * this should never happen, but it does :-( See e.g. - * com.vaadin.tests.components.accordion.RemoveTabs (with test - * script) - */ - VConsole.error("ApplicationConnetion tried to unregister component (id=" - + id - + ") that is never registered (or already unregistered)"); - continue; - } - // check if can be cleaned - Widget component = (Widget) componentDetail.getComponent(); - if (!component.isAttached()) { - // clean reference from ac to paintable - idToPaintableDetail.remove(id); - } - /* - * 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) { - final Iterator it = container.iterator(); - while (it.hasNext()) { - final Widget w = it.next(); - if (w instanceof Paintable) { - unregisterPaintable((Paintable) w); - } else if (w instanceof HasWidgets) { - unregisterChildPaintables((HasWidgets) w); - } - } - } - - /** - * Returns Paintable element by its id - * - * @param id - * Paintable ID - */ - public Paintable getPaintable(String id) { - ComponentDetail componentDetail = idToPaintableDetail.get(id); - if (componentDetail == null) { - return null; - } else { - return componentDetail.getComponent(); - } - } - private void addVariableToQueue(String paintableId, String variableName, String encodedValue, boolean immediate, char type) { final String id = paintableId + VAR_FIELD_SEPARATOR + variableName @@ -1396,7 +1227,7 @@ public class ApplicationConnection { */ public void updateVariable(String paintableId, String variableName, Paintable newValue, boolean immediate) { - String pid = (newValue != null) ? getPid(newValue) : null; + String pid = paintableMap.getPid(newValue); addVariableToQueue(paintableId, variableName, pid, immediate, 'p'); } @@ -1556,7 +1387,7 @@ public class ApplicationConnection { * the id of the paintable that owns the variable * @param variableName * the name of the variable - * @param newValue + * @param map * the new value to be sent * @param immediate * true if the update is to be sent as soon as possible @@ -1573,7 +1404,7 @@ public class ApplicationConnection { buf.append(escapeVariableValue(key)); buf.append(VAR_ARRAYITEM_SEPARATOR); if (transportType == 'p') { - buf.append(getPid((Paintable) value)); + buf.append(paintableMap.getPid((Paintable) value)); } else { buf.append(escapeVariableValue(String.valueOf(value))); } @@ -1674,7 +1505,7 @@ public class ApplicationConnection { // first char tells the type in array buf.append(transportType); if (transportType == 'p') { - buf.append(getPid((Paintable) value)); + buf.append(paintableMap.getPid((Paintable) value)); } else { buf.append(escapeVariableValue(String.valueOf(value))); } @@ -1757,22 +1588,15 @@ public class ApplicationConnection { */ public boolean updateComponent(Widget component, UIDL uidl, boolean manageCaption) { - String pid = getPid(component.getElement()); + Paintable paintable = paintableMap.getPaintable(component); + + String pid = paintableMap.getPid(paintable); if (pid == null) { VConsole.error("Trying to update an unregistered component: " + Util.getSimpleName(component)); return true; } - ComponentDetail componentDetail = idToPaintableDetail.get(pid); - - if (componentDetail == null) { - VConsole.error("ComponentDetail not found for " - + Util.getSimpleName(component) + " with PID " + pid - + ". This should not happen."); - return true; - } - // If the server request that a cached instance should be used, do // nothing if (uidl.getBooleanAttribute("cached")) { @@ -1781,7 +1605,7 @@ public class ApplicationConnection { // register the listened events by the server-side to the event-handler // of the component - componentDetail.registerEventListenersFromUIDL(uidl); + paintableMap.registerEventListenersFromUIDL(pid, uidl); // Visibility boolean visible = !uidl.getBooleanAttribute("invisible"); @@ -1807,7 +1631,7 @@ public class ApplicationConnection { if (!visible) { // component is invisible, delete old size to notify parent, if // later make visible - componentDetail.setOffsetSize(null); + paintableMap.setOffsetSize(paintable, null); return true; } @@ -1821,8 +1645,8 @@ public class ApplicationConnection { final Container parent = Util.getLayout(component); if (parent != null) { parent.replaceChildComponent(component, w); - unregisterPaintable((Paintable) component); - registerPaintable(uidl.getId(), (Paintable) w); + paintableMap.unregisterPaintable(paintable); + paintableMap.registerPaintable(uidl.getId(), (Paintable) w); ((Paintable) w).updateFromUIDL(uidl, this); return true; } @@ -1877,7 +1701,7 @@ public class ApplicationConnection { styleBuf.append(MODIFIED_CLASSNAME); } - TooltipInfo tooltipInfo = componentDetail.getTooltipInfo(null); + TooltipInfo tooltipInfo = paintableMap.getTooltipInfo(paintable, null); // Update tooltip if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) { tooltipInfo @@ -1918,12 +1742,12 @@ public class ApplicationConnection { * taken into account */ - updateComponentSize(componentDetail, uidl); + updateComponentSize(paintable, uidl); return false; } - private void updateComponentSize(ComponentDetail cd, UIDL uidl) { + private void updateComponentSize(Paintable paintable, UIDL uidl) { String w = uidl.hasAttribute("width") ? uidl .getStringAttribute("width") : ""; @@ -1938,20 +1762,22 @@ public class ApplicationConnection { // One or both is relative FloatSize relativeSize = new FloatSize(relativeWidth, relativeHeight); - if (cd.getRelativeSize() == null && cd.getOffsetSize() != null) { + + if (paintableMap.getRelativeSize(paintable) == null + && paintableMap.getOffsetSize(paintable) != null) { // The component has changed from absolute size to relative size - relativeSizeChanges.add(cd.getComponent()); + relativeSizeChanges.add(paintable); } - cd.setRelativeSize(relativeSize); + paintableMap.setRelativeSize(paintable, relativeSize); } else if (relativeHeight < 0.0 && relativeWidth < 0.0) { - if (cd.getRelativeSize() != null) { + if (paintableMap.getRelativeSize(paintable) != null) { // The component has changed from relative size to absolute size - relativeSizeChanges.add(cd.getComponent()); + relativeSizeChanges.add(paintable); } - cd.setRelativeSize(null); + paintableMap.setRelativeSize(paintable, null); } - Widget component = (Widget) cd.getComponent(); + Widget component = paintableMap.getWidget(paintable); // Set absolute sizes if (relativeHeight < 0.0) { component.setHeight(h); @@ -1963,7 +1789,7 @@ public class ApplicationConnection { // Set relative sizes if (relativeHeight >= 0.0 || relativeWidth >= 0.0) { // One or both is relative - handleComponentRelativeSize(cd); + handleComponentRelativeSize(paintable); } } @@ -1996,9 +1822,7 @@ public class ApplicationConnection { */ public void forceLayout() { Set set = new HashSet(); - for (ComponentDetail cd : idToPaintableDetail.values()) { - set.add(cd.getComponent()); - } + set.addAll(paintableMap.getPaintables()); Util.componentSizeUpdated(set); } @@ -2040,31 +1864,31 @@ public class ApplicationConnection { * @param child * @return true if the child has a relative size */ - private boolean handleComponentRelativeSize(ComponentDetail cd) { - if (cd == null) { + private boolean handleComponentRelativeSize(Paintable paintable) { + if (paintable == null) { return false; } boolean debugSizes = false; - FloatSize relativeSize = cd.getRelativeSize(); + FloatSize relativeSize = paintableMap.getRelativeSize(paintable); if (relativeSize == null) { return false; } - Widget widget = (Widget) cd.getComponent(); + Widget widget = paintableMap.getWidget(paintable); boolean horizontalScrollBar = false; boolean verticalScrollBar = false; - Container parent = Util.getLayout(widget); + Container parentPaintable = Util.getLayout(widget); RenderSpace renderSpace; // Parent-less components (like sub-windows) are relative to browser // window. - if (parent == null) { + if (parentPaintable == null) { renderSpace = new RenderSpace(Window.getClientWidth(), Window.getClientHeight()); } else { - renderSpace = parent.getAllocatedSpace(widget); + renderSpace = parentPaintable.getAllocatedSpace(widget); } if (relativeSize.getHeight() >= 0) { @@ -2088,7 +1912,7 @@ public class ApplicationConnection { height -= renderSpace.getScrollbarSize(); } if (validatingLayouts && height <= 0) { - zeroHeightComponents.add(cd.getComponent()); + zeroHeightComponents.add(paintable); } height = (int) (height * relativeSize.getHeight() / 100.0); @@ -2098,14 +1922,20 @@ public class ApplicationConnection { } if (debugSizes) { - VConsole.log("Widget " + Util.getSimpleName(widget) + "/" - + getPid(widget.getElement()) + " relative height " - + relativeSize.getHeight() + "% of " - + renderSpace.getHeight() + "px (reported by " - - + Util.getSimpleName(parent) + "/" - + (parent == null ? "?" : parent.hashCode()) - + ") : " + height + "px"); + VConsole.log("Widget " + + Util.getSimpleName(widget) + + "/" + + paintableMap.getPid(paintable) + + " relative height " + + relativeSize.getHeight() + + "% of " + + renderSpace.getHeight() + + "px (reported by " + + + Util.getSimpleName(parentPaintable) + + "/" + + (parentPaintable == null ? "?" : parentPaintable + .hashCode()) + ") : " + height + "px"); } widget.setHeight(height + "px"); } else { @@ -2137,7 +1967,7 @@ public class ApplicationConnection { width -= renderSpace.getScrollbarSize(); } if (validatingLayouts && width <= 0) { - zeroWidthComponents.add(cd.getComponent()); + zeroWidthComponents.add(paintable); } width = (int) (width * relativeSize.getWidth() / 100.0); @@ -2147,13 +1977,20 @@ public class ApplicationConnection { } if (debugSizes) { - VConsole.log("Widget " + Util.getSimpleName(widget) + "/" - + getPid(widget.getElement()) + " relative width " - + relativeSize.getWidth() + "% of " - + renderSpace.getWidth() + "px (reported by " - + Util.getSimpleName(parent) + "/" - + (parent == null ? "?" : getPid(parent)) + ") : " - + width + "px"); + VConsole.log("Widget " + + Util.getSimpleName(widget) + + "/" + + paintableMap.getPid(paintable) + + " relative width " + + relativeSize.getWidth() + + "% of " + + renderSpace.getWidth() + + "px (reported by " + + Util.getSimpleName(parentPaintable) + + "/" + + (parentPaintable == null ? "?" : paintableMap + .getPid(parentPaintable)) + ") : " + width + + "px"); } widget.setWidth(width + "px"); } else { @@ -2173,9 +2010,8 @@ public class ApplicationConnection { * @param child * @return true if the child has a relative size */ - public boolean handleComponentRelativeSize(Widget child) { - return handleComponentRelativeSize(idToPaintableDetail.get(getPid(child - .getElement()))); + public boolean handleComponentRelativeSize(Widget widget) { + return handleComponentRelativeSize(paintableMap.getPaintable(widget)); } @@ -2187,8 +2023,7 @@ public class ApplicationConnection { * @return the the size if the paintable is relatively sized, -1 otherwise */ public FloatSize getRelativeSize(Widget widget) { - return idToPaintableDetail.get(getPid(widget.getElement())) - .getRelativeSize(); + return paintableMap.getRelativeSize(paintableMap.getPaintable(widget)); } /** @@ -2204,26 +2039,13 @@ public class ApplicationConnection { * @return Either existing or new Paintable corresponding to UIDL. */ public Paintable getPaintable(UIDL uidl) { - final String id = uidl.getId(); - Paintable w = getPaintable(id); - if (w != null) { - return w; - } else { - w = widgetSet.createWidget(uidl, configuration); - registerPaintable(id, w); - return w; - + final String pid = uidl.getId(); + if (!paintableMap.hasPaintable(pid)) { + // Create and register a new paintable if no old was found + Paintable p = widgetSet.createWidget(uidl, configuration); + paintableMap.registerPaintable(pid, p); } - } - - /** - * Returns a Paintable element by its root element - * - * @param element - * Root element of the paintable - */ - public Paintable getPaintable(Element element) { - return getPaintable(getPid(element)); + return paintableMap.getPaintable(pid); } /** @@ -2320,12 +2142,7 @@ public class ApplicationConnection { if (null == titleOwner) { return null; } - ComponentDetail cd = idToPaintableDetail.get(getPid(titleOwner)); - if (null != cd) { - return cd.getTooltipInfo(key); - } else { - return null; - } + return paintableMap.getTooltipInfo(titleOwner, key); } private final VTooltip tooltip = new VTooltip(this); @@ -2387,6 +2204,8 @@ public class ApplicationConnection { } }; + private PaintableMap paintableMap = new PaintableMap(); + /** * Components can call this function to run all layout functions. This is * usually done, when component knows that its size has changed. @@ -2443,9 +2262,7 @@ public class ApplicationConnection { */ public void registerTooltip(Paintable paintable, Object key, TooltipInfo tooltip) { - ComponentDetail componentDetail = idToPaintableDetail - .get(getPid(paintable)); - componentDetail.putAdditionalTooltip(key, tooltip); + paintableMap.registerTooltip(paintable, key, tooltip); } /** @@ -2470,8 +2287,7 @@ public class ApplicationConnection { * for the event identified by eventIdentifier. */ public boolean hasEventListeners(Paintable paintable, String eventIdentifier) { - return idToPaintableDetail.get(getPid(paintable)).hasEventListeners( - eventIdentifier); + return paintableMap.hasEventListeners(paintable, eventIdentifier); } /** @@ -2515,4 +2331,14 @@ public class ApplicationConnection { return uri; } + PaintableMap getPaintableMap() { + return paintableMap; + } + + @Deprecated + public void unregisterPaintable(Paintable p) { + paintableMap.unregisterPaintable(p); + + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ComponentDetail.java b/src/com/vaadin/terminal/gwt/client/ComponentDetail.java index 7fc93b2a3e..c83c570068 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentDetail.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentDetail.java @@ -11,16 +11,20 @@ import com.vaadin.terminal.gwt.client.RenderInformation.Size; class ComponentDetail { - private Paintable component; + // private Paintable paintable; private TooltipInfo tooltipInfo = new TooltipInfo(); - private String pid; - public ComponentDetail(ApplicationConnection client, String pid, - Paintable component) { - this.component = component; - this.pid = pid; + // private String pid; + + public ComponentDetail() { + } + // public ComponentDetail(String pid, Paintable paintable) { + // this.paintable = paintable; + // this.pid = pid; + // } + /** * Returns a TooltipInfo assosiated with Component. If element is given, * returns an additional TooltipInfo. @@ -52,19 +56,19 @@ class ComponentDetail { private Size offsetSize; private HashMap additionalTooltips; - /** - * @return the pid - */ - String getPid() { - return pid; - } - - /** - * @return the component - */ - Paintable getComponent() { - return component; - } + // /** + // * @return the pid + // */ + // String getPid() { + // return pid; + // } + + // /** + // * @return the component + // */ + // Paintable getPaintable() { + // return paintable; + // } /** * @return the relativeSize diff --git a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index b4489df81e..9206e3c068 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -78,7 +78,7 @@ public class ComponentLocator { Element e = targetElement; while (true) { - pid = client.getPid(e); + pid = PaintableMap.get(client).getPid(e); if (pid != null) { break; } @@ -94,7 +94,7 @@ public class ComponentLocator { // If we found a Paintable then we use that as reference. We should // find the Paintable for all but very special cases (like // overlays). - w = (Widget) client.getPaintable(pid); + w = (Widget) PaintableMap.get(client).getPaintable(pid); /* * Still if the Paintable contains a widget that implements @@ -364,7 +364,7 @@ public class ComponentLocator { return null; } - String pid = client.getPid(w.getElement()); + String pid = PaintableMap.get(client).getPid(w.getElement()); if (isStaticPid(pid)) { return pid; } @@ -437,7 +437,7 @@ public class ComponentLocator { w = client.getView(); } else if (w == null) { // Must be static pid (PID_S*) - w = (Widget) client.getPaintable(part); + w = (Widget) PaintableMap.get(client).getPaintable(part); } else if (part.startsWith("domChild[")) { // The target widget has been found and the rest identifies the // element diff --git a/src/com/vaadin/terminal/gwt/client/PaintableMap.java b/src/com/vaadin/terminal/gwt/client/PaintableMap.java new file mode 100644 index 0000000000..cbdc4efa68 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/PaintableMap.java @@ -0,0 +1,356 @@ +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.gwt.client.RenderInformation.FloatSize; +import com.vaadin.terminal.gwt.client.RenderInformation.Size; + +public class PaintableMap { + + private Map idToPaintable = new HashMap(); + + @Deprecated + private final ComponentDetailMap idToComponentDetail = ComponentDetailMap + .create(); + + private Set unregistryBag = new HashSet(); + + /** + * Returns a Paintable by its paintable id + * + * @param id + * The Paintable id + */ + public Paintable getPaintable(String pid) { + return idToPaintable.get(pid); + } + + /** + * Returns a Paintable element by its root element + * + * @param element + * Root element of the paintable + */ + public Paintable getPaintable(Element element) { + return getPaintable(getPid(element)); + } + + public static PaintableMap get(ApplicationConnection applicationConnection) { + return applicationConnection.getPaintableMap(); + } + + /** + * 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(); + idToComponentDetail.clear(); + } + + @Deprecated + public Widget getWidget(Paintable paintable) { + return (Widget) paintable; + } + + @Deprecated + public Paintable getPaintable(Widget widget) { + return (Paintable) widget; + } + + public void registerPaintable(String pid, Paintable paintable) { + ComponentDetail componentDetail = GWT.create(ComponentDetail.class); + idToComponentDetail.put(pid, componentDetail); + idToPaintable.put(pid, paintable); + setPid(((Widget) paintable).getElement(), pid); + } + + private native void setPid(Element el, String pid) + /*-{ + el.tkPid = pid; + }-*/; + + /** + * Gets the paintableId for a specific paintable. + *

+ * The paintableId is used in the UIDL to identify a specific widget + * instance, effectively linking the widget with it's server side Component. + *

+ * + * @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(Paintable paintable) { + return getPid(getWidget(paintable)); + } + + @Deprecated + public String getPid(Widget widget) { + if (widget == null) { + return null; + } + 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) { + return ((Widget) getPaintable(pid)).getElement(); + } + + /** + * 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(Paintable p) { + + // add to unregistry que + + if (p == null) { + VConsole.error("WARN: Trying to unregister null paintable"); + return; + } + String id = getPid(p); + 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."); + // } + if (p instanceof HasWidgets) { + unregisterChildPaintables((HasWidgets) p); + } + } else { + unregistryBag.add(id); + if (p instanceof HasWidgets) { + unregisterChildPaintables((HasWidgets) p); + } + } + } + + void purgeUnregistryBag(boolean unregisterPaintables) { + if (unregisterPaintables) { + for (String pid : unregistryBag) { + Paintable 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; + } + // check if can be cleaned + Widget component = getWidget(paintable); + if (!component.isAttached()) { + // clean reference to paintable + idToComponentDetail.remove(pid); + idToPaintable.remove(pid); + } + /* + * 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) { + final Iterator it = container.iterator(); + while (it.hasNext()) { + final Widget w = it.next(); + if (w instanceof Paintable) { + unregisterPaintable((Paintable) w); + } else if (w instanceof HasWidgets) { + 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(Paintable paintable) { + return getComponentDetail(paintable).getOffsetSize(); + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public FloatSize getRelativeSize(Paintable paintable) { + return getComponentDetail(paintable).getRelativeSize(); + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public void setOffsetSize(Paintable paintable, Size newSize) { + getComponentDetail(paintable).setOffsetSize(newSize); + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public void setRelativeSize(Paintable paintable, FloatSize relativeSize) { + getComponentDetail(paintable).setRelativeSize(relativeSize); + + } + + private ComponentDetail getComponentDetail(Paintable paintable) { + return idToComponentDetail.get(getPid(paintable)); + } + + public int size() { + return idToPaintable.size(); + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public TooltipInfo getTooltipInfo(Paintable paintable, Object key) { + return getComponentDetail(paintable).getTooltipInfo(key); + } + + public Collection getPaintables() { + return Collections.unmodifiableCollection(idToPaintable.values()); + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public void registerTooltip(Paintable paintable, Object key, + TooltipInfo tooltip) { + getComponentDetail(paintable).putAdditionalTooltip(key, tooltip); + + } + + /** + * FIXME: Should not be here + * + * @param paintable + * @return + */ + @Deprecated + public boolean hasEventListeners(Paintable paintable, String eventIdentifier) { + return getComponentDetail(paintable).hasEventListeners(eventIdentifier); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/UIDL.java b/src/com/vaadin/terminal/gwt/client/UIDL.java index a6298af8d1..12bbe563d7 100644 --- a/src/com/vaadin/terminal/gwt/client/UIDL.java +++ b/src/com/vaadin/terminal/gwt/client/UIDL.java @@ -518,7 +518,8 @@ public final class UIDL extends JavaScriptObject { */ public Paintable getPaintableAttribute(String name, ApplicationConnection connection) { - return connection.getPaintable(getStringAttribute(name)); + return PaintableMap.get(connection).getPaintable( + getStringAttribute(name)); } /** @@ -530,7 +531,8 @@ public final class UIDL extends JavaScriptObject { */ public Paintable getPaintableVariable(String name, ApplicationConnection connection) { - return connection.getPaintable(getStringVariable(name)); + return PaintableMap.get(connection).getPaintable( + getStringVariable(name)); } /** diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java index af5ad0616f..3b3c761e84 100644 --- a/src/com/vaadin/terminal/gwt/client/Util.java +++ b/src/com/vaadin/terminal/gwt/client/Util.java @@ -747,11 +747,12 @@ public class Util { ApplicationConnection client, Container parent, Element element) { Element rootElement = ((Widget) parent).getElement(); while (element != null && element != rootElement) { - Paintable paintable = client.getPaintable(element); + Paintable paintable = PaintableMap.get(client) + .getPaintable(element); if (paintable == null) { String ownerPid = VCaption.getCaptionOwnerPid(element); if (ownerPid != null) { - paintable = client.getPaintable(ownerPid); + paintable = PaintableMap.get(client).getPaintable(ownerPid); } } @@ -796,11 +797,12 @@ public class Util { ApplicationConnection client, Widget parent, Element element) { Element rootElement = parent.getElement(); while (element != null && element != rootElement) { - Paintable paintable = client.getPaintable(element); + Paintable paintable = PaintableMap.get(client) + .getPaintable(element); if (paintable == null) { String ownerPid = VCaption.getCaptionOwnerPid(element); if (ownerPid != null) { - paintable = client.getPaintable(ownerPid); + paintable = PaintableMap.get(client).getPaintable(ownerPid); } } @@ -946,7 +948,7 @@ public class Util { private static void printPaintablesVariables(ArrayList vars, String id, ApplicationConnection c) { - Paintable paintable = c.getPaintable(id); + Paintable paintable = PaintableMap.get(c).getPaintable(id); if (paintable != null) { VConsole.log("\t" + id + " (" + paintable.getClass() + ") :"); for (String[] var : vars) { diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index 16d18f93f6..12347b76bd 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -54,7 +54,7 @@ public class VCaption extends HTML { owner = component; if (client != null && owner != null) { - setOwnerPid(getElement(), client.getPid(owner)); + setOwnerPid(getElement(), PaintableMap.get(client).getPid(owner)); } setStyleName(CLASSNAME); diff --git a/src/com/vaadin/terminal/gwt/client/VDebugConsole.java b/src/com/vaadin/terminal/gwt/client/VDebugConsole.java index e180c05aaa..259f6ea5ce 100644 --- a/src/com/vaadin/terminal/gwt/client/VDebugConsole.java +++ b/src/com/vaadin/terminal/gwt/client/VDebugConsole.java @@ -97,7 +97,7 @@ public class VDebugConsole extends VOverlay implements Console { RootPanel.get(), eventTarget); } if (paintable != null) { - String pid = a.getPid(paintable); + String pid = PaintableMap.get(a).getPid(paintable); VUIDLBrowser.highlight(paintable); label.setText("Currently focused :" + paintable.getClass() + " ID:" + pid); @@ -547,7 +547,7 @@ public class VDebugConsole extends VOverlay implements Console { private void printLayoutError(ValueMap valueMap, SimpleTree root, final ApplicationConnection ac) { final String pid = valueMap.getString("id"); - final Paintable paintable = ac.getPaintable(pid); + final Paintable paintable = PaintableMap.get(ac).getPaintable(pid); SimpleTree errorNode = new SimpleTree(); VerticalPanel errorDetails = new VerticalPanel(); diff --git a/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java b/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java index 142fbe293a..dc6fa142d4 100644 --- a/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java +++ b/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java @@ -126,8 +126,8 @@ public class VUIDLBrowser extends SimpleTree { // same // host page for (ApplicationConnection applicationConnection : runningApplications) { - Paintable paintable = applicationConnection.getPaintable(uidl - .getId()); + Paintable paintable = PaintableMap.get(applicationConnection) + .getPaintable(uidl.getId()); highlight(paintable); if (event != null && event.getNativeEvent().getShiftKey()) { applicationConnection.highlightComponent(paintable); diff --git a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java index 3deb140d30..f87f3dd904 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java +++ b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java @@ -21,6 +21,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; public abstract class ClickEventHandler implements DoubleClickHandler, ContextMenuHandler, MouseUpHandler { @@ -81,7 +82,8 @@ public abstract class ClickEventHandler implements DoubleClickHandler, protected void fireClick(NativeEvent event) { ApplicationConnection client = getApplicationConnection(); - String pid = getApplicationConnection().getPid(paintable); + String pid = PaintableMap.get(getApplicationConnection()).getPid( + paintable); MouseEventDetails mouseDetails = new MouseEventDetails(event, getRelativeToElement()); diff --git a/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java b/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java index 3a4048907f..1ad69d19cf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java +++ b/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java @@ -11,6 +11,7 @@ import com.google.gwt.user.client.Element; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; public abstract class LayoutClickEventHandler extends ClickEventHandler { @@ -24,7 +25,8 @@ public abstract class LayoutClickEventHandler extends ClickEventHandler { @Override protected void fireClick(NativeEvent event) { ApplicationConnection client = getApplicationConnection(); - String pid = getApplicationConnection().getPid(paintable); + String pid = PaintableMap.get(getApplicationConnection()).getPid( + paintable); MouseEventDetails mouseDetails = new MouseEventDetails(event, getRelativeToElement()); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java index 072754e0ce..f4a876a7ba 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java @@ -27,6 +27,7 @@ import com.google.gwt.xhr.client.XMLHttpRequest; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderInformation.Size; import com.vaadin.terminal.gwt.client.UIDL; @@ -468,7 +469,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements } private String getPid() { - return client.getPid(this); + return PaintableMap.get(client).getPid((Paintable) this); } public VDropHandler getDropHandler() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index 5ab28de913..4311d82802 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -36,6 +36,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; @@ -219,8 +220,8 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, moreItem.setHTML(itemHTML.toString()); moreItem.setCommand(emptyCommand); - collapsedRootItems = new VMenuBar(true, - (VMenuBar) client.getPaintable(uidlId)); + collapsedRootItems = new VMenuBar(true, (VMenuBar) PaintableMap + .get(client).getPaintable(uidlId)); moreItem.setSubMenu(collapsedRootItems); moreItem.addStyleName(CLASSNAME + "-more-menuitem"); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java index 84a22bc272..c719639961 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java @@ -18,6 +18,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize; import com.vaadin.terminal.gwt.client.RenderInformation.Size; import com.vaadin.terminal.gwt.client.RenderSpace; @@ -898,7 +899,7 @@ public class VOrderedLayout extends CellBasedLayout { for (int i = 0; i < renderedWidgets.size(); i++) { Widget widget = renderedWidgets.get(i); - String pid = client.getPid(widget.getElement()); + String pid = PaintableMap.get(client).getPid(widget); ChildComponentContainer container = getComponentContainer(widget); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 9f0f3c725a..3301e73202 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -62,6 +62,7 @@ import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.Focusable; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; @@ -1304,7 +1305,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, private void purgeUnregistryBag() { for (Iterator iterator = lazyUnregistryBag.iterator(); iterator .hasNext();) { - client.unregisterChildPaintables(iterator.next()); + PaintableMap.get(client).unregisterChildPaintables(iterator.next()); } lazyUnregistryBag.clear(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java index 4d97e113f3..5142dda357 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java @@ -462,7 +462,7 @@ public class VTextField extends TextBoxBase implements Paintable, Field, } focusedTextField = this; if (client.hasEventListeners(this, EventId.FOCUS)) { - client.updateVariable(client.getPid(this), EventId.FOCUS, "", true); + client.updateVariable(id, EventId.FOCUS, "", true); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java index 1278ed7fdb..e0c0cafd63 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java @@ -4,6 +4,7 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.UIDL; /** @@ -21,8 +22,10 @@ final public class VDragSourceIs extends VAcceptCriterion { for (int i = 0; i < c; i++) { String requiredPid = configuration .getStringAttribute("component" + i); - Paintable paintable = VDragAndDropManager.get() - .getCurrentDropHandler().getApplicationConnection() + VDropHandler currentDropHandler = VDragAndDropManager.get() + .getCurrentDropHandler(); + Paintable paintable = PaintableMap.get( + currentDropHandler.getApplicationConnection()) .getPaintable(requiredPid); if (paintable == component) { return true; diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java index 58dc0d3956..78974f060e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java @@ -7,6 +7,7 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.UIDL; final public class VIsOverId extends VAcceptCriterion { @@ -16,10 +17,13 @@ final public class VIsOverId extends VAcceptCriterion { try { String pid = configuration.getStringAttribute("s"); - Paintable paintable = VDragAndDropManager.get() - .getCurrentDropHandler().getPaintable(); - String pid2 = VDragAndDropManager.get().getCurrentDropHandler() - .getApplicationConnection().getPid(paintable); + VDropHandler currentDropHandler = VDragAndDropManager.get() + .getCurrentDropHandler(); + Paintable paintable = currentDropHandler.getPaintable(); + PaintableMap paintableMap = PaintableMap.get(currentDropHandler + .getApplicationConnection()); + + String pid2 = paintableMap.getPid(paintable); if (pid2.equals(pid)) { Object searchedId = drag.getDropDetails().get("itemIdOver"); String[] stringArrayAttribute = configuration diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java index ada7a3c78a..80f140a458 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java @@ -7,6 +7,7 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.PaintableMap; import com.vaadin.terminal.gwt.client.UIDL; final public class VItemIdIs extends VAcceptCriterion { @@ -16,8 +17,11 @@ final public class VItemIdIs extends VAcceptCriterion { try { String pid = configuration.getStringAttribute("s"); Paintable dragSource = drag.getTransferable().getDragSource(); - String pid2 = VDragAndDropManager.get().getCurrentDropHandler() - .getApplicationConnection().getPid(dragSource); + VDropHandler currentDropHandler = VDragAndDropManager.get() + .getCurrentDropHandler(); + String pid2 = PaintableMap.get( + currentDropHandler.getApplicationConnection()).getPid( + dragSource); if (pid2.equals(pid)) { Object searchedId = drag.getTransferable().getData("itemId"); String[] stringArrayAttribute = configuration -- 2.39.5