Remove all listeners from entities passed to Window.Lookup.Handler and from item of closed Window.Editor #PL-4677

This commit is contained in:
Yuriy Artamonov 2015-09-28 09:58:09 +00:00
parent f1b0cc18b6
commit bdaaeef81b
3 changed files with 26 additions and 8 deletions

View File

@ -6,12 +6,12 @@
package com.haulmont.cuba.desktop.gui.components;
import com.haulmont.bali.datastruct.Pair;
import com.haulmont.chile.core.model.Instance;
import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.desktop.App;
import com.haulmont.cuba.desktop.gui.data.ComponentSize;
import com.haulmont.cuba.desktop.gui.data.DesktopContainerHelper;
@ -1006,6 +1006,12 @@ public class DesktopWindow implements Window, Component.Disposable,
}
protected void fireWindowClosed(String actionId) {
if (this instanceof Window.Editor) {
Entity item = ((Window.Editor) this).getItem();
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
metadataTools.traverseAttributes(item, (entity, property) -> entity.removeAllListeners());
}
for (Object listener : listeners) {
if (listener instanceof CloseListener) {
((CloseListener) listener).windowClosed(actionId);
@ -1465,8 +1471,9 @@ public class DesktopWindow implements Window, Component.Disposable,
}
close(Window.SELECT_ACTION_ID);
for (Object obj : selected) {
if (obj instanceof Instance) {
((Instance) obj).removeAllListeners();
if (obj instanceof Entity) {
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
metadataTools.traverseAttributes((Entity) obj, (entity, property) -> entity.removeAllListeners());
}
}
handler.handleLookup(selected);

View File

@ -4,8 +4,10 @@
*/
package com.haulmont.cuba.web.gui;
import com.haulmont.chile.core.model.Instance;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.DevelopmentException;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.gui.components.*;
import com.vaadin.ui.Button;
@ -55,14 +57,16 @@ public class SelectAction implements Button.ClickListener {
final Window.Lookup.Handler lookupHandler = window.getLookupHandler();
window.close(Window.SELECT_ACTION_ID);
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
for (Object obj : selected) {
if (obj instanceof Instance) {
((Instance) obj).removeAllListeners();
if (obj instanceof Entity) {
metadataTools.traverseAttributes((Entity) obj, (entity, property) -> entity.removeAllListeners());
}
}
if (lookupHandler != null)
if (lookupHandler != null) {
lookupHandler.handleLookup(selected);
else
} else {
throw new DevelopmentException("A Lookup.Handler was not passed to lookup window " + window.getId());
}
}
}

View File

@ -11,6 +11,7 @@ import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.gui.*;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.Action.Status;
@ -698,6 +699,12 @@ public class WebWindow implements Window, Component.Wrapper,
protected void fireWindowClosed(String actionId) {
if (listeners != null) {
if (this instanceof Window.Editor) {
Entity item = ((Window.Editor) this).getItem();
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
metadataTools.traverseAttributes(item, (entity, property) -> entity.removeAllListeners());
}
for (Object listener : listeners) {
if (listener instanceof CloseListener) {
((CloseListener) listener).windowClosed(actionId);