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.

TreeTableConnector.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2000-2014 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.client.ui.treetable;
  17. import com.google.gwt.dom.client.Element;
  18. import com.vaadin.client.ApplicationConnection;
  19. import com.vaadin.client.TooltipInfo;
  20. import com.vaadin.client.UIDL;
  21. import com.vaadin.client.WidgetUtil;
  22. import com.vaadin.client.ui.FocusableScrollPanel;
  23. import com.vaadin.client.ui.VScrollTable.VScrollTableBody.VScrollTableRow;
  24. import com.vaadin.client.ui.VTreeTable;
  25. import com.vaadin.client.ui.VTreeTable.PendingNavigationEvent;
  26. import com.vaadin.client.ui.VTreeTable.VTreeTableScrollBody.VTreeTableRow;
  27. import com.vaadin.client.ui.table.TableConnector;
  28. import com.vaadin.shared.ui.Connect;
  29. import com.vaadin.shared.ui.treetable.TreeTableConstants;
  30. import com.vaadin.shared.ui.treetable.TreeTableState;
  31. import com.vaadin.ui.TreeTable;
  32. @Connect(TreeTable.class)
  33. public class TreeTableConnector extends TableConnector {
  34. @Override
  35. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  36. FocusableScrollPanel widget = null;
  37. int scrollPosition = 0;
  38. if (getWidget().collapseRequest) {
  39. widget = (FocusableScrollPanel) getWidget().getWidget(1);
  40. scrollPosition = widget.getScrollPosition();
  41. }
  42. getWidget().animationsEnabled = uidl.getBooleanAttribute("animate");
  43. getWidget().colIndexOfHierarchy = uidl
  44. .hasAttribute(TreeTableConstants.ATTRIBUTE_HIERARCHY_COLUMN_INDEX) ? uidl
  45. .getIntAttribute(TreeTableConstants.ATTRIBUTE_HIERARCHY_COLUMN_INDEX)
  46. : 0;
  47. int oldTotalRows = getWidget().getTotalRows();
  48. super.updateFromUIDL(uidl, client);
  49. // super.updateFromUIDL set rendering to false, even though we continue
  50. // rendering here. Set it back to true.
  51. getWidget().rendering = true;
  52. if (getWidget().collapseRequest) {
  53. if (getWidget().collapsedRowKey != null
  54. && getWidget().scrollBody != null) {
  55. VScrollTableRow row = getWidget().getRenderedRowByKey(
  56. getWidget().collapsedRowKey);
  57. if (row != null) {
  58. getWidget().setRowFocus(row);
  59. getWidget().focus();
  60. }
  61. }
  62. int scrollPosition2 = widget.getScrollPosition();
  63. if (scrollPosition != scrollPosition2) {
  64. widget.setScrollPosition(scrollPosition);
  65. }
  66. // check which rows are needed from the server and initiate a
  67. // deferred fetch
  68. getWidget().onScroll(null);
  69. }
  70. // Recalculate table size if collapse request, or if page length is zero
  71. // (not sent by server) and row count changes (#7908).
  72. if (getWidget().collapseRequest
  73. || (!uidl.hasAttribute("pagelength") && getWidget()
  74. .getTotalRows() != oldTotalRows)) {
  75. /*
  76. * Ensure that possibly removed/added scrollbars are considered.
  77. * Triggers row calculations, removes cached rows etc. Basically
  78. * cleans up state. Be careful if touching this, you will break
  79. * pageLength=0 if you remove this.
  80. */
  81. getWidget().triggerLazyColumnAdjustment(true);
  82. getWidget().collapseRequest = false;
  83. }
  84. if (uidl.hasAttribute("focusedRow")) {
  85. String key = uidl.getStringAttribute("focusedRow");
  86. getWidget().setRowFocus(getWidget().getRenderedRowByKey(key));
  87. getWidget().focusParentResponsePending = false;
  88. } else if (uidl.hasAttribute("clearFocusPending")) {
  89. // Special case to detect a response to a focusParent request that
  90. // does not return any focusedRow because the selected node has no
  91. // parent
  92. getWidget().focusParentResponsePending = false;
  93. }
  94. while (!getWidget().collapseRequest
  95. && !getWidget().focusParentResponsePending
  96. && !getWidget().pendingNavigationEvents.isEmpty()) {
  97. // Keep replaying any queued events as long as we don't have any
  98. // potential content changes pending
  99. PendingNavigationEvent event = getWidget().pendingNavigationEvents
  100. .removeFirst();
  101. getWidget()
  102. .handleNavigation(event.keycode, event.ctrl, event.shift);
  103. }
  104. getWidget().rendering = false;
  105. }
  106. @Override
  107. public VTreeTable getWidget() {
  108. return (VTreeTable) super.getWidget();
  109. }
  110. @Override
  111. public TreeTableState getState() {
  112. return (TreeTableState) super.getState();
  113. }
  114. @Override
  115. public TooltipInfo getTooltipInfo(Element element) {
  116. TooltipInfo info = null;
  117. if (element != getWidget().getElement()) {
  118. Object node = WidgetUtil.findWidget(element, VTreeTableRow.class);
  119. if (node != null) {
  120. VTreeTableRow row = (VTreeTableRow) node;
  121. info = row.getTooltip(element);
  122. }
  123. }
  124. if (info == null) {
  125. info = super.getTooltipInfo(element);
  126. }
  127. return info;
  128. }
  129. }