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ů.

VErrorMessage.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2000-2013 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.user.client.DOM;
  18. import com.google.gwt.user.client.Element;
  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. */
  57. public void showAt(Element indicatorElement) {
  58. VOverlay errorContainer = (VOverlay) getParent();
  59. if (errorContainer == null) {
  60. errorContainer = new VOverlay();
  61. errorContainer.setWidget(this);
  62. errorContainer.setOwner(owner);
  63. }
  64. errorContainer.setPopupPosition(
  65. DOM.getAbsoluteLeft(indicatorElement)
  66. + 2
  67. * DOM.getElementPropertyInt(indicatorElement,
  68. "offsetHeight"),
  69. DOM.getAbsoluteTop(indicatorElement)
  70. + 2
  71. * DOM.getElementPropertyInt(indicatorElement,
  72. "offsetHeight"));
  73. errorContainer.show();
  74. }
  75. public void hide() {
  76. final VOverlay errorContainer = (VOverlay) getParent();
  77. if (errorContainer != null) {
  78. errorContainer.hide();
  79. }
  80. }
  81. }