From 015306c0e2bcc8701a352a331e78deb0c867f924 Mon Sep 17 00:00:00 2001 From: Automerge Date: Thu, 3 May 2012 13:06:20 +0000 Subject: [PATCH] [merge from 6.7] Don't paint references to orphan components #8730 svn changeset:23668/svn branch:6.8 --- .../event/dd/acceptcriteria/SourceIs.java | 27 +++++-- .../terminal/gwt/server/JsonPaintTarget.java | 9 +++ .../tests/dd/NotPaintedAcceptSource.html | 71 +++++++++++++++++++ .../tests/dd/NotPaintedAcceptSource.java | 1 + 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html diff --git a/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java b/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java index 8562bc70ec..0d29e9a327 100644 --- a/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java +++ b/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java @@ -6,6 +6,9 @@ */ package com.vaadin.event.dd.acceptcriteria; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.vaadin.event.TransferableImpl; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.terminal.PaintException; @@ -22,27 +25,39 @@ import com.vaadin.ui.Component; @SuppressWarnings("serial") @ClientCriterion(VDragSourceIs.class) public class SourceIs extends ClientSideCriterion { + private static final Logger logger = Logger.getLogger(SourceIs.class + .getName()); - private Component[] component; + private Component[] components; public SourceIs(Component... component) { - this.component = component; + components = component; } @Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); - target.addAttribute("c", component.length); - for (int i = 0; i < component.length; i++) { - target.addAttribute("component" + i, component[i]); + int paintedComponents = 0; + for (int i = 0; i < components.length; i++) { + Component c = components[i]; + if (c.getApplication() != null) { + target.addAttribute("component" + paintedComponents++, c); + } else { + logger.log( + Level.WARNING, + "SourceIs component {0} at index {1} is not attached to the component hierachy and will thus be ignored", + new Object[] { c.getClass().getName(), + Integer.valueOf(i) }); + } } + target.addAttribute("c", paintedComponents); } public boolean accept(DragAndDropEvent dragEvent) { if (dragEvent.getTransferable() instanceof TransferableImpl) { Component sourceComponent = ((TransferableImpl) dragEvent .getTransferable()).getSourceComponent(); - for (Component c : component) { + for (Component c : components) { if (c == sourceComponent) { return true; } diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index d6c53a2da6..97c5139296 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -698,6 +698,15 @@ public class JsonPaintTarget implements PaintTarget { public String getPaintIdentifier(Paintable paintable) throws PaintException { if (!manager.hasPaintableId(paintable)) { + if (paintable instanceof Component + && ((Component) paintable).getApplication() == null) { + logger.log( + Level.WARNING, + "Painting reference to orphan " + + paintable.getClass().getName() + + ", the component will not be accessible on the client side."); + return "Orphan"; + } if (identifiersCreatedDueRefPaint == null) { identifiersCreatedDueRefPaint = new HashSet(); } diff --git a/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html b/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html new file mode 100644 index 0000000000..fd45e7284d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html @@ -0,0 +1,71 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.dd.NotPaintedAcceptSource?restartApplication
dragvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]50,9
dropvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]124,20
assertTextvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]Source 1 value 0
clickvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]Source 2
dragvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]19,8
dropvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]139,18
contextmenuvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[3]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[3]/domChild[0]/domChild[0]Source 2 value 0
+ + diff --git a/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.java b/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.java index d6d49e018c..74774f09ab 100644 --- a/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.java +++ b/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.java @@ -61,6 +61,7 @@ public class NotPaintedAcceptSource extends TestBase { } else { horizontalLayout.replaceComponent(source2, source1); } + target.requestRepaint(); } })); -- 2.39.5