]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Merged shortcut action fix from 6.8 (#8484)" 67/367/2
authorJohn Ahlroos <john@vaadin.com>
Thu, 22 Nov 2012 09:24:22 +0000 (09:24 +0000)
committerJohn Ahlroos <john@vaadin.com>
Fri, 23 Nov 2012 15:09:35 +0000 (17:09 +0200)
This reverts commit a003c8724c1f719e3a9f3ab876396a180b19cae1

Change-Id: Ie73b6f0455a9f8ba1ed5a8cee7573ae998a67b17

client/src/com/vaadin/client/ui/ShortcutAction.java [deleted file]
client/src/com/vaadin/client/ui/ShortcutActionHandler.java
client/src/com/vaadin/client/ui/ShortcutActionTarget.java [deleted file]
client/src/com/vaadin/client/ui/button/ButtonConnector.java
server/src/com/vaadin/event/ActionManager.java
server/src/com/vaadin/event/ShortcutAction.java
server/src/com/vaadin/ui/Button.java

diff --git a/client/src/com/vaadin/client/ui/ShortcutAction.java b/client/src/com/vaadin/client/ui/ShortcutAction.java
deleted file mode 100644 (file)
index 3209c02..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.client.ui;
-
-import com.vaadin.client.ApplicationConnection;
-import com.vaadin.server.KeyMapper;
-
-public class ShortcutAction {
-
-    private final ShortcutKeyCombination sc;
-    private final String caption;
-    private final String key;
-    private String targetCID;
-    private String targetAction;
-
-    /**
-     * Constructor
-     * 
-     * @param key
-     *            The @link {@link KeyMapper} key of the action.
-     * @param sc
-     *            The key combination that triggers the action
-     * @param caption
-     *            The caption of the action
-     */
-    public ShortcutAction(String key, ShortcutKeyCombination sc, String caption) {
-        this(key, sc, caption, null, null);
-    }
-
-    /**
-     * Constructor
-     * 
-     * @param key
-     *            The @link {@link KeyMapper} key of the action.
-     * @param sc
-     *            The key combination that triggers the action
-     * @param caption
-     *            The caption of the action
-     * @param targetPID
-     *            The pid of the component the action is targeting. We use the
-     *            pid, instead of the actual Paintable here, so we can delay the
-     *            fetching of the Paintable in cases where the Paintable does
-     *            not yet exist when the action is painted.
-     * @param targetAction
-     *            The target string of the action. The target string is given to
-     *            the targeted Paintable if the paintable implements the
-     *            {@link ShortcutActionTarget} interface.
-     */
-    public ShortcutAction(String key, ShortcutKeyCombination sc,
-            String caption, String targetCID, String targetAction) {
-        this.sc = sc;
-        this.key = key;
-        this.caption = caption;
-        this.targetCID = targetCID;
-        this.targetAction = targetAction;
-    }
-
-    /**
-     * Get the key combination that triggers the action
-     */
-    public ShortcutKeyCombination getShortcutCombination() {
-        return sc;
-    }
-
-    /**
-     * Get the caption of the action
-     */
-    public String getCaption() {
-        return caption;
-    }
-
-    /**
-     * Get the {@link KeyMapper} key for the action
-     */
-    public String getKey() {
-        return key;
-    }
-
-    /**
-     * Get the pid of the target of the action. Use
-     * {@link ApplicationConnection#getPaintable(String)} to get the actual
-     * Paintable
-     */
-    public String getTargetCID() {
-        return targetCID;
-    }
-
-    /**
-     * Get the target string of the action
-     */
-    public String getTargetAction() {
-        return targetAction;
-    }
-
-}
\ No newline at end of file
index 7165fd74903d2f6515caf971301a0f6fb5ba7a56..25d5cde329c49c2ccb4f577e7ee2fc8298ee5adb 100644 (file)
@@ -30,11 +30,8 @@ import com.google.gwt.user.client.ui.KeyboardListenerCollection;
 import com.vaadin.client.ApplicationConnection;
 import com.vaadin.client.BrowserInfo;
 import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ConnectorMap;
 import com.vaadin.client.UIDL;
 import com.vaadin.client.Util;
-import com.vaadin.shared.Connector;
-import com.vaadin.shared.ui.ShortCutConstants;
 
 /**
  * A helper class to implement keyboard shorcut handling. Keeps a list of owners
@@ -110,25 +107,15 @@ public class ShortcutActionHandler {
             final UIDL action = (UIDL) it.next();
 
             int[] modifiers = null;
-            if (action
-                    .hasAttribute(ShortCutConstants.ACTION_MODIFIER_KEYS_ATTRIBUTE)) {
-                modifiers = action
-                        .getIntArrayAttribute(ShortCutConstants.ACTION_MODIFIER_KEYS_ATTRIBUTE);
+            if (action.hasAttribute("mk")) {
+                modifiers = action.getIntArrayAttribute("mk");
             }
 
             final ShortcutKeyCombination kc = new ShortcutKeyCombination(
-                    action.getIntAttribute(ShortCutConstants.ACTION_SHORTCUT_KEY_ATTRIBUTE),
-                    modifiers);
-            final String key = action
-                    .getStringAttribute(ShortCutConstants.ACTION_KEY_ATTRIBUTE);
-            final String caption = action
-                    .getStringAttribute(ShortCutConstants.ACTION_CAPTION_ATTRIBUTE);
-            final String targetPID = action
-                    .getStringAttribute(ShortCutConstants.ACTION_TARGET_ATTRIBUTE);
-            final String targetAction = action
-                    .getStringAttribute(ShortCutConstants.ACTION_TARGET_ACTION_ATTRIBUTE);
-            actions.add(new ShortcutAction(key, kc, caption, targetPID,
-                    targetAction));
+                    action.getIntAttribute("kc"), modifiers);
+            final String key = action.getStringAttribute("key");
+            final String caption = action.getStringAttribute("caption");
+            actions.add(new ShortcutAction(key, kc, caption));
         }
     }
 
@@ -183,24 +170,11 @@ public class ShortcutActionHandler {
         Scheduler.get().scheduleDeferred(new Command() {
             @Override
             public void execute() {
-                Connector shortcutTarget = ConnectorMap.get(client)
-                        .getConnector(a.getTargetCID());
-
-                boolean handledClientSide = false;
-                if (shortcutTarget instanceof ShortcutActionTarget) {
-                    handledClientSide = ((ShortcutActionTarget) shortcutTarget)
-                            .handleAction(a);
-                }
-                if (!handledClientSide) {
-                    if (finalTarget != null) {
-                        client.updateVariable(paintableId,
-                                ShortCutConstants.ACTION_TARGET_VARIABLE,
-                                finalTarget, false);
-                    }
-                    client.updateVariable(paintableId,
-                            ShortCutConstants.ACTION_TARGET_ACTION_VARIABLE,
-                            a.getKey(), true);
+                if (finalTarget != null) {
+                    client.updateVariable(paintableId, "actiontarget",
+                            finalTarget, false);
                 }
+                client.updateVariable(paintableId, "action", a.getKey(), true);
             }
         });
     }
@@ -307,3 +281,29 @@ class ShortcutKeyCombination {
         return false;
     }
 }
+
+class ShortcutAction {
+
+    private final ShortcutKeyCombination sc;
+    private final String caption;
+    private final String key;
+
+    public ShortcutAction(String key, ShortcutKeyCombination sc, String caption) {
+        this.sc = sc;
+        this.key = key;
+        this.caption = caption;
+    }
+
+    public ShortcutKeyCombination getShortcutCombination() {
+        return sc;
+    }
+
+    public String getCaption() {
+        return caption;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+}
diff --git a/client/src/com/vaadin/client/ui/ShortcutActionTarget.java b/client/src/com/vaadin/client/ui/ShortcutActionTarget.java
deleted file mode 100644 (file)
index 6173346..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.client.ui;
-
-/**
- * Widgets who wish to be notificed when a shortcut action has been triggered
- * with the widget as a target should implement this interface. The
- * {@link #handleAction(ShortcutAction)} method will be called just before the
- * action is communicated to the server
- * 
- */
-public interface ShortcutActionTarget {
-
-    /**
-     * Called by the {@link ShortcutActionHandler} just before the shortcut
-     * action is sent to the server side
-     * 
-     * @param action
-     *            The action which will be performed on the server side
-     * @return Returns true if the shortcut was handled
-     */
-    boolean handleAction(ShortcutAction action);
-}
index 18913b9b0dd6ce8df9349c57f5ca6450f7ecf391..a4c2f153d8393eef5a797543ca0a0fea99c1ff0a 100644 (file)
@@ -32,8 +32,6 @@ import com.vaadin.client.communication.StateChangeEvent;
 import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
 import com.vaadin.client.ui.AbstractComponentConnector;
 import com.vaadin.client.ui.Icon;
-import com.vaadin.client.ui.ShortcutAction;
-import com.vaadin.client.ui.ShortcutActionTarget;
 import com.vaadin.client.ui.VButton;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
@@ -45,7 +43,7 @@ import com.vaadin.ui.Button;
 
 @Connect(value = Button.class, loadStyle = LoadStyle.EAGER)
 public class ButtonConnector extends AbstractComponentConnector implements
-        BlurHandler, FocusHandler, ClickHandler, ShortcutActionTarget {
+        BlurHandler, FocusHandler, ClickHandler {
 
     private HandlerRegistration focusHandlerRegistration = null;
     private HandlerRegistration blurHandlerRegistration = null;
@@ -169,21 +167,4 @@ public class ButtonConnector extends AbstractComponentConnector implements
         getRpcProxy(ButtonServerRpc.class).click(details);
 
     }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * com.vaadin.terminal.gwt.client.ui.ShortcutActionTarget#handleAction(com
-     * .vaadin.terminal.gwt.client.ui.ShortcutAction)
-     */
-    @Override
-    public boolean handleAction(ShortcutAction action) {
-        if ("click".equals(action.getTargetAction())) {
-            getWidget().onClick();
-            return true;
-        }
-        return false;
-    }
-
 }
index 50bb2f8dad515341f2c4abc44a9792974ef496d1..b644bb7422290f57c757998789b01f44382ab1d0 100644 (file)
@@ -24,7 +24,6 @@ import com.vaadin.server.KeyMapper;
 import com.vaadin.server.PaintException;
 import com.vaadin.server.PaintTarget;
 import com.vaadin.server.VariableOwner;
-import com.vaadin.shared.ui.ShortCutConstants;
 import com.vaadin.ui.Component;
 
 /**
@@ -188,28 +187,15 @@ public class ActionManager implements Action.Container, Action.Handler,
                 }
                 if (a instanceof ShortcutAction) {
                     final ShortcutAction sa = (ShortcutAction) a;
-                    paintTarget.addAttribute(
-                            ShortCutConstants.ACTION_SHORTCUT_KEY_ATTRIBUTE,
-                            sa.getKeyCode());
+                    paintTarget.addAttribute("kc", sa.getKeyCode());
+
                     final int[] modifiers = sa.getModifiers();
                     if (modifiers != null) {
                         final String[] smodifiers = new String[modifiers.length];
                         for (int i = 0; i < modifiers.length; i++) {
                             smodifiers[i] = String.valueOf(modifiers[i]);
                         }
-                        paintTarget
-                                .addAttribute(
-                                        ShortCutConstants.ACTION_MODIFIER_KEYS_ATTRIBUTE,
-                                        smodifiers);
-                    }
-                    if (sa.getTarget() != null) {
-                        paintTarget.addAttribute(
-                                ShortCutConstants.ACTION_TARGET_ATTRIBUTE,
-                                sa.getTarget());
-                        paintTarget
-                                .addAttribute(
-                                        ShortCutConstants.ACTION_TARGET_ACTION_ATTRIBUTE,
-                                        sa.getTargetAction());
+                        paintTarget.addAttribute("mk", smodifiers);
                     }
                 }
                 paintTarget.endTag("action");
@@ -227,14 +213,10 @@ public class ActionManager implements Action.Container, Action.Handler,
     }
 
     public void handleActions(Map<String, Object> variables, Container sender) {
-        if (variables
-                .containsKey(ShortCutConstants.ACTION_TARGET_ACTION_VARIABLE)
-                && actionMapper != null) {
-            final String key = (String) variables
-                    .get(ShortCutConstants.ACTION_TARGET_ACTION_VARIABLE);
+        if (variables.containsKey("action") && actionMapper != null) {
+            final String key = (String) variables.get("action");
             final Action action = actionMapper.get(key);
-            final Object target = variables
-                    .get(ShortCutConstants.ACTION_TARGET_VARIABLE);
+            final Object target = variables.get("actiontarget");
             if (action != null) {
                 handleAction(action, sender, target);
             }
index 4583b04bf98e433137e8cc14c7aff8f0535730c0..b1d14b15fe2035179ac0f745ab04eb22b08422c4 100644 (file)
@@ -21,7 +21,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import com.vaadin.server.Resource;
-import com.vaadin.ui.Component;
 import com.vaadin.ui.ComponentContainer;
 import com.vaadin.ui.Panel;
 import com.vaadin.ui.Window;
@@ -58,10 +57,6 @@ public class ShortcutAction extends Action {
 
     private final int[] modifiers;
 
-    private Component target;
-
-    private String targetAction;
-
     /**
      * Creates a shortcut that reacts to the given {@link KeyCode} and
      * (optionally) {@link ModifierKey}s. <br/>
@@ -241,46 +236,6 @@ public class ShortcutAction extends Action {
         return modifiers;
     }
 
-    /**
-     * Set the target for the shortcut action. If the target widget on the
-     * client side implements ShortcutActionTarget it will be notified of the
-     * action before the action is communicated to the server side
-     * 
-     * @param target
-     *            The component which will be thet target of the action
-     */
-    public void setTarget(Component target) {
-        this.target = target;
-    }
-
-    /**
-     * Get the target of the shortcut action
-     */
-    public Component getTarget() {
-        return target;
-    }
-
-    /**
-     * Get the action string that is given to the ShortcutActionTarget on the
-     * client side
-     * 
-     * @return
-     */
-    public String getTargetAction() {
-        return targetAction;
-    }
-
-    /**
-     * Set the action string that is give to the ShortcutActionTarget on the
-     * client side
-     * 
-     * @param targetAction
-     *            The target action string
-     */
-    public void setTargetAction(String targetAction) {
-        this.targetAction = targetAction;
-    }
-
     /**
      * Key codes that can be used for shortcuts
      * 
index d581293713573244c70a3aed762bbe8d70c28bc6..dc3c21089906453a3735d9c4a372de840b36f1b6 100644 (file)
@@ -472,6 +472,7 @@ public class Button extends AbstractComponent implements
      * 
      */
     public static class ClickShortcut extends ShortcutListener {
+        protected Button button;
 
         /**
          * Creates a keyboard shortcut for clicking the given button using the
@@ -484,8 +485,7 @@ public class Button extends AbstractComponent implements
          */
         public ClickShortcut(Button button, String shorthandCaption) {
             super(shorthandCaption);
-            setTarget(button);
-            setTargetAction("click");
+            this.button = button;
         }
 
         /**
@@ -501,8 +501,7 @@ public class Button extends AbstractComponent implements
          */
         public ClickShortcut(Button button, int keyCode, int... modifiers) {
             super(null, keyCode, modifiers);
-            setTarget(button);
-            setTargetAction("click");
+            this.button = button;
         }
 
         /**
@@ -520,7 +519,7 @@ public class Button extends AbstractComponent implements
 
         @Override
         public void handleAction(Object sender, Object target) {
-            // Action handled on the client side
+            button.click();
         }
     }