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 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2011 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.terminal.gwt.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.vaadin.terminal.gwt.client.ui.VOverlay;
  22. public class VErrorMessage extends FlowPanel {
  23. public static final String CLASSNAME = "v-errormessage";
  24. public VErrorMessage() {
  25. super();
  26. setStyleName(CLASSNAME);
  27. }
  28. public void updateMessage(String htmlErrorMessage) {
  29. clear();
  30. if (htmlErrorMessage == null || htmlErrorMessage.length() == 0) {
  31. add(new HTML(" "));
  32. } else {
  33. // pre-formatted on the server as div per child
  34. add(new HTML(htmlErrorMessage));
  35. }
  36. }
  37. /**
  38. * Shows this error message next to given element.
  39. *
  40. * @param indicatorElement
  41. */
  42. public void showAt(Element indicatorElement) {
  43. VOverlay errorContainer = (VOverlay) getParent();
  44. if (errorContainer == null) {
  45. errorContainer = new VOverlay();
  46. errorContainer.setWidget(this);
  47. }
  48. errorContainer.setPopupPosition(
  49. DOM.getAbsoluteLeft(indicatorElement)
  50. + 2
  51. * DOM.getElementPropertyInt(indicatorElement,
  52. "offsetHeight"),
  53. DOM.getAbsoluteTop(indicatorElement)
  54. + 2
  55. * DOM.getElementPropertyInt(indicatorElement,
  56. "offsetHeight"));
  57. errorContainer.show();
  58. }
  59. public void hide() {
  60. final VOverlay errorContainer = (VOverlay) getParent();
  61. if (errorContainer != null) {
  62. errorContainer.hide();
  63. }
  64. }
  65. }