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 4.0KB

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