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.

MyComponent.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.vaadin.tests.minitutorials.v7a2;
  2. import com.vaadin.shared.MouseEventDetails;
  3. import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentClientRpc;
  4. import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentServerRpc;
  5. import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentState;
  6. import com.vaadin.ui.AbstractComponent;
  7. public class MyComponent extends AbstractComponent {
  8. private int clickCount = 0;
  9. private MyComponentServerRpc rpc = new MyComponentServerRpc() {
  10. @Override
  11. public void clicked(MouseEventDetails mouseDetails) {
  12. clickCount++;
  13. // nag every 5:th click
  14. if (clickCount % 5 == 0) {
  15. getRpcProxy(MyComponentClientRpc.class)
  16. .alert("Ok, that's enough!");
  17. }
  18. setText("You have clicked " + clickCount + " times");
  19. }
  20. };
  21. public MyComponent() {
  22. registerRpc(rpc);
  23. }
  24. @Override
  25. public MyComponentState getState() {
  26. return (MyComponentState) super.getState();
  27. }
  28. public void setText(String text) {
  29. getState().text = text;
  30. }
  31. public String getText() {
  32. return getState().text;
  33. }
  34. }