\r
import com.google.gwt.event.dom.client.KeyDownEvent;\r
import com.google.gwt.event.dom.client.KeyDownHandler;\r
+import com.google.gwt.event.shared.HandlerRegistration;\r
import com.google.gwt.user.client.DOM;\r
import com.google.gwt.user.client.Element;\r
import com.google.gwt.user.client.Event;\r
import com.vaadin.terminal.gwt.client.Util;\r
import com.vaadin.terminal.gwt.client.VErrorMessage;\r
\r
-public class VForm extends ComplexPanel implements Container {\r
+public class VForm extends ComplexPanel implements Container, KeyDownHandler {\r
\r
protected String id;\r
\r
\r
ShortcutActionHandler shortcutHandler;\r
\r
+ private HandlerRegistration keyDownRegistration;\r
+\r
public VForm() {\r
setElement(DOM.createDiv());\r
DOM.appendChild(getElement(), fieldSet);\r
errorMessage.setStyleName(CLASSNAME + "-errormessage");\r
DOM.appendChild(fieldSet, errorMessage.getElement());\r
DOM.appendChild(fieldSet, footerContainer);\r
-\r
- addDomHandler(new KeyDownHandler() {\r
- public void onKeyDown(KeyDownEvent event) {\r
- shortcutHandler.handleKeyboardEvent(Event.as(event\r
- .getNativeEvent()));\r
- return;\r
- }\r
- }, KeyDownEvent.getType());\r
}\r
\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
\r
// We may have actions attached\r
if (uidl.getChildCount() > 1) {\r
- final int cnt = uidl.getChildCount();\r
- for (int i = 1; i < cnt; i++) {\r
- UIDL childUidl = uidl.getChildUIDL(i);\r
- if (childUidl.getTag().equals("actions")) {\r
- if (shortcutHandler == null) {\r
- shortcutHandler = new ShortcutActionHandler(id, client);\r
- }\r
- shortcutHandler.updateActionMap(childUidl);\r
+ UIDL childUidl = uidl.getChildByTagName("actions");\r
+ if (childUidl != null) {\r
+ if (shortcutHandler == null) {\r
+ shortcutHandler = new ShortcutActionHandler(id, client);\r
+ keyDownRegistration = addDomHandler(this, KeyDownEvent\r
+ .getType());\r
}\r
+ shortcutHandler.updateActionMap(childUidl);\r
}\r
+ } else if (shortcutHandler != null) {\r
+ keyDownRegistration.removeHandler();\r
+ shortcutHandler = null;\r
+ keyDownRegistration = null;\r
}\r
\r
rendering = false;\r
Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, this);\r
}\r
}\r
+\r
+ public void onKeyDown(KeyDownEvent event) {\r
+ shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));\r
+ }\r
}\r