diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-05-22 16:44:20 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-05-22 16:44:20 +0000 |
commit | f8fb7e2997775c3762e6b8cd310d0fe07b7a6587 (patch) | |
tree | 23350be75115dd20cb63f130889169d8326aba1b /src | |
parent | f8da0829bfdb862d2e429b27f86d41754b4ecaf6 (diff) | |
download | vaadin-framework-f8fb7e2997775c3762e6b8cd310d0fe07b7a6587.tar.gz vaadin-framework-f8fb7e2997775c3762e6b8cd310d0fe07b7a6587.zip |
Test case and fix for #2941 - Panel does not remove all Action Handlers on client-side
svn changeset:7969/svn branch:6.0
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VPanel.java | 3 | ||||
-rw-r--r-- | src/com/vaadin/tests/components/caption/PanelShouldRemoveActionHandler.java | 119 |
2 files changed, 122 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java index d1790bf710..1ddf654cb8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java @@ -184,6 +184,9 @@ public class VPanel extends SimplePanel implements Container { shortcutHandler.updateActionMap(childUidl); } } + } else if (shortcutHandler != null) { + // All actions have been removed + shortcutHandler = null; } if (uidl.hasVariable("scrollTop") diff --git a/src/com/vaadin/tests/components/caption/PanelShouldRemoveActionHandler.java b/src/com/vaadin/tests/components/caption/PanelShouldRemoveActionHandler.java new file mode 100644 index 0000000000..227a47f50d --- /dev/null +++ b/src/com/vaadin/tests/components/caption/PanelShouldRemoveActionHandler.java @@ -0,0 +1,119 @@ +package com.vaadin.tests.components.caption; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.event.Action; +import com.vaadin.event.ShortcutAction; +import com.vaadin.event.Action.Handler; +import com.vaadin.event.ShortcutAction.ModifierKey; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Button.ClickEvent; + +public class PanelShouldRemoveActionHandler extends TestBase { + + private Panel panel; + + @Override + protected String getDescription() { + return "Adding action handlers to the panel should make them appear on the client side. Removing the action handlers should remove them also from the client side, also if all action handlers are removed."; + } + + @Override + protected Integer getTicketNumber() { + return 2941; + } + + @Override + protected void setup() { + panel = new Panel("A panel"); + panel.addComponent(new TextField()); + Button add = new Button("Add an action handler", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + add(); + } + + }); + Button addAnother = new Button("Add another action handler", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + addAnother(); + } + + }); + Button remove = new Button("Remove an action handler", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + remove(); + } + + }); + + addComponent(panel); + addComponent(add); + addComponent(addAnother); + addComponent(remove); + } + + public void remove() { + panel.setCaption(panel.getCaption() + " - Removed handler"); + panel.removeActionHandler(actionHandlers + .remove(actionHandlers.size() - 1)); + } + + private List<Handler> actionHandlers = new ArrayList<Handler>(); + + public void add() { + panel.setCaption(panel.getCaption() + " - Added handler"); + Handler actionHandler = new Handler() { + + public Action[] getActions(Object target, Object sender) { + return new Action[] { new ShortcutAction("Ctrl+Left", + ShortcutAction.KeyCode.ARROW_LEFT, + new int[] { ModifierKey.CTRL }) }; + } + + public void handleAction(Action action, Object sender, Object target) { + getMainWindow().showNotification( + "Handling action " + action.getCaption()); + } + + }; + + addHandler(actionHandler); + } + + public void addAnother() { + Handler actionHandler = new Handler() { + + public Action[] getActions(Object target, Object sender) { + return new Action[] { new ShortcutAction("Ctrl+Right", + ShortcutAction.KeyCode.ARROW_RIGHT, + new int[] { ModifierKey.CTRL }) }; + } + + public void handleAction(Action action, Object sender, Object target) { + getMainWindow().showNotification( + "Handling action " + action.getCaption()); + } + + }; + + addHandler(actionHandler); + } + + private void addHandler(Handler actionHandler) { + actionHandlers.add(actionHandler); + panel.addActionHandler(actionHandler); + panel.setCaption("A panel with " + actionHandlers.size() + + " action handlers"); + + } +} |