Ver código fonte

Fire attach/detach events when Window is added/removed from UI (#14908).

Change-Id: Idc51aa5ab97a9d3f7a1f316d9536ae1cbaeafe38
tags/7.4.0.beta1
Denis Anisimov 9 anos atrás
pai
commit
b5d16c5305

+ 2
- 0
server/src/com/vaadin/ui/UI.java Ver arquivo

@@ -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;
}

+ 44
- 0
server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java Ver arquivo

@@ -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.

Carregando…
Cancelar
Salvar