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.

VButtonPaintable.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.UIDL;
  12. import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc;
  13. public class VButtonPaintable extends AbstractComponentConnector {
  14. /**
  15. * RPC interface for calls from client to server.
  16. *
  17. * @since 7.0
  18. */
  19. public interface ButtonClientToServerRpc extends ClientToServerRpc {
  20. /**
  21. * Button click event.
  22. *
  23. * @param mouseEventDetails
  24. * serialized mouse event details
  25. */
  26. public void click(String mouseEventDetails);
  27. /**
  28. * Indicate to the server that the client has disabled the button as a
  29. * result of a click.
  30. */
  31. public void disableOnClick();
  32. }
  33. @Override
  34. protected boolean delegateCaptionHandling() {
  35. return false;
  36. }
  37. @Override
  38. public void init() {
  39. super.init();
  40. ButtonClientToServerRpc rpcProxy = GWT
  41. .create(ButtonClientToServerRpc.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
  53. .updateFocusHandler(this, client,
  54. getWidget().focusHandlerRegistration);
  55. getWidget().blurHandlerRegistration = EventHelper
  56. .updateBlurHandler(this, client,
  57. getWidget().blurHandlerRegistration);
  58. // Save details
  59. getWidget().client = client;
  60. getWidget().paintableId = uidl.getId();
  61. // Set text
  62. getWidget().setText(getState().getCaption());
  63. getWidget().disableOnClick = getState().isDisableOnClick();
  64. // handle error
  65. if (uidl.hasAttribute("error")) {
  66. if (getWidget().errorIndicatorElement == null) {
  67. getWidget().errorIndicatorElement = DOM
  68. .createSpan();
  69. getWidget().errorIndicatorElement
  70. .setClassName("v-errorindicator");
  71. }
  72. getWidget().wrapper.insertBefore(
  73. getWidget().errorIndicatorElement,
  74. getWidget().captionElement);
  75. } else if (getWidget().errorIndicatorElement != null) {
  76. getWidget().wrapper
  77. .removeChild(getWidget().errorIndicatorElement);
  78. getWidget().errorIndicatorElement = null;
  79. }
  80. if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
  81. if (getWidget().icon == null) {
  82. getWidget().icon = new Icon(client);
  83. getWidget().wrapper.insertBefore(
  84. getWidget().icon.getElement(),
  85. getWidget().captionElement);
  86. }
  87. getWidget().icon.setUri(uidl
  88. .getStringAttribute(ATTRIBUTE_ICON));
  89. } else {
  90. if (getWidget().icon != null) {
  91. getWidget().wrapper
  92. .removeChild(getWidget().icon.getElement());
  93. getWidget().icon = null;
  94. }
  95. }
  96. getWidget().clickShortcut = getState()
  97. .getClickShortcutKeyCode();
  98. }
  99. @Override
  100. protected Widget createWidget() {
  101. return GWT.create(VButton.class);
  102. }
  103. @Override
  104. public VButton getWidget() {
  105. return (VButton) super.getWidget();
  106. }
  107. @Override
  108. public ButtonState getState() {
  109. return (ButtonState) super.getState();
  110. }
  111. @Override
  112. protected ComponentState createState() {
  113. return GWT.create(ButtonState.class);
  114. }
  115. }