Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ButtonConnector.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright 2000-2016 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.button;
  17. import com.google.gwt.event.dom.client.ClickEvent;
  18. import com.google.gwt.event.dom.client.ClickHandler;
  19. import com.google.gwt.user.client.DOM;
  20. import com.vaadin.client.MouseEventDetailsBuilder;
  21. import com.vaadin.client.VCaption;
  22. import com.vaadin.client.annotations.OnStateChange;
  23. import com.vaadin.client.ui.AbstractComponentConnector;
  24. import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
  25. import com.vaadin.client.ui.Icon;
  26. import com.vaadin.client.ui.VButton;
  27. import com.vaadin.shared.MouseEventDetails;
  28. import com.vaadin.shared.ui.Connect;
  29. import com.vaadin.shared.ui.Connect.LoadStyle;
  30. import com.vaadin.shared.ui.button.ButtonServerRpc;
  31. import com.vaadin.shared.ui.button.ButtonState;
  32. import com.vaadin.ui.Button;
  33. @Connect(value = Button.class, loadStyle = LoadStyle.EAGER)
  34. public class ButtonConnector extends AbstractComponentConnector
  35. implements ClickHandler {
  36. @Override
  37. public boolean delegateCaptionHandling() {
  38. return false;
  39. }
  40. @Override
  41. public void init() {
  42. super.init();
  43. getWidget().addClickHandler(this);
  44. getWidget().client = getConnection();
  45. ConnectorFocusAndBlurHandler.addHandlers(this);
  46. }
  47. @OnStateChange("errorMessage")
  48. void setErrorMessage() {
  49. if (null != getState().errorMessage) {
  50. if (getWidget().errorIndicatorElement == null) {
  51. getWidget().errorIndicatorElement = DOM.createSpan();
  52. getWidget().errorIndicatorElement
  53. .setClassName("v-errorindicator");
  54. }
  55. getWidget().wrapper.insertFirst(getWidget().errorIndicatorElement);
  56. } else if (getWidget().errorIndicatorElement != null) {
  57. getWidget().wrapper.removeChild(getWidget().errorIndicatorElement);
  58. getWidget().errorIndicatorElement = null;
  59. }
  60. }
  61. @OnStateChange("resources")
  62. void onResourceChange() {
  63. if (getWidget().icon != null) {
  64. getWidget().wrapper.removeChild(getWidget().icon.getElement());
  65. getWidget().icon = null;
  66. }
  67. Icon icon = getIcon();
  68. if (icon != null) {
  69. getWidget().icon = icon;
  70. icon.setAlternateText(getState().iconAltText);
  71. getWidget().wrapper.insertBefore(icon.getElement(),
  72. getWidget().captionElement);
  73. }
  74. }
  75. @OnStateChange({ "caption", "captionAsHtml" })
  76. void setCaption() {
  77. VCaption.setCaptionText(getWidget().captionElement, getState());
  78. }
  79. @OnStateChange("iconAltText")
  80. void setIconAltText() {
  81. if (getWidget().icon != null) {
  82. getWidget().icon.setAlternateText(getState().iconAltText);
  83. }
  84. }
  85. @OnStateChange("clickShortcutKeyCode")
  86. void setClickShortcut() {
  87. getWidget().clickShortcut = getState().clickShortcutKeyCode;
  88. }
  89. @Override
  90. public VButton getWidget() {
  91. return (VButton) super.getWidget();
  92. }
  93. @Override
  94. public ButtonState getState() {
  95. return (ButtonState) super.getState();
  96. }
  97. @Override
  98. public void onClick(ClickEvent event) {
  99. if (getState().disableOnClick) {
  100. // Simulate getting disabled from the server without waiting for the
  101. // round trip. The server-side RPC handler takes care of updating
  102. // the server-side state in a similar way to ensure subsequent
  103. // changes are properly propagated. Changing state on client is not
  104. // generally supported.
  105. getState().enabled = false;
  106. super.updateEnabledState(false);
  107. getRpcProxy(ButtonServerRpc.class).disableOnClick();
  108. }
  109. // Add mouse details
  110. MouseEventDetails details = MouseEventDetailsBuilder
  111. .buildMouseEventDetails(event.getNativeEvent(),
  112. getWidget().getElement());
  113. getRpcProxy(ButtonServerRpc.class).click(details);
  114. }
  115. @Override
  116. public void onDragSourceAttached() {
  117. // Disable mouse event capturing to make the widget draggable
  118. getWidget().setCapturingEnabled(false);
  119. }
  120. @Override
  121. public void onDragSourceDetached() {
  122. // Reset mouse event capturing
  123. getWidget().setCapturingEnabled(true);
  124. }
  125. }