summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.