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.

VScrollTablePaintable.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.core.client.Scheduler;
  7. import com.google.gwt.dom.client.Style.Position;
  8. import com.google.gwt.user.client.Command;
  9. import com.google.gwt.user.client.ui.Widget;
  10. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  11. import com.vaadin.terminal.gwt.client.BrowserInfo;
  12. import com.vaadin.terminal.gwt.client.UIDL;
  13. import com.vaadin.terminal.gwt.client.Util;
  14. import com.vaadin.terminal.gwt.client.VPaintableWidget;
  15. public class VScrollTablePaintable extends VAbstractPaintableWidgetContainer {
  16. /*
  17. * (non-Javadoc)
  18. *
  19. * @see
  20. * com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal
  21. * .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection)
  22. */
  23. @Override
  24. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  25. getWidgetForPaintable().rendering = true;
  26. if (uidl.hasAttribute(VScrollTable.ATTRIBUTE_PAGEBUFFER_FIRST)) {
  27. getWidgetForPaintable().serverCacheFirst = uidl
  28. .getIntAttribute(VScrollTable.ATTRIBUTE_PAGEBUFFER_FIRST);
  29. getWidgetForPaintable().serverCacheLast = uidl
  30. .getIntAttribute(VScrollTable.ATTRIBUTE_PAGEBUFFER_LAST);
  31. } else {
  32. getWidgetForPaintable().serverCacheFirst = -1;
  33. getWidgetForPaintable().serverCacheLast = -1;
  34. }
  35. /*
  36. * We need to do this before updateComponent since updateComponent calls
  37. * this.setHeight() which will calculate a new body height depending on
  38. * the space available.
  39. */
  40. if (uidl.hasAttribute("colfooters")) {
  41. getWidgetForPaintable().showColFooters = uidl
  42. .getBooleanAttribute("colfooters");
  43. }
  44. getWidgetForPaintable().tFoot
  45. .setVisible(getWidgetForPaintable().showColFooters);
  46. super.updateFromUIDL(uidl, client);
  47. if (!isRealUpdate(uidl)) {
  48. getWidgetForPaintable().rendering = false;
  49. return;
  50. }
  51. getWidgetForPaintable().enabled = !uidl.hasAttribute("disabled");
  52. if (BrowserInfo.get().isIE8() && !getWidgetForPaintable().enabled) {
  53. /*
  54. * The disabled shim will not cover the table body if it is relative
  55. * in IE8. See #7324
  56. */
  57. getWidgetForPaintable().scrollBodyPanel.getElement().getStyle()
  58. .setPosition(Position.STATIC);
  59. } else if (BrowserInfo.get().isIE8()) {
  60. getWidgetForPaintable().scrollBodyPanel.getElement().getStyle()
  61. .setPosition(Position.RELATIVE);
  62. }
  63. getWidgetForPaintable().client = client;
  64. getWidgetForPaintable().paintableId = uidl.getStringAttribute("id");
  65. getWidgetForPaintable().immediate = uidl
  66. .getBooleanAttribute("immediate");
  67. int previousTotalRows = getWidgetForPaintable().totalRows;
  68. getWidgetForPaintable().updateTotalRows(uidl);
  69. boolean totalRowsChanged = (getWidgetForPaintable().totalRows != previousTotalRows);
  70. getWidgetForPaintable().updateDragMode(uidl);
  71. getWidgetForPaintable().updateSelectionProperties(uidl);
  72. if (uidl.hasAttribute("alb")) {
  73. getWidgetForPaintable().bodyActionKeys = uidl
  74. .getStringArrayAttribute("alb");
  75. } else {
  76. // Need to clear the actions if the action handlers have been
  77. // removed
  78. getWidgetForPaintable().bodyActionKeys = null;
  79. }
  80. getWidgetForPaintable().setCacheRateFromUIDL(uidl);
  81. getWidgetForPaintable().recalcWidths = uidl
  82. .hasAttribute("recalcWidths");
  83. if (getWidgetForPaintable().recalcWidths) {
  84. getWidgetForPaintable().tHead.clear();
  85. getWidgetForPaintable().tFoot.clear();
  86. }
  87. getWidgetForPaintable().updatePageLength(uidl);
  88. getWidgetForPaintable().updateFirstVisibleAndScrollIfNeeded(uidl);
  89. getWidgetForPaintable().showRowHeaders = uidl
  90. .getBooleanAttribute("rowheaders");
  91. getWidgetForPaintable().showColHeaders = uidl
  92. .getBooleanAttribute("colheaders");
  93. getWidgetForPaintable().updateSortingProperties(uidl);
  94. boolean keyboardSelectionOverRowFetchInProgress = getWidgetForPaintable()
  95. .selectSelectedRows(uidl);
  96. getWidgetForPaintable().updateActionMap(uidl);
  97. getWidgetForPaintable().updateColumnProperties(uidl);
  98. UIDL ac = uidl.getChildByTagName("-ac");
  99. if (ac == null) {
  100. if (getWidgetForPaintable().dropHandler != null) {
  101. // remove dropHandler if not present anymore
  102. getWidgetForPaintable().dropHandler = null;
  103. }
  104. } else {
  105. if (getWidgetForPaintable().dropHandler == null) {
  106. getWidgetForPaintable().dropHandler = getWidgetForPaintable().new VScrollTableDropHandler();
  107. }
  108. getWidgetForPaintable().dropHandler.updateAcceptRules(ac);
  109. }
  110. UIDL partialRowAdditions = uidl.getChildByTagName("prows");
  111. UIDL partialRowUpdates = uidl.getChildByTagName("urows");
  112. if (partialRowUpdates != null || partialRowAdditions != null) {
  113. // we may have pending cache row fetch, cancel it. See #2136
  114. getWidgetForPaintable().rowRequestHandler.cancel();
  115. getWidgetForPaintable().updateRowsInBody(partialRowUpdates);
  116. getWidgetForPaintable().addAndRemoveRows(partialRowAdditions);
  117. } else {
  118. UIDL rowData = uidl.getChildByTagName("rows");
  119. if (rowData != null) {
  120. // we may have pending cache row fetch, cancel it. See #2136
  121. getWidgetForPaintable().rowRequestHandler.cancel();
  122. if (!getWidgetForPaintable().recalcWidths
  123. && getWidgetForPaintable().initializedAndAttached) {
  124. getWidgetForPaintable().updateBody(rowData,
  125. uidl.getIntAttribute("firstrow"),
  126. uidl.getIntAttribute("rows"));
  127. if (getWidgetForPaintable().headerChangedDuringUpdate) {
  128. getWidgetForPaintable().triggerLazyColumnAdjustment(
  129. true);
  130. } else if (!getWidgetForPaintable()
  131. .isScrollPositionVisible()
  132. || totalRowsChanged
  133. || getWidgetForPaintable().lastRenderedHeight != getWidgetForPaintable().scrollBody
  134. .getOffsetHeight()) {
  135. // webkits may still bug with their disturbing scrollbar
  136. // bug, see #3457
  137. // Run overflow fix for the scrollable area
  138. // #6698 - If there's a scroll going on, don't abort it
  139. // by changing overflows as the length of the contents
  140. // *shouldn't* have changed (unless the number of rows
  141. // or the height of the widget has also changed)
  142. Scheduler.get().scheduleDeferred(new Command() {
  143. public void execute() {
  144. Util.runWebkitOverflowAutoFix(getWidgetForPaintable().scrollBodyPanel
  145. .getElement());
  146. }
  147. });
  148. }
  149. } else {
  150. getWidgetForPaintable().initializeRows(uidl, rowData);
  151. }
  152. }
  153. }
  154. if (!getWidgetForPaintable().isSelectable()) {
  155. getWidgetForPaintable().scrollBody
  156. .addStyleName(VScrollTable.CLASSNAME + "-body-noselection");
  157. } else {
  158. getWidgetForPaintable().scrollBody
  159. .removeStyleName(VScrollTable.CLASSNAME
  160. + "-body-noselection");
  161. }
  162. getWidgetForPaintable().hideScrollPositionAnnotation();
  163. getWidgetForPaintable().purgeUnregistryBag();
  164. // selection is no in sync with server, avoid excessive server visits by
  165. // clearing to flag used during the normal operation
  166. if (!keyboardSelectionOverRowFetchInProgress) {
  167. getWidgetForPaintable().selectionChanged = false;
  168. }
  169. /*
  170. * This is called when the Home or page up button has been pressed in
  171. * selectable mode and the next selected row was not yet rendered in the
  172. * client
  173. */
  174. if (getWidgetForPaintable().selectFirstItemInNextRender
  175. || getWidgetForPaintable().focusFirstItemInNextRender) {
  176. getWidgetForPaintable().selectFirstRenderedRowInViewPort(
  177. getWidgetForPaintable().focusFirstItemInNextRender);
  178. getWidgetForPaintable().selectFirstItemInNextRender = getWidgetForPaintable().focusFirstItemInNextRender = false;
  179. }
  180. /*
  181. * This is called when the page down or end button has been pressed in
  182. * selectable mode and the next selected row was not yet rendered in the
  183. * client
  184. */
  185. if (getWidgetForPaintable().selectLastItemInNextRender
  186. || getWidgetForPaintable().focusLastItemInNextRender) {
  187. getWidgetForPaintable().selectLastRenderedRowInViewPort(
  188. getWidgetForPaintable().focusLastItemInNextRender);
  189. getWidgetForPaintable().selectLastItemInNextRender = getWidgetForPaintable().focusLastItemInNextRender = false;
  190. }
  191. getWidgetForPaintable().multiselectPending = false;
  192. if (getWidgetForPaintable().focusedRow != null) {
  193. if (!getWidgetForPaintable().focusedRow.isAttached()
  194. && !getWidgetForPaintable().rowRequestHandler.isRunning()) {
  195. // focused row has been orphaned, can't focus
  196. getWidgetForPaintable().focusRowFromBody();
  197. }
  198. }
  199. getWidgetForPaintable().tabIndex = uidl.hasAttribute("tabindex") ? uidl
  200. .getIntAttribute("tabindex") : 0;
  201. getWidgetForPaintable().setProperTabIndex();
  202. getWidgetForPaintable().resizeSortedColumnForSortIndicator();
  203. // Remember this to detect situations where overflow hack might be
  204. // needed during scrolling
  205. getWidgetForPaintable().lastRenderedHeight = getWidgetForPaintable().scrollBody
  206. .getOffsetHeight();
  207. getWidgetForPaintable().rendering = false;
  208. getWidgetForPaintable().headerChangedDuringUpdate = false;
  209. }
  210. @Override
  211. protected Widget createWidget() {
  212. return GWT.create(VScrollTable.class);
  213. }
  214. @Override
  215. public VScrollTable getWidgetForPaintable() {
  216. return (VScrollTable) super.getWidgetForPaintable();
  217. }
  218. public void updateCaption(VPaintableWidget component, UIDL uidl) {
  219. // NOP, not rendered
  220. }
  221. }