*/
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;
@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;
}
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>();
}
--- /dev/null
+<?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>
} else {
horizontalLayout.replaceComponent(source2, source1);
}
+ target.requestRepaint();
}
}));