1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.VScrollTable.VScrollTableBody.VScrollTableRow;
25 import com.vaadin.client.ui.VTreeTable;
26 import com.vaadin.client.ui.VTreeTable.PendingNavigationEvent;
27 import com.vaadin.client.ui.VTreeTable.VTreeTableScrollBody.VTreeTableRow;
28 import com.vaadin.client.ui.table.TableConnector;
29 import com.vaadin.shared.ui.Connect;
30 import com.vaadin.shared.ui.treetable.TreeTableConstants;
31 import com.vaadin.shared.ui.treetable.TreeTableState;
32 import com.vaadin.ui.TreeTable;
33
34 @Connect(TreeTable.class)
35 public class TreeTableConnector extends TableConnector {
36
37 @Override
38 public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
39 FocusableScrollPanel widget = null;
40 int scrollPosition = 0;
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 int scrollPosition2 = widget.getScrollPosition();
64 if (scrollPosition != scrollPosition2) {
65 widget.setScrollPosition(scrollPosition);
66 }
67
68
69
70 getWidget().onScroll(null);
71 }
72
73
74 if (getWidget().collapseRequest
75 || (!uidl.hasAttribute("pagelength") && getWidget()
76 .getTotalRows() != oldTotalRows)) {
77
78
79
80
81
82
83 getWidget().triggerLazyColumnAdjustment(true);
84
85 getWidget().collapseRequest = false;
86 }
87 if (uidl.hasAttribute("focusedRow")) {
88 String key = uidl.getStringAttribute("focusedRow");
89 getWidget().setRowFocus(getWidget().getRenderedRowByKey(key));
90 getWidget().focusParentResponsePending = false;
91 } else if (uidl.hasAttribute("clearFocusPending")) {
92
93
94
95 getWidget().focusParentResponsePending = false;
96 }
97
98 while (!getWidget().collapseRequest
99 && !getWidget().focusParentResponsePending
100 && !getWidget().pendingNavigationEvents.isEmpty()) {
101
102
103 PendingNavigationEvent event = getWidget().pendingNavigationEvents
104 .removeFirst();
105 getWidget()
106 .handleNavigation(event.keycode, event.ctrl, event.shift);
107 }
108 }
109
110 @Override
111 public VTreeTable getWidget() {
112 return (VTreeTable) super.getWidget();
113 }
114
115 @Override
116 public TreeTableState getState() {
117 return (TreeTableState) super.getState();
118 }
119
120 @Override
121 public TooltipInfo getTooltipInfo(Element element) {
122
123 TooltipInfo info = null;
124
125 if (element != getWidget().getElement()) {
126 Object node = Util.findWidget(
127 (com.google.gwt.user.client.Element) element,
128 VTreeTableRow.class);
129
130 if (node != null) {
131 VTreeTableRow row = (VTreeTableRow) node;
132 info = row.getTooltip(element);
133 }
134 }
135
136 if (info == null) {
137 info = super.getTooltipInfo(element);
138 }
139
140 return info;
141 }
142 }