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.

VErrorMessage.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.user.client.DOM;
  19. import com.google.gwt.user.client.ui.FlowPanel;
  20. import com.google.gwt.user.client.ui.HTML;
  21. import com.google.gwt.user.client.ui.Widget;
  22. import com.vaadin.client.ui.VOverlay;
  23. public class VErrorMessage extends FlowPanel {
  24. public static final String CLASSNAME = "v-errormessage";
  25. private Widget owner;
  26. public VErrorMessage() {
  27. super();
  28. setStyleName(CLASSNAME);
  29. }
  30. /**
  31. * Set the owner, i.e the Widget that created this {@link VErrorMessage}.
  32. * The owner must be set if the {@link VErrorMessage} is created
  33. * 'stand-alone' (not within a {@link VOverlay}), or theming might not work
  34. * properly.
  35. *
  36. * @see VOverlay#setOwner(Widget)
  37. * @param owner
  38. * the owner (creator Widget)
  39. */
  40. public void setOwner(Widget owner) {
  41. this.owner = owner;
  42. }
  43. public void updateMessage(String htmlErrorMessage) {
  44. clear();
  45. if (htmlErrorMessage == null || htmlErrorMessage.length() == 0) {
  46. add(new HTML(" "));
  47. } else {
  48. // pre-formatted on the server as div per child
  49. add(new HTML(htmlErrorMessage));
  50. }
  51. }
  52. /**
  53. * Shows this error message next to given element.
  54. *
  55. * @param indicatorElement
  56. * @deprecated As of 7.2, call and override {@link #showAt(Element)} instead
  57. */
  58. @Deprecated
  59. public void showAt(com.google.gwt.user.client.Element indicatorElement) {
  60. VOverlay errorContainer = (VOverlay) getParent();
  61. if (errorContainer == null) {
  62. errorContainer = new VOverlay();
  63. errorContainer.setWidget(this);
  64. errorContainer.setOwner(owner);
  65. }
  66. errorContainer.setPopupPosition(
  67. DOM.getAbsoluteLeft(indicatorElement)
  68. + 2 * DOM.getElementPropertyInt(indicatorElement,
  69. "offsetHeight"),
  70. DOM.getAbsoluteTop(indicatorElement)
  71. + 2 * DOM.getElementPropertyInt(indicatorElement,
  72. "offsetHeight"));
  73. errorContainer.show();
  74. }
  75. /**
  76. * Shows this error message next to given element.
  77. *
  78. * @param indicatorElement
  79. *
  80. * @since 7.2
  81. */
  82. public void showAt(Element indicatorElement) {
  83. showAt(DOM.asOld(indicatorElement));
  84. }
  85. public void hide() {
  86. final VOverlay errorContainer = (VOverlay) getParent();
  87. if (errorContainer != null) {
  88. errorContainer.hide();
  89. }
  90. }
  91. }