From f227f0c1068f17e5491bd399d9f5bde16a0c8272 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sat, 5 Apr 2014 15:14:59 +0300 Subject: Drag image for text-area should contain text of text-area (#13557). Change-Id: Ief653c3f15d18fdd076f0fb80f8a91ae429a54d3 --- client/src/com/vaadin/client/ui/VTextArea.java | 15 +++++- .../com/vaadin/client/ui/dd/VDragCloneAware.java | 40 ++++++++++++++ client/src/com/vaadin/client/ui/dd/VDragEvent.java | 31 +++++++++++ .../draganddropwrapper/DragAndDropTextArea.java | 56 ++++++++++++++++++++ .../DragAndDropTextAreaTest.java | 61 ++++++++++++++++++++++ 5 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 client/src/com/vaadin/client/ui/dd/VDragCloneAware.java create mode 100644 uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java create mode 100644 uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 2a697969df..627d14a058 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -17,6 +17,7 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Overflow; import com.google.gwt.dom.client.Style.WhiteSpace; import com.google.gwt.dom.client.TextAreaElement; @@ -30,6 +31,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; +import com.vaadin.client.ui.dd.VDragCloneAware; /** * This class represents a multiline textfield (textarea). @@ -40,7 +42,7 @@ import com.vaadin.client.Util; * @author Vaadin Ltd. * */ -public class VTextArea extends VTextField { +public class VTextArea extends VTextField implements VDragCloneAware { public static final String CLASSNAME = "v-textarea"; private boolean wordwrap = true; private MaxLengthHandler maxLengthHandler = new MaxLengthHandler(); @@ -294,4 +296,15 @@ public class VTextArea extends VTextField { // class instead of directly each other. } + @Override + public void initDragImageCopy(Element element) { + // Fix for #13557 - drag image doesn't show original text area text. + // It happens because "value" property is not copied into the cloned + // element + String value = getElement().getPropertyString("value"); + if (value != null) { + element.setPropertyString("value", value); + } + } + } diff --git a/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java b/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java new file mode 100644 index 0000000000..546ca88a9f --- /dev/null +++ b/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.client.ui.dd; + +import com.google.gwt.dom.client.Element; + +/** + * Widget could implement this interface if drag image requires additional + * initialization/configuration. Method {@link #initDragImageCopy(Element)} + * allows to change/correct drag image element when element is dragged via DnD. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public interface VDragCloneAware { + + /** + * This method is called for cloned element which corresponds + * to the widget element. One could modify/correct this element + * for drag image. + * + * @since 7.1 + * @param element + * cloned element of drag image + */ + void initDragImageCopy(Element element); +} diff --git a/client/src/com/vaadin/client/ui/dd/VDragEvent.java b/client/src/com/vaadin/client/ui/dd/VDragEvent.java index a4667e57f3..0f0e1ecdad 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragEvent.java +++ b/client/src/com/vaadin/client/ui/dd/VDragEvent.java @@ -20,11 +20,14 @@ import java.util.Map; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.TableElement; import com.google.gwt.dom.client.TableSectionElement; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.EventListener; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; @@ -184,6 +187,7 @@ public class VDragEvent { cloneNode = table.cast(); } } + syncContent(element, cloneNode); if (alignImageToEvent) { int absoluteTop = element.getAbsoluteTop(); int absoluteLeft = element.getAbsoluteLeft(); @@ -198,4 +202,31 @@ public class VDragEvent { } + /** + * Do additional content sync between original element and its + * copy if needed. + * + * @since 7.1 + * @param original + * original element + * @param copy + * copy of original element + */ + protected void syncContent(Element original, Element copy) { + for (int i = 0; i < original.getChildCount(); i++) { + Node child = original.getChild(i); + if (child instanceof Element) { + syncContent((Element) child, (Element) copy.getChild(i)); + } + } + doSyncContent(original, copy); + } + + private void doSyncContent(Element original, Element copy) { + EventListener eventListener = Event.getEventListener(original); + if (eventListener instanceof VDragCloneAware) { + ((VDragCloneAware) eventListener).initDragImageCopy(copy); + } + } + } diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java new file mode 100644 index 0000000000..410eb21170 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.draganddropwrapper; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DragAndDropWrapper; +import com.vaadin.ui.DragAndDropWrapper.DragStartMode; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.VerticalLayout; + +/** + * Test UI for text area: drag image should contain text-area text. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public class DragAndDropTextArea extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout dndLayout = new VerticalLayout(); + + TextArea area = new TextArea(); + area.setValue("text"); + + dndLayout.addComponent(area); + DragAndDropWrapper wrapper = new DragAndDropWrapper(dndLayout); + wrapper.setDragStartMode(DragStartMode.WRAPPER); + addComponent(wrapper); + } + + @Override + protected String getTestDescription() { + return "Drag image for textarea should contain text-area text"; + } + + @Override + protected Integer getTicketNumber() { + return 13557; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java new file mode 100644 index 0000000000..2abf3599ac --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.draganddropwrapper; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for drag image of text area which should contain text-area text. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public class DragAndDropTextAreaTest extends MultiBrowserTest { + + @Test + public void testTextAreaDndImage() { + openTestURL(); + + WebElement wrapper = driver.findElement(By + .className("v-verticallayout")); + Actions actions = new Actions(driver); + actions.clickAndHold(wrapper); + actions.moveByOffset(50, 50); + actions.perform(); + + WebElement dragElement = driver.findElement(By + .className("v-drag-element")); + List children = dragElement.findElements(By.xpath(".//*")); + boolean found = false; + for (WebElement child : children) { + if ("text".equals(child.getAttribute("value"))) { + found = true; + } + } + + Assert.assertTrue( + "Text value is not found in the DnD image of text area", found); + } + +} -- cgit v1.2.3 From 7e5d44d19bd02ecc7b900ba4926380d2fa7e7668 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 7 Apr 2014 17:32:29 +0300 Subject: Introduce a drag threshold for Drag and Drop (#13381) Based on partial fix by Fabian Lange. Change-Id: I1a18c6ea105d87496b196b93e701aaccb987b3e7 --- .../vaadin/client/ui/dd/VDragAndDropManager.java | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java index b911c28a07..47fd3c88a2 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -31,7 +31,6 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; -import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; @@ -345,10 +344,7 @@ public class VDragAndDropManager { .addNativePreviewHandler(defaultDragAndDropEventHandler); if (dragElement != null && dragElement.getParentElement() == null) { - // deferred attaching drag image is on going, we can - // hurry with it now - lazyAttachDragElement.cancel(); - lazyAttachDragElement.run(); + attachDragElement(); } } // just capture something to prevent text selection in IE @@ -370,6 +366,13 @@ public class VDragAndDropManager { deferredStartRegistration = Event .addNativePreviewHandler(new NativePreviewHandler() { + private int startX = Util + .getTouchOrMouseClientX(currentDrag + .getCurrentGwtEvent()); + private int startY = Util + .getTouchOrMouseClientY(currentDrag + .getCurrentGwtEvent()); + @Override public void onPreviewNativeEvent( NativePreviewEvent event) { @@ -422,13 +425,23 @@ public class VDragAndDropManager { } case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: - if (deferredStartRegistration != null) { - deferredStartRegistration.removeHandler(); - deferredStartRegistration = null; + int currentX = Util + .getTouchOrMouseClientX(event + .getNativeEvent()); + int currentY = Util + .getTouchOrMouseClientY(event + .getNativeEvent()); + if (Math.abs(startX - currentX) > 3 + || Math.abs(startY - currentY) > 3) { + if (deferredStartRegistration != null) { + deferredStartRegistration + .removeHandler(); + deferredStartRegistration = null; + } + currentDrag.setCurrentGwtEvent(event + .getNativeEvent()); + startDrag.execute(); } - currentDrag.setCurrentGwtEvent(event - .getNativeEvent()); - startDrag.execute(); break; default: // on any other events, clean up the @@ -718,16 +731,7 @@ public class VDragAndDropManager { updateDragImagePosition(); if (isStarted) { - lazyAttachDragElement.run(); - } else { - /* - * To make our default dnd handler as compatible as possible, we - * need to defer the appearance of dragElement. Otherwise events - * that are derived from sequences of other events might not - * fire as domchanged will fire between them or mouse up might - * happen on dragElement. - */ - lazyAttachDragElement.schedule(300); + attachDragElement(); } } } @@ -736,24 +740,20 @@ public class VDragAndDropManager { return dragElement; } - private final Timer lazyAttachDragElement = new Timer() { - - @Override - public void run() { - if (dragElement != null && dragElement.getParentElement() == null) { - ApplicationConnection connection = getCurrentDragApplicationConnection(); - Element dragImageParent; - if (connection == null) { - VConsole.error("Could not determine ApplicationConnection for current drag operation. The drag image will likely look broken"); - dragImageParent = RootPanel.getBodyElement(); - } else { - dragImageParent = VOverlay.getOverlayContainer(connection); - } - dragImageParent.appendChild(dragElement); + public void attachDragElement() { + if (dragElement != null && dragElement.getParentElement() == null) { + ApplicationConnection connection = getCurrentDragApplicationConnection(); + Element dragImageParent; + if (connection == null) { + VConsole.error("Could not determine ApplicationConnection for current drag operation. The drag image will likely look broken"); + dragImageParent = RootPanel.getBodyElement(); + } else { + dragImageParent = VOverlay.getOverlayContainer(connection); } - + dragImageParent.appendChild(dragElement); } - }; + + } private Command deferredCommand; -- cgit v1.2.3 From 35e2a34c9c4dfcf9117db31f6403401129c9befc Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 14 Apr 2014 10:19:17 +0300 Subject: Fix FieldGroup and TransactionalPropertyWrapper memory leaks (#13438) Change-Id: Ifafb6d87b4280f8bd9e631235fff62f42de4b4c8 --- .../src/com/vaadin/data/fieldgroup/FieldGroup.java | 8 ++++++- .../data/util/TransactionalPropertyWrapper.java | 26 +++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index 23f2da53ce..c5f9907610 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -316,12 +316,18 @@ public class FieldGroup implements Serializable { "The given field is not part of this FieldBinder"); } + TransactionalPropertyWrapper wrapper = null; Property fieldDataSource = field.getPropertyDataSource(); if (fieldDataSource instanceof TransactionalPropertyWrapper) { - fieldDataSource = ((TransactionalPropertyWrapper) fieldDataSource) + wrapper = (TransactionalPropertyWrapper) fieldDataSource; + fieldDataSource = ((TransactionalPropertyWrapper) fieldDataSource) .getWrappedProperty(); + } if (fieldDataSource == getItemProperty(propertyId)) { + if (null != wrapper) { + wrapper.detachFromProperty(); + } field.setPropertyDataSource(null); } fieldToPropertyId.remove(field); diff --git a/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java b/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java index 6b0119c503..3bac5bdfb8 100644 --- a/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java +++ b/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java @@ -48,18 +48,32 @@ public class TransactionalPropertyWrapper extends AbstractProperty private boolean inTransaction = false; private boolean valueChangePending; private T valueBeforeTransaction; + private final ValueChangeListener listener = new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + fireValueChange(); + } + }; public TransactionalPropertyWrapper(Property wrappedProperty) { this.wrappedProperty = wrappedProperty; if (wrappedProperty instanceof ValueChangeNotifier) { ((ValueChangeNotifier) wrappedProperty) - .addListener(new ValueChangeListener() { + .addValueChangeListener(listener); + } + } - @Override - public void valueChange(ValueChangeEvent event) { - fireValueChange(); - } - }); + /** + * Removes the ValueChangeListener from wrapped Property that was added by + * TransactionalPropertyWrapper. + * + * @since 7.1.14 + */ + public void detachFromProperty() { + if (wrappedProperty instanceof ValueChangeNotifier) { + ((ValueChangeNotifier) wrappedProperty) + .removeValueChangeListener(listener); } } -- cgit v1.2.3 From 168de1fefa0f09b07d438968575033e6d234cfb2 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 14 Apr 2014 11:14:32 +0000 Subject: Revert "Drag image for text-area should contain text of text-area (#13557)" This reverts commit f227f0c1068f17e5491bd399d9f5bde16a0c8272. Synchronising content after IE wraps the given element into a table with a body causes a NullPointerException on client side. This patch also contains new API and should be targeted to master branch. Change-Id: Ia19acd9fa31c7b67507bf797a2bab7c28ea37b4b --- client/src/com/vaadin/client/ui/VTextArea.java | 15 +----- .../com/vaadin/client/ui/dd/VDragCloneAware.java | 40 -------------- client/src/com/vaadin/client/ui/dd/VDragEvent.java | 31 ----------- .../draganddropwrapper/DragAndDropTextArea.java | 56 -------------------- .../DragAndDropTextAreaTest.java | 61 ---------------------- 5 files changed, 1 insertion(+), 202 deletions(-) delete mode 100644 client/src/com/vaadin/client/ui/dd/VDragCloneAware.java delete mode 100644 uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java delete mode 100644 uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 627d14a058..2a697969df 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Overflow; import com.google.gwt.dom.client.Style.WhiteSpace; import com.google.gwt.dom.client.TextAreaElement; @@ -31,7 +30,6 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; -import com.vaadin.client.ui.dd.VDragCloneAware; /** * This class represents a multiline textfield (textarea). @@ -42,7 +40,7 @@ import com.vaadin.client.ui.dd.VDragCloneAware; * @author Vaadin Ltd. * */ -public class VTextArea extends VTextField implements VDragCloneAware { +public class VTextArea extends VTextField { public static final String CLASSNAME = "v-textarea"; private boolean wordwrap = true; private MaxLengthHandler maxLengthHandler = new MaxLengthHandler(); @@ -296,15 +294,4 @@ public class VTextArea extends VTextField implements VDragCloneAware { // class instead of directly each other. } - @Override - public void initDragImageCopy(Element element) { - // Fix for #13557 - drag image doesn't show original text area text. - // It happens because "value" property is not copied into the cloned - // element - String value = getElement().getPropertyString("value"); - if (value != null) { - element.setPropertyString("value", value); - } - } - } diff --git a/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java b/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java deleted file mode 100644 index 546ca88a9f..0000000000 --- a/client/src/com/vaadin/client/ui/dd/VDragCloneAware.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.client.ui.dd; - -import com.google.gwt.dom.client.Element; - -/** - * Widget could implement this interface if drag image requires additional - * initialization/configuration. Method {@link #initDragImageCopy(Element)} - * allows to change/correct drag image element when element is dragged via DnD. - * - * @since 7.1 - * @author Vaadin Ltd - */ -public interface VDragCloneAware { - - /** - * This method is called for cloned element which corresponds - * to the widget element. One could modify/correct this element - * for drag image. - * - * @since 7.1 - * @param element - * cloned element of drag image - */ - void initDragImageCopy(Element element); -} diff --git a/client/src/com/vaadin/client/ui/dd/VDragEvent.java b/client/src/com/vaadin/client/ui/dd/VDragEvent.java index 0f0e1ecdad..a4667e57f3 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragEvent.java +++ b/client/src/com/vaadin/client/ui/dd/VDragEvent.java @@ -20,14 +20,11 @@ import java.util.Map; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.TableElement; import com.google.gwt.dom.client.TableSectionElement; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; @@ -187,7 +184,6 @@ public class VDragEvent { cloneNode = table.cast(); } } - syncContent(element, cloneNode); if (alignImageToEvent) { int absoluteTop = element.getAbsoluteTop(); int absoluteLeft = element.getAbsoluteLeft(); @@ -202,31 +198,4 @@ public class VDragEvent { } - /** - * Do additional content sync between original element and its - * copy if needed. - * - * @since 7.1 - * @param original - * original element - * @param copy - * copy of original element - */ - protected void syncContent(Element original, Element copy) { - for (int i = 0; i < original.getChildCount(); i++) { - Node child = original.getChild(i); - if (child instanceof Element) { - syncContent((Element) child, (Element) copy.getChild(i)); - } - } - doSyncContent(original, copy); - } - - private void doSyncContent(Element original, Element copy) { - EventListener eventListener = Event.getEventListener(original); - if (eventListener instanceof VDragCloneAware) { - ((VDragCloneAware) eventListener).initDragImageCopy(copy); - } - } - } diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java deleted file mode 100644 index 410eb21170..0000000000 --- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextArea.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.draganddropwrapper; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.DragAndDropWrapper; -import com.vaadin.ui.DragAndDropWrapper.DragStartMode; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.VerticalLayout; - -/** - * Test UI for text area: drag image should contain text-area text. - * - * @since 7.1 - * @author Vaadin Ltd - */ -public class DragAndDropTextArea extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - VerticalLayout dndLayout = new VerticalLayout(); - - TextArea area = new TextArea(); - area.setValue("text"); - - dndLayout.addComponent(area); - DragAndDropWrapper wrapper = new DragAndDropWrapper(dndLayout); - wrapper.setDragStartMode(DragStartMode.WRAPPER); - addComponent(wrapper); - } - - @Override - protected String getTestDescription() { - return "Drag image for textarea should contain text-area text"; - } - - @Override - protected Integer getTicketNumber() { - return 13557; - } - -} diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java deleted file mode 100644 index 2abf3599ac..0000000000 --- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropTextAreaTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.draganddropwrapper; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.By; -import com.vaadin.tests.tb3.MultiBrowserTest; - -/** - * Test for drag image of text area which should contain text-area text. - * - * @since 7.1 - * @author Vaadin Ltd - */ -public class DragAndDropTextAreaTest extends MultiBrowserTest { - - @Test - public void testTextAreaDndImage() { - openTestURL(); - - WebElement wrapper = driver.findElement(By - .className("v-verticallayout")); - Actions actions = new Actions(driver); - actions.clickAndHold(wrapper); - actions.moveByOffset(50, 50); - actions.perform(); - - WebElement dragElement = driver.findElement(By - .className("v-drag-element")); - List children = dragElement.findElements(By.xpath(".//*")); - boolean found = false; - for (WebElement child : children) { - if ("text".equals(child.getAttribute("value"))) { - found = true; - } - } - - Assert.assertTrue( - "Text value is not found in the DnD image of text area", found); - } - -} -- cgit v1.2.3 From e033fcda3537290a2db1b33ab5e7d5264639f1bb Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 8 Apr 2014 16:56:50 +0300 Subject: Always initialize WebBrowser for new sessions (#13571) Change-Id: I3918498d63032f6b507b52634df5b41470363e15 --- server/src/com/vaadin/server/BootstrapHandler.java | 4 -- server/src/com/vaadin/server/VaadinService.java | 3 + .../vaadin/server/communication/UIInitHandler.java | 2 +- .../UnsupportedBrowserHandlerUserAgents.java | 76 ++++++++++++++++++++++ .../vaadin/tests/tb3/PrivateTB3Configuration.java | 31 +++++++-- 5 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 0a4949ffa7..60b4459d2a 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -155,10 +155,6 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { } try { - // Update WebBrowser here only to make WebBrowser information - // available in init for LegacyApplications - session.getBrowser().updateRequestDetails(request); - List uiProviders = session.getUIProviders(); UIClassSelectionEvent classSelectionEvent = new UIClassSelectionEvent( diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index eda794438f..b26097a247 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -735,6 +735,9 @@ public abstract class VaadinService implements Serializable { session.storeInSession(this, request.getWrappedSession()); + // Initial WebBrowser data comes from the request + session.getBrowser().updateRequestDetails(request); + // Initial locale comes from the request Locale locale = request.getLocale(); session.setLocale(locale); diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java index d4b0bc709f..9f299d9427 100644 --- a/server/src/com/vaadin/server/communication/UIInitHandler.java +++ b/server/src/com/vaadin/server/communication/UIInitHandler.java @@ -67,7 +67,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler { try { assert UI.getCurrent() == null; - // Set browser information from the request + // Update browser information from the request session.getBrowser().updateRequestDetails(request); UI uI = getBrowserDetailsUI(request, session); diff --git a/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java b/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java new file mode 100644 index 0000000000..9147d0fe50 --- /dev/null +++ b/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.requesthandlers; + +import java.net.HttpURLConnection; +import java.net.URL; + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.PrivateTB3Configuration; + +public class UnsupportedBrowserHandlerUserAgents { + /* + * This test doesn't use testbench, but it's still in the uitest source + * folder since it should be run with the testing server deployed. + */ + + @Test + public void ie7NotSupported() { + String response = requestWithUserAgent("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727)"); + Assert.assertTrue("IE7 should not be supported", + response.contains("your browser is not supported")); + } + + @Test + public void ie9Supported() { + String response = requestWithUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)"); + Assert.assertFalse("IE9 should be supported", + response.contains("your browser is not supported")); + } + + @Test + public void unknownSupported() { + String response = requestWithUserAgent("Very strange user agent, like wat"); + Assert.assertFalse("Unkonwn user agent should be supported", + response.contains("your browser is not supported")); + } + + private String requestWithUserAgent(String userAgent) { + try { + String url = "http://" + + PrivateTB3Configuration.getConfiguredDeploymentHostname() + + ":" + + PrivateTB3Configuration.getConfiguredDeploymentPort() + + "/run/" + + com.vaadin.tests.components.ui.UIInitTest.class.getName() + + "/"; + + HttpURLConnection connection = (HttpURLConnection) new URL(url) + .openConnection(); + connection.setRequestProperty("User-Agent", userAgent); + + String response = IOUtils.toString(connection.getInputStream()); + connection.disconnect(); + + return response; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java index 400a2fe429..97150f96ab 100644 --- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -25,6 +25,7 @@ import java.net.SocketException; import java.util.Enumeration; import java.util.Properties; +import org.apache.commons.io.IOUtils; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxBinary; @@ -44,9 +45,8 @@ import com.vaadin.testbench.TestBench; public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname"; private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port"; - private final Properties properties = new Properties(); - - public PrivateTB3Configuration() { + private static final Properties properties = new Properties(); + static { File file = new File("work", "eclipse-run-selected-test.properties"); if (file.exists()) { try { @@ -57,7 +57,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { } } - private String getProperty(String name) { + private static String getProperty(String name) { String property = properties.getProperty(name); if (property == null) { property = System.getProperty(name); @@ -86,6 +86,15 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { if (getClass().getAnnotation(RunLocally.class) != null) { return "localhost"; } + return getConfiguredDeploymentHostname(); + } + + /** + * Gets the hostname that tests are configured to use. + * + * @return the host name configuration value + */ + public static String getConfiguredDeploymentHostname() { String hostName = getProperty(HOSTNAME_PROPERTY); if (hostName == null || "".equals(hostName)) { @@ -97,6 +106,15 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { @Override protected int getDeploymentPort() { + return getConfiguredDeploymentPort(); + } + + /** + * Gets the port that tests are configured to use. + * + * @return the port configuration value + */ + public static int getConfiguredDeploymentPort() { String portString = getProperty(PORT_PROPERTY); int port = 8888; @@ -115,7 +133,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { * @throws RuntimeException * if there was an error or no IP was found */ - private String findAutoHostname() { + private static String findAutoHostname() { try { Enumeration interfaces = NetworkInterface .getNetworkInterfaces(); @@ -125,7 +143,8 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { || nwInterface.isVirtual()) { continue; } - Enumeration addresses = nwInterface.getInetAddresses(); + Enumeration addresses = nwInterface + .getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (address.isLoopbackAddress()) { -- cgit v1.2.3 From f0aaf89c18e3953500c6ae93ae2b5437bfb3dcdd Mon Sep 17 00:00:00 2001 From: Tapio Aali Date: Wed, 26 Mar 2014 11:09:23 +0200 Subject: Fixed resetting of ComboBox if focused and new items allowed (#13413). Change-Id: Ibea81666101ff119e1b3e48726224f369e59b00f --- .../client/ui/combobox/ComboBoxConnector.java | 4 +- .../ComboBoxSetNullWhenNewItemsAllowed.java | 61 ++++++++++++++++++++++ .../ComboBoxSetNullWhenNewItemsAllowedTest.java | 55 +++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowed.java create mode 100644 uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowedTest.java diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index 8dec26cf90..c9c1d9c50c 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -267,7 +267,9 @@ public class ComboBoxConnector extends AbstractFieldConnector implements // we have focus in field, prompting can't be set on, instead // just clear the input if the value has changed from something // else to null - if (getWidget().selectedOptionKey != null) { + if (getWidget().selectedOptionKey != null + || (getWidget().allowNewItem && !getWidget().tb + .getValue().isEmpty())) { getWidget().tb.setValue(""); } } diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowed.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowed.java new file mode 100644 index 0000000000..c0ac5cc392 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowed.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.combobox; + +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Label; + +public class ComboBoxSetNullWhenNewItemsAllowed extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final ComboBox comboBox = new ComboBox("My ComboBox"); + comboBox.setImmediate(true); + comboBox.setNullSelectionAllowed(false); + comboBox.setNewItemsAllowed(true); + for (int i = 0; i < 10; i++) { + comboBox.addItem("Item " + i); + } + + final Label value = new Label("Selected: "); + + comboBox.addValueChangeListener(new Property.ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + if (comboBox.getValue() != null) { + comboBox.setValue(null); + value.setValue("Selected: " + (String) comboBox.getValue()); + } + } + }); + addComponent(comboBox); + addComponent(value); + } + + @Override + protected String getTestDescription() { + return "ComboBox should clear its value when setting to null with new items."; + } + + @Override + protected Integer getTicketNumber() { + return 13413; + } +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowedTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowedTest.java new file mode 100644 index 0000000000..1794b9865f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSetNullWhenNewItemsAllowedTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.combobox; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.commands.TestBenchElementCommands; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * ComboBox should clear its value when setting to null with new items. + */ +public class ComboBoxSetNullWhenNewItemsAllowedTest extends MultiBrowserTest { + + @Test + public void testNewValueIsClearedAppropriately() + throws InterruptedException { + setDebug(true); + openTestURL(); + Thread.sleep(1000); + + WebElement element = findElement(); + ((TestBenchElementCommands) element).click(8, 7); + element.clear(); + element.sendKeys("New value"); + assertEquals("New value", element.getAttribute("value")); + element.sendKeys(Keys.RETURN); + assertEquals("", element.getAttribute("value")); + } + + private WebElement findElement() { + return getDriver() + .findElement( + By.vaadin("runcomvaadintestscomponentscomboboxComboBoxSetNullWhenNewItemsAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFilterSelect[0]#textbox")); + } + +} -- cgit v1.2.3 From 6e91bdf4224d5e95cf1746775855c13c25e9b82c Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 14 Apr 2014 15:56:05 +0300 Subject: Add test for TransactionalPropertyWrapper memory leaks Change-Id: I69d0d759f95100f1dd9e2dbba57ec2c246e3aca9 --- .../data/util/TransactionalPropertyWrapper.java | 2 +- .../util/TransactionalPropertyWrapperTest.java | 116 +++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 server/tests/src/com/vaadin/data/util/TransactionalPropertyWrapperTest.java diff --git a/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java b/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java index 3bac5bdfb8..3c52ab9afc 100644 --- a/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java +++ b/server/src/com/vaadin/data/util/TransactionalPropertyWrapper.java @@ -68,7 +68,7 @@ public class TransactionalPropertyWrapper extends AbstractProperty * Removes the ValueChangeListener from wrapped Property that was added by * TransactionalPropertyWrapper. * - * @since 7.1.14 + * @since 7.1.15 */ public void detachFromProperty() { if (wrappedProperty instanceof ValueChangeNotifier) { diff --git a/server/tests/src/com/vaadin/data/util/TransactionalPropertyWrapperTest.java b/server/tests/src/com/vaadin/data/util/TransactionalPropertyWrapperTest.java new file mode 100644 index 0000000000..8e83db5aef --- /dev/null +++ b/server/tests/src/com/vaadin/data/util/TransactionalPropertyWrapperTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.util; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.ui.TextField; + +/** + * Test verifying that TransactionalPropertyWrapper removes it's listener from + * wrapped Property + * + * @since 7.1.15 + * @author Vaadin Ltd + */ +public class TransactionalPropertyWrapperTest { + + @SuppressWarnings("serial") + public class TestingProperty extends + ObjectProperty { + + private List listeners = new ArrayList(); + + public TestingProperty(Object value) { + super(value); + } + + @Override + public void addValueChangeListener(ValueChangeListener listener) { + super.addValueChangeListener(listener); + listeners.add(listener); + } + + @Override + public void removeValueChangeListener(ValueChangeListener listener) { + super.removeValueChangeListener(listener); + if (listeners.contains(listener)) { + listeners.remove(listener); + } + } + + public boolean hasListeners() { + return !listeners.isEmpty(); + } + } + + private final TextField nameField = new TextField("Name"); + private final TextField ageField = new TextField("Age"); + private final TextField unboundField = new TextField("No FieldGroup"); + private final TestingProperty unboundProp = new TestingProperty( + "Hello World"); + private final PropertysetItem item = new PropertysetItem(); + + @Test + public void fieldGroupBindAndUnbind() { + item.addItemProperty("name", new TestingProperty( + "Just some text")); + item.addItemProperty("age", new TestingProperty("42")); + + final FieldGroup binder = new FieldGroup(item); + binder.setBuffered(false); + + for (int i = 0; i < 2; ++i) { + binder.bind(nameField, "name"); + binder.bind(ageField, "age"); + unboundField.setPropertyDataSource(unboundProp); + + assertTrue("No listeners in Properties", fieldsHaveListeners(true)); + + binder.unbind(nameField); + binder.unbind(ageField); + unboundField.setPropertyDataSource(null); + + assertTrue("Listeners in Properties after unbinding", + fieldsHaveListeners(false)); + } + } + + /** + * Check that all listeners have same hasListeners() response + * + * @param expected + * expected response + * @return true if all are the same as expected. false if not + */ + private boolean fieldsHaveListeners(boolean expected) { + for (Object id : item.getItemPropertyIds()) { + TestingProperty itemProperty = (TestingProperty) item + .getItemProperty(id); + + if (itemProperty.hasListeners() != expected) { + return false; + } + } + return unboundProp.hasListeners() == expected; + } +} -- cgit v1.2.3 From 0d4080ba5e5931fa928675ba6c95540e34b2f281 Mon Sep 17 00:00:00 2001 From: Maciej Przepióra Date: Fri, 11 Apr 2014 23:53:43 +0300 Subject: ContainerEventProvider returns style names from container. Fixes #10718 ContainerEventProvider doesn't actually return style names from container in certain situations (copy-pasted code). This patch fixes the problem. Change-Id: I512ea260f34a6db0572b614db393699da152fa8d (cherry picked from commit 4709b75bb47d28630dacbb240bb43de16d972371) --- .../calendar/ContainerEventProvider.java | 4 +-- .../component/calendar/ContainerDataSource.java | 32 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java index 37ea255d27..b025de6f9a 100644 --- a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java +++ b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java @@ -224,8 +224,8 @@ public class ContainerEventProvider implements CalendarEditableEventProvider, } if (styleNameProperty != null && item.getItemPropertyIds().contains(styleNameProperty)) { - basicEvent.setDescription(String.valueOf(item.getItemProperty( - descriptionProperty).getValue())); + basicEvent.setStyleName(String.valueOf(item.getItemProperty( + styleNameProperty).getValue())); } event = basicEvent; } diff --git a/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java b/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java index 2bc95e371c..d5b0d5d9c8 100644 --- a/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java +++ b/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java @@ -25,6 +25,7 @@ import org.junit.Test; import com.vaadin.data.Container.Indexed; import com.vaadin.data.Container.Sortable; import com.vaadin.data.Item; +import com.vaadin.data.Property; import com.vaadin.data.util.BeanItemContainer; import com.vaadin.data.util.IndexedContainer; import com.vaadin.ui.Calendar; @@ -327,6 +328,37 @@ public class ContainerDataSource extends TestCase { assertEquals(0, calendar.getEvents(start, end).size()); } + @Test + public void testStyleNamePropertyRetrieved() { + IndexedContainer ic = (IndexedContainer) createTestIndexedContainer(); + ic.addContainerProperty("testStyleName", String.class, ""); + for (int i = 0; i < 10; i++) { + Item item = ic.getItem(ic.getIdByIndex(i)); + @SuppressWarnings("unchecked") + Property itemProperty = item + .getItemProperty("testStyleName"); + itemProperty.setValue("testStyle"); + } + + ContainerEventProvider provider = new ContainerEventProvider(ic); + provider.setCaptionProperty("testCaption"); + provider.setDescriptionProperty("testDescription"); + provider.setStartDateProperty("testStartDate"); + provider.setEndDateProperty("testEndDate"); + provider.setStyleNameProperty("testStyleName"); + + calendar.setEventProvider(provider); + java.util.Calendar cal = java.util.Calendar.getInstance(); + Date now = cal.getTime(); + cal.add(java.util.Calendar.DAY_OF_MONTH, 20); + Date then = cal.getTime(); + List events = calendar.getEventProvider().getEvents(now, + then); + for (CalendarEvent ce : events) { + assertEquals("testStyle", ce.getStyleName()); + } + } + private static Indexed createTestBeanItemContainer() { BeanItemContainer eventContainer = new BeanItemContainer( CalendarEvent.class); -- cgit v1.2.3