Vojtech Szocs has uploaded a new change for review. Change subject: webadmin,userportal: Listener cleanup in UiCommandButtonDefinition ......................................................................
webadmin,userportal: Listener cleanup in UiCommandButtonDefinition This patch removes PropertyChangedEvent listener on the original command before setting new command (and attaching listener to it). Change-Id: Ide1e188efd024080cb16edb7cf5826208ca04091 Signed-off-by: Vojtech Szocs <[email protected]> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/action/UiCommandButtonDefinition.java 1 file changed, 32 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/12030/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/action/UiCommandButtonDefinition.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/action/UiCommandButtonDefinition.java index b0e50af..5d9ce4b 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/action/UiCommandButtonDefinition.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/action/UiCommandButtonDefinition.java @@ -37,6 +37,7 @@ protected final EventBus eventBus; private UICommand command; + private IEventListener propertyChangeListener; private final SafeHtml title; @@ -115,21 +116,43 @@ UICommand newCommand = command != null ? command : EMPTY_COMMAND; if (this.command != newCommand) { - this.command = newCommand; - InitializeEvent.fire(UiCommandButtonDefinition.this); + // Remove property change handler from current command + removePropertyChangeEventHandler(); - // Register property change handler + // Update current command + this.command = newCommand; + fireInitializeEvent(); + + // Add property change handler to new command if (newCommand != EMPTY_COMMAND) { - newCommand.getPropertyChangedEvent().addListener(new IEventListener() { - @Override - public void eventRaised(Event ev, Object sender, EventArgs args) { - InitializeEvent.fire(UiCommandButtonDefinition.this); - } - }); + addPropertyChangeEventHandler(); } } } + void addPropertyChangeEventHandler() { + if (command != null) { + propertyChangeListener = new IEventListener() { + @Override + public void eventRaised(Event ev, Object sender, EventArgs args) { + fireInitializeEvent(); + } + }; + command.getPropertyChangedEvent().addListener(propertyChangeListener); + } + } + + void removePropertyChangeEventHandler() { + if (command != null && propertyChangeListener != null) { + command.getPropertyChangedEvent().removeListener(propertyChangeListener); + propertyChangeListener = null; + } + } + + void fireInitializeEvent() { + InitializeEvent.fire(this); + } + /** * Returns the command associated with this button definition. * <p> -- To view, visit http://gerrit.ovirt.org/12030 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ide1e188efd024080cb16edb7cf5826208ca04091 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Vojtech Szocs <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
