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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client;
  5. import java.util.Iterator;
  6. import com.google.gwt.user.client.DOM;
  7. import com.google.gwt.user.client.Element;
  8. import com.google.gwt.user.client.ui.FlowPanel;
  9. import com.google.gwt.user.client.ui.HTML;
  10. import com.vaadin.terminal.gwt.client.ui.VOverlay;
  11. public class VErrorMessage extends FlowPanel {
  12. public static final String CLASSNAME = "v-errormessage";
  13. public VErrorMessage() {
  14. super();
  15. setStyleName(CLASSNAME);
  16. }
  17. public void updateFromUIDL(UIDL uidl) {
  18. clear();
  19. if (uidl.getChildCount() == 0) {
  20. add(new HTML(" "));
  21. } else {
  22. for (final Iterator it = uidl.getChildIterator(); it.hasNext();) {
  23. final Object child = it.next();
  24. if (child instanceof String) {
  25. final String errorMessage = (String) child;
  26. add(new HTML(errorMessage));
  27. } else {
  28. try {
  29. final VErrorMessage childError = new VErrorMessage();
  30. childError.updateFromUIDL((UIDL) child);
  31. add(childError);
  32. } catch (Exception e) {
  33. // TODO XML type error, check if this can even happen
  34. // anymore??
  35. final UIDL.XML xml = (UIDL.XML) child;
  36. add(new HTML(xml.getXMLAsString()));
  37. }
  38. }
  39. }
  40. }
  41. }
  42. /**
  43. * Shows this error message next to given element.
  44. *
  45. * @param indicatorElement
  46. */
  47. public void showAt(Element indicatorElement) {
  48. VOverlay errorContainer = (VOverlay) getParent();
  49. if (errorContainer == null) {
  50. errorContainer = new VOverlay();
  51. errorContainer.setWidget(this);
  52. }
  53. errorContainer.setPopupPosition(
  54. DOM.getAbsoluteLeft(indicatorElement)
  55. + 2
  56. * DOM.getElementPropertyInt(indicatorElement,
  57. "offsetHeight"),
  58. DOM.getAbsoluteTop(indicatorElement)
  59. + 2
  60. * DOM.getElementPropertyInt(indicatorElement,
  61. "offsetHeight"));
  62. errorContainer.show();
  63. }
  64. public void hide() {
  65. final VOverlay errorContainer = (VOverlay) getParent();
  66. if (errorContainer != null) {
  67. errorContainer.hide();
  68. }
  69. }
  70. }