]> source.dussan.org Git - vaadin-framework.git/commitdiff
[merge from 6.7] Don't paint references to orphan components #8730
authorAutomerge <automerge@vaadin.com>
Thu, 3 May 2012 13:06:20 +0000 (13:06 +0000)
committerAutomerge <automerge@vaadin.com>
Thu, 3 May 2012 13:06:20 +0000 (13:06 +0000)
svn changeset:23668/svn branch:6.8

src/com/vaadin/event/dd/acceptcriteria/SourceIs.java
src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java
tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.java

index 8562bc70ec757f62309c35e3be2545ff59c3f239..0d29e9a327d249d91f800d0351c3b3cd8504d252 100644 (file)
@@ -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;
                 }
index d6c53a2da669edc6ca035c4e71190c4423aff6ca..97c513929613469dd85cc2a00b8052e021ce7ff6 100644 (file)
@@ -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<Paintable>();
             }
diff --git a/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html b/tests/testbench/com/vaadin/tests/dd/NotPaintedAcceptSource.html
new file mode 100644 (file)
index 0000000..fd45e72
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.dd.NotPaintedAcceptSource?restartApplication</td>
+       <td></td>
+</tr>
+<!--Drag value 0 to target-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=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]</td>
+       <td>50,9</td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=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]</td>
+       <td>124,20</td>
+</tr>
+<!--Assert drag was successful-->
+<tr>
+       <td>assertText</td>
+       <td>vaadin=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]</td>
+       <td>Source 1 value 0</td>
+</tr>
+<!--Swap source and verify it was properly painted-->
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestsddNotPaintedAcceptSource::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>Source 2</td>
+</tr>
+<!--Drag value 0 from source 2 and verify-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=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]</td>
+       <td>19,8</td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=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]</td>
+       <td>139,18</td>
+</tr>
+<tr>
+       <td>contextmenu</td>
+       <td>vaadin=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]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=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]</td>
+       <td>Source 2 value 0</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
index d6d49e018c81c1c96618f68c03a1460028b84ffb..74774f09abfed0f6af68b266faafdbf0c3bd9f54 100644 (file)
@@ -61,6 +61,7 @@ public class NotPaintedAcceptSource extends TestBase {
                 } else {
                     horizontalLayout.replaceComponent(source2, source1);
                 }
+                target.requestRepaint();
             }
         }));