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.

ButtonConnector.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.user.client.DOM;
  7. import com.google.gwt.user.client.ui.Widget;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.ComponentState;
  10. import com.vaadin.terminal.gwt.client.EventHelper;
  11. import com.vaadin.terminal.gwt.client.MouseEventDetails;
  12. import com.vaadin.terminal.gwt.client.UIDL;
  13. import com.vaadin.terminal.gwt.client.communication.ServerRpc;
  14. public class ButtonConnector extends AbstractComponentConnector {
  15. /**
  16. * RPC interface for calls from client to server.
  17. *
  18. * @since 7.0
  19. */
  20. public interface ButtonServerRpc extends ServerRpc {
  21. /**
  22. * Button click event.
  23. *
  24. * @param mouseEventDetails
  25. * serialized mouse event details
  26. */
  27. public void click(MouseEventDetails mouseEventDetails);
  28. /**
  29. * Indicate to the server that the client has disabled the button as a
  30. * result of a click.
  31. */
  32. public void disableOnClick();
  33. }
  34. @Override
  35. protected boolean delegateCaptionHandling() {
  36. return false;
  37. }
  38. @Override
  39. public void init() {
  40. super.init();
  41. ButtonServerRpc rpcProxy = GWT.create(ButtonServerRpc.class);
  42. getWidget().buttonRpcProxy = initRPC(rpcProxy);
  43. }
  44. @Override
  45. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  46. // Ensure correct implementation,
  47. // but don't let container manage caption etc.
  48. super.updateFromUIDL(uidl, client);
  49. if (!isRealUpdate(uidl)) {
  50. return;
  51. }
  52. getWidget().focusHandlerRegistration = EventHelper.updateFocusHandler(
  53. this, client, getWidget().focusHandlerRegistration);
  54. getWidget().blurHandlerRegistration = EventHelper.updateBlurHandler(
  55. this, client, getWidget().blurHandlerRegistration);
  56. // Save details
  57. getWidget().client = client;
  58. getWidget().paintableId = uidl.getId();
  59. // Set text
  60. getWidget().setText(getState().getCaption());
  61. getWidget().disableOnClick = getState().isDisableOnClick();
  62. // handle error
  63. if (null != getState().getErrorMessage()) {
  64. if (getWidget().errorIndicatorElement == null) {
  65. getWidget().errorIndicatorElement = DOM.createSpan();
  66. getWidget().errorIndicatorElement
  67. .setClassName("v-errorindicator");
  68. }
  69. getWidget().wrapper.insertBefore(getWidget().errorIndicatorElement,
  70. getWidget().captionElement);
  71. } else if (getWidget().errorIndicatorElement != null) {
  72. getWidget().wrapper.removeChild(getWidget().errorIndicatorElement);
  73. getWidget().errorIndicatorElement = null;
  74. }
  75. if (getState().getIcon() != null) {
  76. if (getWidget().icon == null) {
  77. getWidget().icon = new Icon(client);
  78. getWidget().wrapper.insertBefore(getWidget().icon.getElement(),
  79. getWidget().captionElement);
  80. }
  81. getWidget().icon.setUri(getState().getIcon().getURL());
  82. } else {
  83. if (getWidget().icon != null) {
  84. getWidget().wrapper.removeChild(getWidget().icon.getElement());
  85. getWidget().icon = null;
  86. }
  87. }
  88. getWidget().clickShortcut = getState().getClickShortcutKeyCode();
  89. }
  90. @Override
  91. protected Widget createWidget() {
  92. return GWT.create(VButton.class);
  93. }
  94. @Override
  95. public VButton getWidget() {
  96. return (VButton) super.getWidget();
  97. }
  98. @Override
  99. public ButtonState getState() {
  100. return (ButtonState) super.getState();
  101. }
  102. @Override
  103. protected ComponentState createState() {
  104. return GWT.create(ButtonState.class);
  105. }
  106. }