]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #2431
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 8 Jan 2009 06:22:27 +0000 (06:22 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 8 Jan 2009 06:22:27 +0000 (06:22 +0000)
svn changeset:6439/svn branch:trunk

src/com/itmill/toolkit/tests/tickets/Ticket2431.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/Panel.java

diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2431.java b/src/com/itmill/toolkit/tests/tickets/Ticket2431.java
new file mode 100644 (file)
index 0000000..16e2d11
--- /dev/null
@@ -0,0 +1,52 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.event.Action;
+import com.itmill.toolkit.event.ShortcutAction;
+import com.itmill.toolkit.event.Action.Handler;
+import com.itmill.toolkit.event.ShortcutAction.KeyCode;
+import com.itmill.toolkit.event.ShortcutAction.ModifierKey;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Window;
+
+public class Ticket2431 extends Application {
+
+    @Override
+    public void init() {
+
+        Window w = new Window();
+        setMainWindow(w);
+        Label help = new Label(
+                "Use CTRL X to fire action, CTRL C to remove it (fails before fix)");
+
+        w.addComponent(help);
+
+        w.addActionHandler(new Handler() {
+
+            final ShortcutAction a1 = new ShortcutAction("action", KeyCode.X,
+                    new int[] { ModifierKey.CTRL });
+            final ShortcutAction a2 = new ShortcutAction("action", KeyCode.C,
+                    new int[] { ModifierKey.CTRL });
+
+            Action[] actions = new Action[] { a1, a2 };
+
+            public Action[] getActions(Object target, Object sender) {
+                return actions;
+            }
+
+            public void handleAction(Action action, Object sender, Object target) {
+                if (action == a1) {
+                    getMainWindow().addComponent(new Label("CTRL X hit"));
+                } else {
+                    actions = new Action[] { a2 };
+                    // annoyance, we need to repaint the panel or detect the
+                    // action in presence in handler
+                    getMainWindow().removeActionHandler(this);
+                    getMainWindow().addActionHandler(this);
+                }
+            }
+        });
+
+    }
+
+}
index 531fa193ff163fa5a40380bb88be03723cf6fec2..1a8871e7e3d3d7518c00af3405165913fde672f2 100644 (file)
@@ -307,8 +307,9 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
             final String key = (String) variables.get("action");
             final Action action = (Action) actionMapper.get(key);
             if (action != null && actionHandlers != null) {
-                for (final Iterator i = actionHandlers.iterator(); i.hasNext();) {
-                    ((Action.Handler) i.next())
+                Object[] array = actionHandlers.toArray();
+                for (int i = 0; i < array.length; i++) {
+                    ((Action.Handler) array[i])
                             .handleAction(action, this, this);
                 }
             }