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