OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of app; | 5 part of app; |
6 | 6 |
7 abstract class TableTreeRow extends Observable { | 7 abstract class TableTreeRow extends Observable { |
8 static const arrowRight = '\u2192'; | 8 static const arrowRight = '\u2192'; |
9 static const arrowDownRight = '\u21b3'; | 9 static const arrowDownRight = '\u21b3'; |
10 // Number of pixels each subtree is indented. | 10 // Number of pixels each subtree is indented. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 void _buildRow() { | 60 void _buildRow() { |
61 _tr = new TableRowElement(); | 61 _tr = new TableRowElement(); |
62 for (var i = 0; i < tree.columnCount; i++) { | 62 for (var i = 0; i < tree.columnCount; i++) { |
63 var cell = _tr.insertCell(-1); | 63 var cell = _tr.insertCell(-1); |
64 cell.classes.add(_backgroundColorClassForRow()); | 64 cell.classes.add(_backgroundColorClassForRow()); |
65 tableColumns.add(cell); | 65 tableColumns.add(cell); |
66 } | 66 } |
67 var firstColumn = tableColumns[0]; | 67 var firstColumn = tableColumns[0]; |
| 68 var columnContainer = new DivElement(); |
| 69 columnContainer.classes.add('flex-row'); |
68 _expander = new SpanElement(); | 70 _expander = new SpanElement(); |
69 _expander.style.display = 'inline-block'; | 71 _expander.style.display = 'inline-block'; |
70 _expander.style.minWidth = '1.5em'; | 72 _expander.style.minWidth = '1.5em'; |
71 _expander.onClick.listen(onClick); | 73 _expander.onClick.listen(onClick); |
72 firstColumn.children.add(_expander); | 74 columnContainer.children.add(_expander); |
73 firstColumn.style.paddingLeft = '${depth * subtreeIndent}px'; | 75 firstColumn.style.paddingLeft = '${depth * subtreeIndent}px'; |
| 76 firstColumn.children.add(columnContainer); |
74 updateExpanderView(); | 77 updateExpanderView(); |
75 } | 78 } |
76 | 79 |
77 void updateExpanderView() { | 80 void updateExpanderView() { |
78 if (_expander == null) { | 81 if (_expander == null) { |
79 return; | 82 return; |
80 } | 83 } |
81 if (!hasChildren()) { | 84 if (!hasChildren()) { |
82 _expander.style.visibility = 'hidden'; | 85 _expander.style.visibility = 'hidden'; |
83 _expander.style.cursor = 'auto'; | 86 _expander.style.cursor = 'auto'; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 131 } |
129 | 132 |
130 class TableTree extends Observable { | 133 class TableTree extends Observable { |
131 final TableSectionElement tableBody; | 134 final TableSectionElement tableBody; |
132 final List<TableTreeRow> rows = []; | 135 final List<TableTreeRow> rows = []; |
133 final int columnCount; | 136 final int columnCount; |
134 | 137 |
135 /// Create a table tree with column [headers]. | 138 /// Create a table tree with column [headers]. |
136 TableTree(this.tableBody, this.columnCount); | 139 TableTree(this.tableBody, this.columnCount); |
137 | 140 |
| 141 void clear() { |
| 142 tableBody.children.clear(); |
| 143 rows.clear(); |
| 144 } |
| 145 |
138 /// Initialize the table tree with the list of root children. | 146 /// Initialize the table tree with the list of root children. |
139 void initialize(TableTreeRow root) { | 147 void initialize(TableTreeRow root) { |
140 tableBody.children.clear(); | 148 clear(); |
141 rows.clear(); | |
142 root.onShow(); | 149 root.onShow(); |
143 rows.addAll(root.children); | 150 rows.addAll(root.children); |
144 for (var i = 0; i < rows.length; i++) { | 151 for (var i = 0; i < rows.length; i++) { |
145 rows[i].onShow(); | 152 rows[i].onShow(); |
146 tableBody.children.add(rows[i].tr); | 153 tableBody.children.add(rows[i].tr); |
147 } | 154 } |
148 } | 155 } |
149 | 156 |
150 /// Toggle expansion of row in tree. | 157 /// Toggle expansion of row in tree. |
151 void toggle(TableTreeRow row) { | 158 void toggle(TableTreeRow row) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return b.compareTo(a); | 247 return b.compareTo(a); |
241 } | 248 } |
242 | 249 |
243 int _sortFuncAscending(int i, int j) { | 250 int _sortFuncAscending(int i, int j) { |
244 var a = getSortKeyFor(i, _sortColumnIndex); | 251 var a = getSortKeyFor(i, _sortColumnIndex); |
245 var b = getSortKeyFor(j, _sortColumnIndex); | 252 var b = getSortKeyFor(j, _sortColumnIndex); |
246 return a.compareTo(b); | 253 return a.compareTo(b); |
247 } | 254 } |
248 | 255 |
249 void sort() { | 256 void sort() { |
250 Stopwatch sw = new Stopwatch()..start(); | |
251 assert(_sortColumnIndex >= 0); | 257 assert(_sortColumnIndex >= 0); |
252 assert(_sortColumnIndex < columns.length); | 258 assert(_sortColumnIndex < columns.length); |
253 if (_sortDescending) { | 259 if (_sortDescending) { |
254 sortedRows.sort(_sortFuncDescending); | 260 sortedRows.sort(_sortFuncDescending); |
255 } else { | 261 } else { |
256 sortedRows.sort(_sortFuncAscending); | 262 sortedRows.sort(_sortFuncAscending); |
257 } | 263 } |
258 } | 264 } |
259 | 265 |
260 void clearRows() { | 266 void clearRows() { |
(...skipping 22 matching lines...) Expand all Loading... |
283 if (column != _sortColumnIndex) { | 289 if (column != _sortColumnIndex) { |
284 return columns[column].label + '\u2003'; | 290 return columns[column].label + '\u2003'; |
285 } | 291 } |
286 return columns[column].label + (_sortDescending ? arrowUp : arrowDown); | 292 return columns[column].label + (_sortDescending ? arrowUp : arrowDown); |
287 } | 293 } |
288 | 294 |
289 dynamic getValue(int row, int column) { | 295 dynamic getValue(int row, int column) { |
290 return rows[row].values[column]; | 296 return rows[row].values[column]; |
291 } | 297 } |
292 } | 298 } |
OLD | NEW |