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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2000-2013 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.Util;
  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. if (getWidget().collapseRequest) {
  50. if (getWidget().collapsedRowKey != null
  51. && getWidget().scrollBody != null) {
  52. VScrollTableRow row = getWidget().getRenderedRowByKey(
  53. getWidget().collapsedRowKey);
  54. if (row != null) {
  55. getWidget().setRowFocus(row);
  56. getWidget().focus();
  57. }
  58. }
  59. int scrollPosition2 = widget.getScrollPosition();
  60. if (scrollPosition != scrollPosition2) {
  61. widget.setScrollPosition(scrollPosition);
  62. }
  63. // check which rows are needed from the server and initiate a
  64. // deferred fetch
  65. getWidget().onScroll(null);
  66. }
  67. // Recalculate table size if collapse request, or if page length is zero
  68. // (not sent by server) and row count changes (#7908).
  69. if (getWidget().collapseRequest
  70. || (!uidl.hasAttribute("pagelength") && getWidget()
  71. .getTotalRows() != oldTotalRows)) {
  72. /*
  73. * Ensure that possibly removed/added scrollbars are considered.
  74. * Triggers row calculations, removes cached rows etc. Basically
  75. * cleans up state. Be careful if touching this, you will break
  76. * pageLength=0 if you remove this.
  77. */
  78. getWidget().triggerLazyColumnAdjustment(true);
  79. getWidget().collapseRequest = false;
  80. }
  81. if (uidl.hasAttribute("focusedRow")) {
  82. String key = uidl.getStringAttribute("focusedRow");
  83. getWidget().setRowFocus(getWidget().getRenderedRowByKey(key));
  84. getWidget().focusParentResponsePending = false;
  85. } else if (uidl.hasAttribute("clearFocusPending")) {
  86. // Special case to detect a response to a focusParent request that
  87. // does not return any focusedRow because the selected node has no
  88. // parent
  89. getWidget().focusParentResponsePending = false;
  90. }
  91. while (!getWidget().collapseRequest
  92. && !getWidget().focusParentResponsePending
  93. && !getWidget().pendingNavigationEvents.isEmpty()) {
  94. // Keep replaying any queued events as long as we don't have any
  95. // potential content changes pending
  96. PendingNavigationEvent event = getWidget().pendingNavigationEvents
  97. .removeFirst();
  98. getWidget()
  99. .handleNavigation(event.keycode, event.ctrl, event.shift);
  100. }
  101. }
  102. @Override
  103. public VTreeTable getWidget() {
  104. return (VTreeTable) super.getWidget();
  105. }
  106. @Override
  107. public TreeTableState getState() {
  108. return (TreeTableState) super.getState();
  109. }
  110. @Override
  111. public TooltipInfo getTooltipInfo(Element element) {
  112. TooltipInfo info = null;
  113. if (element != getWidget().getElement()) {
  114. Object node = Util.findWidget(element, VTreeTableRow.class);
  115. if (node != null) {
  116. VTreeTableRow row = (VTreeTableRow) node;
  117. info = row.getTooltip(element);
  118. }
  119. }
  120. if (info == null) {
  121. info = super.getTooltipInfo(element);
  122. }
  123. return info;
  124. }
  125. }