Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VErrorMessage.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.VToolkitOverlay;
  11. public class VErrorMessage extends FlowPanel {
  12. public static final String CLASSNAME = "i-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 if (child instanceof UIDL.XML) {
  28. final UIDL.XML xml = (UIDL.XML) child;
  29. add(new HTML(xml.getXMLAsString()));
  30. } else {
  31. final VErrorMessage childError = new VErrorMessage();
  32. add(childError);
  33. childError.updateFromUIDL((UIDL) child);
  34. }
  35. }
  36. }
  37. }
  38. /**
  39. * Shows this error message next to given element.
  40. *
  41. * @param indicatorElement
  42. */
  43. public void showAt(Element indicatorElement) {
  44. VToolkitOverlay errorContainer = (VToolkitOverlay) getParent();
  45. if (errorContainer == null) {
  46. errorContainer = new VToolkitOverlay();
  47. errorContainer.setWidget(this);
  48. }
  49. errorContainer.setPopupPosition(DOM.getAbsoluteLeft(indicatorElement)
  50. + 2
  51. * DOM.getElementPropertyInt(indicatorElement, "offsetHeight"),
  52. DOM.getAbsoluteTop(indicatorElement)
  53. + 2
  54. * DOM.getElementPropertyInt(indicatorElement,
  55. "offsetHeight"));
  56. errorContainer.show();
  57. }
  58. public void hide() {
  59. final VToolkitOverlay errorContainer = (VToolkitOverlay) getParent();
  60. if (errorContainer != null) {
  61. errorContainer.hide();
  62. }
  63. }
  64. }