summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-10-23 19:35:39 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-10 12:57:38 +0200
commitd9cbbe89d35d7b8110376b7bf9adce0a4e1e39c6 (patch)
tree820b3d371e15ef456e963c8de60d7583320b2c2f
parent672fee934c804fa232e8d573142a37746cceff77 (diff)
downloadvaadin-framework-d9cbbe89d35d7b8110376b7bf9adce0a4e1e39c6.tar.gz
vaadin-framework-d9cbbe89d35d7b8110376b7bf9adce0a4e1e39c6.zip
Fire attach/detach events when Window is added/removed from UI (#14908).
Change-Id: Idc51aa5ab97a9d3f7a1f316d9536ae1cbaeafe38
-rw-r--r--server/src/com/vaadin/ui/UI.java2
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java44
2 files changed, 46 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index 438b086ec2..78cb5488e8 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -499,6 +499,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
private void attachWindow(Window w) {
windows.add(w);
w.setParent(this);
+ fireComponentAttachEvent(w);
markAsDirty();
}
@@ -523,6 +524,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
window.setParent(null);
markAsDirty();
window.fireClose();
+ fireComponentDetachEvent(window);
return true;
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java
index 51d396801d..5720744e2f 100644
--- a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java
+++ b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java
@@ -3,12 +3,17 @@ package com.vaadin.tests.server.component.window;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
+import com.vaadin.ui.HasComponents.ComponentAttachEvent;
+import com.vaadin.ui.HasComponents.ComponentAttachListener;
+import com.vaadin.ui.HasComponents.ComponentDetachEvent;
+import com.vaadin.ui.HasComponents.ComponentDetachListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@@ -213,6 +218,45 @@ public class AttachDetachWindow {
assertDetached(sub);
}
+ @Test
+ public void addWindow_attachEventIsFired() {
+ TestUI ui = new TestUI();
+ final Window window = new Window();
+
+ final boolean[] eventFired = new boolean[1];
+ ui.addComponentAttachListener(new ComponentAttachListener() {
+
+ @Override
+ public void componentAttachedToContainer(ComponentAttachEvent event) {
+ eventFired[0] = event.getAttachedComponent().equals(window);
+ }
+ });
+ ui.addWindow(window);
+ Assert.assertTrue("Attach event is not fired for added window",
+ eventFired[0]);
+ }
+
+ @Test
+ public void removeWindow_detachEventIsFired() {
+ TestUI ui = new TestUI();
+ final Window window = new Window();
+
+ final boolean[] eventFired = new boolean[1];
+ ui.addComponentDetachListener(new ComponentDetachListener() {
+
+ @Override
+ public void componentDetachedFromContainer(
+ ComponentDetachEvent event) {
+ eventFired[0] = event.getDetachedComponent().equals(window);
+ }
+ });
+ ui.addWindow(window);
+ ui.removeWindow(window);
+
+ Assert.assertTrue("Detach event is not fired for removed window",
+ eventFired[0]);
+ }
+
/**
* Asserts that win and its children are attached to testApp and their
* attach() methods have been called.