From 8664c97c7bb6fb36b2ebbe3849b51ec00e052e24 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 31 Mar 2015 15:41:46 +0300 Subject: Fix declarative support for Window (#17314) Change-Id: If89a46a4c08ec1491eb00a2f2b8580fb3ef785fc --- .../converters/DesignShortcutActionConverter.java | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'server/src/com/vaadin/ui/declarative') diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignShortcutActionConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignShortcutActionConverter.java index e2b6ed8e14..d6f2f65938 100644 --- a/server/src/com/vaadin/ui/declarative/converters/DesignShortcutActionConverter.java +++ b/server/src/com/vaadin/ui/declarative/converters/DesignShortcutActionConverter.java @@ -126,32 +126,37 @@ public class DesignShortcutActionConverter implements if (value.length() == 0) { return null; } - String[] data = value.split(" ", 2); + String[] data = value.split(" ", 2); String[] parts = data[0].split("-"); - // handle keycode - String keyCodePart = parts[parts.length - 1]; - int keyCode = getKeycodeForString(keyCodePart); - if (keyCode < 0) { - throw new IllegalArgumentException("Invalid shortcut definition " - + value); - } - // handle modifiers - int[] modifiers = null; - if (parts.length > 1) { - modifiers = new int[parts.length - 1]; - } - for (int i = 0; i < parts.length - 1; i++) { - int modifier = getKeycodeForString(parts[i]); - if (modifier > 0) { - modifiers[i] = modifier; - } else { - throw new IllegalArgumentException( - "Invalid shortcut definition " + value); + + try { + // handle keycode + String keyCodePart = parts[parts.length - 1]; + int keyCode = getKeycodeForString(keyCodePart); + if (keyCode < 0) { + throw new IllegalArgumentException("Invalid key '" + + keyCodePart + "'"); + } + // handle modifiers + int[] modifiers = null; + if (parts.length > 1) { + modifiers = new int[parts.length - 1]; + } + for (int i = 0; i < parts.length - 1; i++) { + int modifier = getKeycodeForString(parts[i]); + if (modifier > 0) { + modifiers[i] = modifier; + } else { + throw new IllegalArgumentException("Invalid modifier '" + + parts[i] + "'"); + } } + return new ShortcutAction(data.length == 2 ? data[1] : null, + keyCode, modifiers); + } catch (Exception e) { + throw new ConversionException("Invalid shortcut '" + value + "'", e); } - return new ShortcutAction(data.length == 2 ? data[1] : null, keyCode, - modifiers); } @Override -- cgit v1.2.3