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.

NativeButtonConnector.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.nativebutton;
  17. import com.google.gwt.event.dom.client.ClickEvent;
  18. import com.google.gwt.event.dom.client.ClickHandler;
  19. import com.vaadin.client.MouseEventDetailsBuilder;
  20. import com.vaadin.client.VCaption;
  21. import com.vaadin.client.communication.StateChangeEvent;
  22. import com.vaadin.client.ui.AbstractComponentConnector;
  23. import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
  24. import com.vaadin.client.ui.Icon;
  25. import com.vaadin.client.ui.VNativeButton;
  26. import com.vaadin.shared.MouseEventDetails;
  27. import com.vaadin.shared.ui.Connect;
  28. import com.vaadin.shared.ui.button.ButtonServerRpc;
  29. import com.vaadin.shared.ui.button.NativeButtonState;
  30. import com.vaadin.ui.NativeButton;
  31. @Connect(NativeButton.class)
  32. public class NativeButtonConnector extends AbstractComponentConnector
  33. implements ClickHandler {
  34. @Override
  35. public void init() {
  36. super.init();
  37. getWidget().buttonRpcProxy = getRpcProxy(ButtonServerRpc.class);
  38. getWidget().client = getConnection();
  39. getWidget().paintableId = getConnectorId();
  40. getWidget().addClickHandler(this);
  41. ConnectorFocusAndBlurHandler.addHandlers(this);
  42. }
  43. @Override
  44. public boolean delegateCaptionHandling() {
  45. return false;
  46. }
  47. @Override
  48. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  49. super.onStateChanged(stateChangeEvent);
  50. // Set text
  51. VCaption.setCaptionText(getWidget(), getState());
  52. if (getWidget().icon != null) {
  53. getWidget().getElement().removeChild(getWidget().icon.getElement());
  54. getWidget().icon = null;
  55. }
  56. Icon icon = getIcon();
  57. if (icon != null) {
  58. getWidget().icon = icon;
  59. getWidget().getElement().insertBefore(icon.getElement(),
  60. getWidget().captionElement);
  61. icon.setAlternateText(getState().iconAltText);
  62. }
  63. }
  64. @Override
  65. public VNativeButton getWidget() {
  66. return (VNativeButton) super.getWidget();
  67. }
  68. @Override
  69. public NativeButtonState getState() {
  70. return (NativeButtonState) super.getState();
  71. }
  72. @Override
  73. public void onClick(ClickEvent event) {
  74. if (getState().disableOnClick) {
  75. getState().enabled = false;
  76. super.updateEnabledState(false);
  77. getRpcProxy(ButtonServerRpc.class).disableOnClick();
  78. }
  79. // Add mouse details
  80. MouseEventDetails details = MouseEventDetailsBuilder
  81. .buildMouseEventDetails(event.getNativeEvent(),
  82. getWidget().getElement());
  83. getRpcProxy(ButtonServerRpc.class).click(details);
  84. getWidget().clickPending = false;
  85. }
  86. }