]> source.dussan.org Git - vaadin-framework.git/blob
b7dead981905aa6d798f659f94244a29bc1fd337
[vaadin-framework.git] /
1 package com.vaadin.tests.widgetset.client.minitutorials.v7b1;
2
3 import com.google.gwt.event.dom.client.KeyPressEvent;
4 import com.google.gwt.event.dom.client.KeyPressHandler;
5 import com.google.gwt.user.client.ui.HTML;
6 import com.google.gwt.user.client.ui.Widget;
7 import com.vaadin.client.ComponentConnector;
8 import com.vaadin.client.ServerConnector;
9 import com.vaadin.client.communication.RpcProxy;
10 import com.vaadin.client.extensions.AbstractExtensionConnector;
11 import com.vaadin.client.ui.VOverlay;
12 import com.vaadin.shared.ui.Connect;
13 import com.vaadin.tests.minitutorials.v7b1.CapsLockWarningWithRpc;
14
15 @Connect(CapsLockWarningWithRpc.class)
16 public class CapsLockWarningWithRpcConnector extends AbstractExtensionConnector {
17
18     private CapsLockWarningRpc rpc = RpcProxy.create(CapsLockWarningRpc.class,
19             this);
20
21     @Override
22     protected void extend(ServerConnector target) {
23         final Widget passwordWidget = ((ComponentConnector) target).getWidget();
24
25         final VOverlay warning = new VOverlay();
26         warning.setOwner(passwordWidget);
27         warning.add(new HTML("Caps Lock is enabled!"));
28
29         passwordWidget.addDomHandler(new KeyPressHandler() {
30             @Override
31             public void onKeyPress(KeyPressEvent event) {
32                 if (isEnabled() && isCapsLockOn(event)) {
33                     warning.showRelativeTo(passwordWidget);
34                     rpc.isCapsLockEnabled(true); // Added to send message to the
35                                                  // server
36                 } else {
37                     warning.hide();
38                     rpc.isCapsLockEnabled(false); // Added to send message to
39                                                   // the server
40                 }
41             }
42         }, KeyPressEvent.getType());
43     }
44
45     private boolean isCapsLockOn(KeyPressEvent e) {
46         return e.isShiftKeyDown() ^ Character.isUpperCase(e.getCharCode());
47     }
48 }