aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2012-10-01 11:31:58 +0000
committerVaadin Code Review <review@vaadin.com>2012-10-01 11:31:58 +0000
commit9d348da520096bc73681bd648ae68cb8d14800e4 (patch)
tree6dac364b5c2eeb3c4d96e38a896e3bf53982a5ca /server/src
parent4a9daa9edda206840aef12732606608587ce05ac (diff)
parenta003c8724c1f719e3a9f3ab876396a180b19cae1 (diff)
downloadvaadin-framework-9d348da520096bc73681bd648ae68cb8d14800e4.tar.gz
vaadin-framework-9d348da520096bc73681bd648ae68cb8d14800e4.zip
Merge "Merged shortcut action fix from 6.8 (#8484)"
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/event/ActionManager.java30
-rw-r--r--server/src/com/vaadin/event/ShortcutAction.java45
-rw-r--r--server/src/com/vaadin/ui/Button.java9
3 files changed, 75 insertions, 9 deletions
diff --git a/server/src/com/vaadin/event/ActionManager.java b/server/src/com/vaadin/event/ActionManager.java
index 85a1bf0f12..ad643863a7 100644
--- a/server/src/com/vaadin/event/ActionManager.java
+++ b/server/src/com/vaadin/event/ActionManager.java
@@ -18,6 +18,7 @@ package com.vaadin.event;
import java.util.HashSet;
import java.util.Map;
+import com.vaadin.client.ui.ShortcutActionHandler;
import com.vaadin.event.Action.Container;
import com.vaadin.event.Action.Handler;
import com.vaadin.server.KeyMapper;
@@ -187,14 +188,29 @@ public class ActionManager implements Action.Container, Action.Handler,
}
if (a instanceof ShortcutAction) {
final ShortcutAction sa = (ShortcutAction) a;
- paintTarget.addAttribute("kc", sa.getKeyCode());
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_SHORTCUT_KEY_ATTRIBUTE,
+ 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("mk", smodifiers);
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_MODIFIER_KEYS_ATTRIBUTE,
+ smodifiers);
+ }
+ if (sa.getTarget() != null) {
+ paintTarget.addAttribute(
+ ShortcutActionHandler.ACTION_TARGET_ATTRIBUTE,
+ sa.getTarget());
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_TARGET_ACTION_ATTRIBUTE,
+ sa.getTargetAction());
}
}
paintTarget.endTag("action");
@@ -212,10 +228,14 @@ public class ActionManager implements Action.Container, Action.Handler,
}
public void handleActions(Map<String, Object> variables, Container sender) {
- if (variables.containsKey("action") && actionMapper != null) {
- final String key = (String) variables.get("action");
+ if (variables
+ .containsKey(ShortcutActionHandler.ACTION_TARGET_ACTION_VARIABLE)
+ && actionMapper != null) {
+ final String key = (String) variables
+ .get(ShortcutActionHandler.ACTION_TARGET_ACTION_VARIABLE);
final Action action = actionMapper.get(key);
- final Object target = variables.get("actiontarget");
+ final Object target = variables
+ .get(ShortcutActionHandler.ACTION_TARGET_VARIABLE);
if (action != null) {
handleAction(action, sender, target);
}
diff --git a/server/src/com/vaadin/event/ShortcutAction.java b/server/src/com/vaadin/event/ShortcutAction.java
index b1d14b15fe..9d13d41b9f 100644
--- a/server/src/com/vaadin/event/ShortcutAction.java
+++ b/server/src/com/vaadin/event/ShortcutAction.java
@@ -21,6 +21,7 @@ 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;
@@ -57,6 +58,10 @@ 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/>
@@ -237,6 +242,46 @@ public class ShortcutAction extends Action {
}
/**
+ * Set the target for the shortcut action. If the target widget on the
+ * client side implements {@link 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 {@link ShortcutActionTarget}
+ * on the client side
+ *
+ * @return
+ */
+ public String getTargetAction() {
+ return targetAction;
+ }
+
+ /**
+ * Set the action string that is give to the {@link 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
*
*/
diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java
index 02b7689259..d248efd570 100644
--- a/server/src/com/vaadin/ui/Button.java
+++ b/server/src/com/vaadin/ui/Button.java
@@ -463,7 +463,6 @@ 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
@@ -476,7 +475,8 @@ public class Button extends AbstractComponent implements
*/
public ClickShortcut(Button button, String shorthandCaption) {
super(shorthandCaption);
- this.button = button;
+ setTarget(button);
+ setTargetAction("click");
}
/**
@@ -492,7 +492,8 @@ public class Button extends AbstractComponent implements
*/
public ClickShortcut(Button button, int keyCode, int... modifiers) {
super(null, keyCode, modifiers);
- this.button = button;
+ setTarget(button);
+ setTargetAction("click");
}
/**
@@ -510,7 +511,7 @@ public class Button extends AbstractComponent implements
@Override
public void handleAction(Object sender, Object target) {
- button.click();
+ // Action handled on the client side
}
}