Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VCheckBox.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2000-2014 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;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.event.dom.client.ClickEvent;
  19. import com.google.gwt.event.dom.client.ClickHandler;
  20. import com.google.gwt.user.client.DOM;
  21. import com.google.gwt.user.client.Event;
  22. import com.vaadin.client.ApplicationConnection;
  23. import com.vaadin.client.BrowserInfo;
  24. import com.vaadin.client.Util;
  25. import com.vaadin.client.VTooltip;
  26. import com.vaadin.client.ui.aria.AriaHelper;
  27. import com.vaadin.client.ui.aria.HandlesAriaInvalid;
  28. import com.vaadin.client.ui.aria.HandlesAriaRequired;
  29. public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
  30. Field, HandlesAriaInvalid, HandlesAriaRequired {
  31. public static final String CLASSNAME = "v-checkbox";
  32. /** For internal use only. May be removed or replaced in the future. */
  33. public String id;
  34. /** For internal use only. May be removed or replaced in the future. */
  35. public boolean immediate;
  36. /** For internal use only. May be removed or replaced in the future. */
  37. public ApplicationConnection client;
  38. /** For internal use only. May be removed or replaced in the future. */
  39. public Element errorIndicatorElement;
  40. /** For internal use only. May be removed or replaced in the future. */
  41. public Icon icon;
  42. public VCheckBox() {
  43. setStyleName(CLASSNAME);
  44. Element el = DOM.getFirstChild(getElement());
  45. while (el != null) {
  46. DOM.sinkEvents(el,
  47. (DOM.getEventsSunk(el) | VTooltip.TOOLTIP_EVENTS));
  48. el = DOM.getNextSibling(el);
  49. }
  50. if (BrowserInfo.get().isWebkit()) {
  51. // Webkit does not focus non-text input elements on click
  52. // (#11854)
  53. addClickHandler(new ClickHandler() {
  54. @Override
  55. public void onClick(ClickEvent event) {
  56. setFocus(true);
  57. }
  58. });
  59. }
  60. }
  61. @Override
  62. public void onBrowserEvent(Event event) {
  63. if (icon != null && (event.getTypeInt() == Event.ONCLICK)
  64. && (DOM.eventGetTarget(event) == icon.getElement())) {
  65. // Click on icon should do nothing if widget is disabled
  66. if (isEnabled()) {
  67. setValue(!getValue());
  68. }
  69. }
  70. super.onBrowserEvent(event);
  71. if (event.getTypeInt() == Event.ONLOAD) {
  72. Util.notifyParentOfSizeChange(this, true);
  73. }
  74. }
  75. /**
  76. * Gives access to the input element.
  77. *
  78. * @return Element of the CheckBox itself
  79. */
  80. private Element getCheckBoxElement() {
  81. // FIXME: Would love to use a better way to access the checkbox element
  82. return getElement().getFirstChildElement();
  83. }
  84. @Override
  85. public void setAriaRequired(boolean required) {
  86. AriaHelper.handleInputRequired(getCheckBoxElement(), required);
  87. }
  88. @Override
  89. public void setAriaInvalid(boolean invalid) {
  90. AriaHelper.handleInputInvalid(getCheckBoxElement(), invalid);
  91. }
  92. }