| 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'; |
| 72 _expander.style.display = 'inline-block'; |
| 70 _expander.style.minWidth = '1.5em'; | 73 _expander.style.minWidth = '1.5em'; |
| 71 _expander.onClick.listen(onClick); | 74 _expander.onClick.listen(onClick); |
| 72 firstColumn.children.add(_expander); | 75 columnContainer.children.add(_expander); |
| 73 firstColumn.style.paddingLeft = '${depth * subtreeIndent}px'; | 76 firstColumn.style.paddingLeft = '${depth * subtreeIndent}px'; |
| 77 firstColumn.children.add(columnContainer); |
| 74 updateExpanderView(); | 78 updateExpanderView(); |
| 75 } | 79 } |
| 76 | 80 |
| 77 void updateExpanderView() { | 81 void updateExpanderView() { |
| 78 if (_expander == null) { | 82 if (_expander == null) { |
| 79 return; | 83 return; |
| 80 } | 84 } |
| 81 if (!hasChildren()) { | 85 if (!hasChildren()) { |
| 82 _expander.style.visibility = 'hidden'; | 86 _expander.style.visibility = 'hidden'; |
| 83 _expander.style.cursor = 'auto'; | 87 _expander.style.cursor = 'auto'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 132 } |
| 129 | 133 |
| 130 class TableTree extends Observable { | 134 class TableTree extends Observable { |
| 131 final TableSectionElement tableBody; | 135 final TableSectionElement tableBody; |
| 132 final List<TableTreeRow> rows = []; | 136 final List<TableTreeRow> rows = []; |
| 133 final int columnCount; | 137 final int columnCount; |
| 134 | 138 |
| 135 /// Create a table tree with column [headers]. | 139 /// Create a table tree with column [headers]. |
| 136 TableTree(this.tableBody, this.columnCount); | 140 TableTree(this.tableBody, this.columnCount); |
| 137 | 141 |
| 142 void clear() { |
| 143 tableBody.children.clear(); |
| 144 rows.clear(); |
| 145 } |
| 146 |
| 138 /// Initialize the table tree with the list of root children. | 147 /// Initialize the table tree with the list of root children. |
| 139 void initialize(TableTreeRow root) { | 148 void initialize(TableTreeRow root) { |
| 140 tableBody.children.clear(); | 149 clear(); |
| 141 rows.clear(); | |
| 142 root.onShow(); | 150 root.onShow(); |
| 143 rows.addAll(root.children); | 151 rows.addAll(root.children); |
| 144 for (var i = 0; i < rows.length; i++) { | 152 for (var i = 0; i < rows.length; i++) { |
| 145 rows[i].onShow(); | 153 rows[i].onShow(); |
| 146 tableBody.children.add(rows[i].tr); | 154 tableBody.children.add(rows[i].tr); |
| 147 } | 155 } |
| 148 } | 156 } |
| 149 | 157 |
| 150 /// Toggle expansion of row in tree. | 158 /// Toggle expansion of row in tree. |
| 151 void toggle(TableTreeRow row) { | 159 void toggle(TableTreeRow row) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return b.compareTo(a); | 248 return b.compareTo(a); |
| 241 } | 249 } |
| 242 | 250 |
| 243 int _sortFuncAscending(int i, int j) { | 251 int _sortFuncAscending(int i, int j) { |
| 244 var a = getSortKeyFor(i, _sortColumnIndex); | 252 var a = getSortKeyFor(i, _sortColumnIndex); |
| 245 var b = getSortKeyFor(j, _sortColumnIndex); | 253 var b = getSortKeyFor(j, _sortColumnIndex); |
| 246 return a.compareTo(b); | 254 return a.compareTo(b); |
| 247 } | 255 } |
| 248 | 256 |
| 249 void sort() { | 257 void sort() { |
| 250 Stopwatch sw = new Stopwatch()..start(); | |
| 251 assert(_sortColumnIndex >= 0); | 258 assert(_sortColumnIndex >= 0); |
| 252 assert(_sortColumnIndex < columns.length); | 259 assert(_sortColumnIndex < columns.length); |
| 253 if (_sortDescending) { | 260 if (_sortDescending) { |
| 254 sortedRows.sort(_sortFuncDescending); | 261 sortedRows.sort(_sortFuncDescending); |
| 255 } else { | 262 } else { |
| 256 sortedRows.sort(_sortFuncAscending); | 263 sortedRows.sort(_sortFuncAscending); |
| 257 } | 264 } |
| 258 } | 265 } |
| 259 | 266 |
| 260 void clearRows() { | 267 void clearRows() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 283 if (column != _sortColumnIndex) { | 290 if (column != _sortColumnIndex) { |
| 284 return columns[column].label + '\u2003'; | 291 return columns[column].label + '\u2003'; |
| 285 } | 292 } |
| 286 return columns[column].label + (_sortDescending ? arrowUp : arrowDown); | 293 return columns[column].label + (_sortDescending ? arrowUp : arrowDown); |
| 287 } | 294 } |
| 288 | 295 |
| 289 dynamic getValue(int row, int column) { | 296 dynamic getValue(int row, int column) { |
| 290 return rows[row].values[column]; | 297 return rows[row].values[column]; |
| 291 } | 298 } |
| 292 } | 299 } |
| OLD | NEW |