| 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 library class_tree_element; | 5 library class_tree_element; |
| 6 | 6 |
| 7 import 'observatory_element.dart'; | 7 import 'observatory_element.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'package:logging/logging.dart'; | 9 import 'package:logging/logging.dart'; |
| 10 import 'package:observatory/app.dart'; | 10 import 'package:observatory/app.dart'; |
| 11 import 'package:observatory/service.dart'; | 11 import 'package:observatory/service.dart'; |
| 12 import 'package:polymer/polymer.dart'; | 12 import 'package:polymer/polymer.dart'; |
| 13 | 13 |
| 14 class ClassTreeRow extends TableTreeRow { | 14 class ClassTreeRow extends TableTreeRow { |
| 15 @reflectable final Isolate isolate; | 15 @reflectable final Isolate isolate; |
| 16 @reflectable final Class cls; | 16 @reflectable final Class cls; |
| 17 ClassTreeRow(this.isolate, this.cls, ClassTreeRow parent) : super(parent) { | 17 ClassTreeRow(this.isolate, this.cls, TableTree tree, ClassTreeRow parent) |
| 18 : super(tree, parent) { |
| 18 assert(isolate != null); | 19 assert(isolate != null); |
| 19 assert(cls != null); | 20 assert(cls != null); |
| 20 } | 21 } |
| 21 | 22 |
| 22 void onShow() { | 23 void onShow() { |
| 23 if (children.length > 0) { | 24 super.onShow(); |
| 24 // Child rows already created. | 25 if (children.length == 0) { |
| 25 return; | 26 for (var subclass in cls.subclasses) { |
| 27 if (subclass.isPatch) { |
| 28 continue; |
| 29 } |
| 30 var row = new ClassTreeRow(isolate, subclass, tree, this); |
| 31 children.add(row); |
| 32 } |
| 26 } | 33 } |
| 27 for (var subclass in cls.subclasses) { | 34 var classCell = tableColumns[0]; |
| 28 if (subclass.isPatch) { | 35 // Enable expansion by clicking anywhere on the class column. |
| 29 continue; | 36 classCell.onClick.listen(onClick); |
| 30 } | |
| 31 var row = new ClassTreeRow(isolate, subclass, this); | |
| 32 children.add(row); | |
| 33 } | |
| 34 } | |
| 35 | 37 |
| 36 void onHide() { | 38 var classRef = new Element.tag('class-ref'); |
| 39 classRef.ref = cls; |
| 40 classCell.children.add(classRef); |
| 37 } | 41 } |
| 38 | 42 |
| 39 bool hasChildren() { | 43 bool hasChildren() { |
| 40 return cls.subclasses.length > 0; | 44 return cls.subclasses.length > 0; |
| 41 } | 45 } |
| 42 } | 46 } |
| 43 | 47 |
| 44 | 48 |
| 45 @CustomTag('class-tree') | 49 @CustomTag('class-tree') |
| 46 class ClassTreeElement extends ObservatoryElement { | 50 class ClassTreeElement extends ObservatoryElement { |
| 47 @observable Isolate isolate; | 51 @observable Isolate isolate; |
| 48 | 52 |
| 49 TableTree tree; | 53 TableTree tree; |
| 50 | 54 |
| 51 ClassTreeElement.created() : super.created(); | 55 ClassTreeElement.created() : super.created(); |
| 52 | 56 |
| 53 @override | 57 @override |
| 54 void attached() { | 58 void attached() { |
| 55 super.attached(); | 59 super.attached(); |
| 56 tree = new TableTree(); | 60 var tableBody = shadowRoot.querySelector('#tableTreeBody'); |
| 61 assert(tableBody != null); |
| 62 tree = new TableTree(tableBody, 1); |
| 57 if (isolate != null) { | 63 if (isolate != null) { |
| 58 _update(isolate.objectClass); | 64 _update(isolate.objectClass); |
| 59 } | 65 } |
| 60 } | 66 } |
| 61 | 67 |
| 62 isolateChanged(oldValue) { | 68 isolateChanged(oldValue) { |
| 63 isolate.getClassHierarchy().then((objectClass) { | 69 isolate.getClassHierarchy().then((objectClass) { |
| 64 _update(objectClass); | 70 _update(objectClass); |
| 65 }); | 71 }); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void _update(Class root) { | 74 void _update(Class root) { |
| 69 try { | 75 try { |
| 70 var rootRow = new ClassTreeRow(isolate, root, null); | 76 var rootRow = new ClassTreeRow(isolate, root, tree, null); |
| 71 rootRow.children.add(new ClassTreeRow(isolate, root, rootRow)); | 77 rootRow.children.add(new ClassTreeRow(isolate, root, tree, rootRow)); |
| 72 tree.initialize(rootRow); | 78 tree.initialize(rootRow); |
| 73 } catch (e, stackTrace) { | 79 } catch (e, stackTrace) { |
| 74 Logger.root.warning('_update', e, stackTrace); | 80 Logger.root.warning('_update', e, stackTrace); |
| 75 } | 81 } |
| 76 // Check if we only have one node at the root and expand it. | 82 // Check if we only have one node at the root and expand it. |
| 77 if (tree.rows.length == 1) { | 83 if (tree.rows.length == 1) { |
| 78 tree.toggle(0); | 84 tree.toggle(tree.rows[0]); |
| 79 } | 85 } |
| 80 notifyPropertyChange(#tree, null, tree); | 86 notifyPropertyChange(#tree, null, tree); |
| 81 } | 87 } |
| 82 | |
| 83 @observable String padding(TableTreeRow row) { | |
| 84 return 'padding-left: ${row.depth * 16}px;'; | |
| 85 } | |
| 86 | |
| 87 @observable String coloring(TableTreeRow row) { | |
| 88 const colors = const ['rowColor0', 'rowColor1', 'rowColor2', 'rowColor3', | |
| 89 'rowColor4', 'rowColor5', 'rowColor6', 'rowColor7', | |
| 90 'rowColor8']; | |
| 91 var index = (row.depth - 1) % colors.length; | |
| 92 return colors[index]; | |
| 93 } | |
| 94 | |
| 95 @observable void toggleExpanded(Event e, var detail, Element target) { | |
| 96 // We only want to expand a tree row if the target of the click is | |
| 97 // the table cell (passed in as target) or the span containing the | |
| 98 // expander symbol (#expand). | |
| 99 var eventTarget = e.target; | |
| 100 if ((eventTarget.id != 'expand') && (e.target != target)) { | |
| 101 // Target of click was not the expander span or the table cell. | |
| 102 return; | |
| 103 } | |
| 104 var row = target.parent; | |
| 105 if (row is TableRowElement) { | |
| 106 try { | |
| 107 // Subtract 1 to get 0 based indexing. | |
| 108 tree.toggle(row.rowIndex - 1); | |
| 109 } catch (e, stackTrace) { | |
| 110 Logger.root.warning('toggleExpanded', e, stackTrace); | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 } | 88 } |
| OLD | NEW |