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.

VFormPaintable.java 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.event.dom.client.KeyDownEvent;
  7. import com.google.gwt.user.client.ui.Widget;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. import com.vaadin.terminal.gwt.client.VPaintableMap;
  11. import com.vaadin.terminal.gwt.client.VPaintableWidget;
  12. public class VFormPaintable extends VAbstractPaintableWidgetContainer {
  13. @Override
  14. protected boolean delegateCaptionHandling() {
  15. return false;
  16. }
  17. @Override
  18. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  19. getWidgetForPaintable().rendering = true;
  20. getWidgetForPaintable().client = client;
  21. getWidgetForPaintable().id = uidl.getId();
  22. super.updateFromUIDL(uidl, client);
  23. if (!isRealUpdate(uidl)) {
  24. getWidgetForPaintable().rendering = false;
  25. return;
  26. }
  27. boolean legendEmpty = true;
  28. if (getState().getCaption() != null) {
  29. getWidgetForPaintable().caption.setInnerText(getState()
  30. .getCaption());
  31. legendEmpty = false;
  32. } else {
  33. getWidgetForPaintable().caption.setInnerText("");
  34. }
  35. if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
  36. if (getWidgetForPaintable().icon == null) {
  37. getWidgetForPaintable().icon = new Icon(client);
  38. getWidgetForPaintable().legend
  39. .insertFirst(getWidgetForPaintable().icon.getElement());
  40. }
  41. getWidgetForPaintable().icon.setUri(uidl
  42. .getStringAttribute(ATTRIBUTE_ICON));
  43. legendEmpty = false;
  44. } else {
  45. if (getWidgetForPaintable().icon != null) {
  46. getWidgetForPaintable().legend
  47. .removeChild(getWidgetForPaintable().icon.getElement());
  48. }
  49. }
  50. if (legendEmpty) {
  51. getWidgetForPaintable().addStyleDependentName("nocaption");
  52. } else {
  53. getWidgetForPaintable().removeStyleDependentName("nocaption");
  54. }
  55. if (uidl.hasAttribute("error")) {
  56. final UIDL errorUidl = uidl.getErrors();
  57. getWidgetForPaintable().errorMessage.updateFromUIDL(errorUidl);
  58. getWidgetForPaintable().errorMessage.setVisible(true);
  59. } else {
  60. getWidgetForPaintable().errorMessage.setVisible(false);
  61. }
  62. if (getState().hasDescription()) {
  63. getWidgetForPaintable().desc.setInnerHTML(getState()
  64. .getDescription());
  65. if (getWidgetForPaintable().desc.getParentElement() == null) {
  66. getWidgetForPaintable().fieldSet.insertAfter(
  67. getWidgetForPaintable().desc,
  68. getWidgetForPaintable().legend);
  69. }
  70. } else {
  71. getWidgetForPaintable().desc.setInnerHTML("");
  72. if (getWidgetForPaintable().desc.getParentElement() != null) {
  73. getWidgetForPaintable().fieldSet
  74. .removeChild(getWidgetForPaintable().desc);
  75. }
  76. }
  77. getWidgetForPaintable().updateSize();
  78. // first render footer so it will be easier to handle relative height of
  79. // main layout
  80. if (uidl.getChildCount() > 1
  81. && !uidl.getChildUIDL(1).getTag().equals("actions")) {
  82. // render footer
  83. VPaintableWidget newFooter = client.getPaintable(uidl
  84. .getChildUIDL(1));
  85. Widget newFooterWidget = newFooter.getWidgetForPaintable();
  86. if (getWidgetForPaintable().footer == null) {
  87. getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
  88. getWidgetForPaintable().footerContainer);
  89. getWidgetForPaintable().footer = newFooterWidget;
  90. } else if (newFooter != getWidgetForPaintable().footer) {
  91. getWidgetForPaintable().remove(getWidgetForPaintable().footer);
  92. client.unregisterPaintable(VPaintableMap.get(getConnection())
  93. .getPaintable(getWidgetForPaintable().footer));
  94. getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
  95. getWidgetForPaintable().footerContainer);
  96. }
  97. getWidgetForPaintable().footer = newFooterWidget;
  98. newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);
  99. // needed for the main layout to know the space it has available
  100. getWidgetForPaintable().updateSize();
  101. } else {
  102. if (getWidgetForPaintable().footer != null) {
  103. getWidgetForPaintable().remove(getWidgetForPaintable().footer);
  104. client.unregisterPaintable(VPaintableMap.get(getConnection())
  105. .getPaintable(getWidgetForPaintable().footer));
  106. // needed for the main layout to know the space it has available
  107. getWidgetForPaintable().updateSize();
  108. }
  109. }
  110. final UIDL layoutUidl = uidl.getChildUIDL(0);
  111. VPaintableWidget newLayout = client.getPaintable(layoutUidl);
  112. Widget newLayoutWidget = newLayout.getWidgetForPaintable();
  113. if (getWidgetForPaintable().lo == null) {
  114. // Layout not rendered before
  115. getWidgetForPaintable().lo = newLayoutWidget;
  116. getWidgetForPaintable().add(newLayoutWidget,
  117. getWidgetForPaintable().fieldContainer);
  118. } else if (getWidgetForPaintable().lo != newLayoutWidget) {
  119. // Layout has changed
  120. client.unregisterPaintable(VPaintableMap.get(getConnection())
  121. .getPaintable(getWidgetForPaintable().lo));
  122. getWidgetForPaintable().remove(getWidgetForPaintable().lo);
  123. getWidgetForPaintable().lo = newLayoutWidget;
  124. getWidgetForPaintable().add(newLayoutWidget,
  125. getWidgetForPaintable().fieldContainer);
  126. }
  127. newLayout.updateFromUIDL(layoutUidl, client);
  128. // also recalculates size of the footer if undefined size form - see
  129. // #3710
  130. getWidgetForPaintable().updateSize();
  131. client.runDescendentsLayout(getWidgetForPaintable());
  132. // We may have actions attached
  133. if (uidl.getChildCount() > 1) {
  134. UIDL childUidl = uidl.getChildByTagName("actions");
  135. if (childUidl != null) {
  136. if (getWidgetForPaintable().shortcutHandler == null) {
  137. getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(
  138. getId(), client);
  139. getWidgetForPaintable().keyDownRegistration = getWidgetForPaintable()
  140. .addDomHandler(getWidgetForPaintable(),
  141. KeyDownEvent.getType());
  142. }
  143. getWidgetForPaintable().shortcutHandler
  144. .updateActionMap(childUidl);
  145. }
  146. } else if (getWidgetForPaintable().shortcutHandler != null) {
  147. getWidgetForPaintable().keyDownRegistration.removeHandler();
  148. getWidgetForPaintable().shortcutHandler = null;
  149. getWidgetForPaintable().keyDownRegistration = null;
  150. }
  151. getWidgetForPaintable().rendering = false;
  152. }
  153. public void updateCaption(VPaintableWidget component, UIDL uidl) {
  154. // NOP form don't render caption for neither field layout nor footer
  155. // layout
  156. }
  157. @Override
  158. public VForm getWidgetForPaintable() {
  159. return (VForm) super.getWidgetForPaintable();
  160. }
  161. @Override
  162. protected Widget createWidget() {
  163. return GWT.create(VForm.class);
  164. }
  165. }