You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CapsLockWarningWithRpcConnector.java 1.6KB

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