| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library class_tree_element; | |
| 6 | |
| 7 import 'observatory_element.dart'; | |
| 8 import 'dart:html'; | |
| 9 import 'package:logging/logging.dart'; | |
| 10 import 'package:observatory/app.dart'; | |
| 11 import 'package:observatory/service.dart'; | |
| 12 import 'package:polymer/polymer.dart'; | |
| 13 | |
| 14 class ClassTreeRow extends TableTreeRow { | |
| 15 @reflectable final Isolate isolate; | |
| 16 @reflectable final Class cls; | |
| 17 ClassTreeRow(this.isolate, this.cls, ClassTreeRow parent) : super(parent) { | |
| 18 assert(isolate != null); | |
| 19 assert(cls != null); | |
| 20 } | |
| 21 | |
| 22 void onShow() { | |
| 23 if (children.length > 0) { | |
| 24 // Child rows already created. | |
| 25 return; | |
| 26 } | |
| 27 for (var subclass in cls.subclasses) { | |
| 28 if (subclass.isPatch) { | |
| 29 continue; | |
| 30 } | |
| 31 var row = new ClassTreeRow(isolate, subclass, this); | |
| 32 children.add(row); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void onHide() { | |
| 37 } | |
| 38 | |
| 39 bool hasChildren() { | |
| 40 return cls.subclasses.length > 0; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 | |
| 45 @CustomTag('class-tree') | |
| 46 class ClassTreeElement extends ObservatoryElement { | |
| 47 @observable Isolate isolate; | |
| 48 | |
| 49 TableTree tree; | |
| 50 | |
| 51 ClassTreeElement.created() : super.created(); | |
| 52 | |
| 53 @override | |
| 54 void attached() { | |
| 55 super.attached(); | |
| 56 tree = new TableTree(); | |
| 57 if (isolate != null) { | |
| 58 _update(isolate.objectClass); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 isolateChanged(oldValue) { | |
| 63 isolate.getClassHierarchy().then((objectClass) { | |
| 64 _update(objectClass); | |
| 65 }); | |
| 66 } | |
| 67 | |
| 68 void _update(Class root) { | |
| 69 try { | |
| 70 var rootRow = new ClassTreeRow(isolate, root, null); | |
| 71 rootRow.children.add(new ClassTreeRow(isolate, root, rootRow)); | |
| 72 tree.initialize(rootRow); | |
| 73 } catch (e, stackTrace) { | |
| 74 Logger.root.warning('_update', e, stackTrace); | |
| 75 } | |
| 76 // Check if we only have one node at the root and expand it. | |
| 77 if (tree.rows.length == 1) { | |
| 78 tree.toggle(0); | |
| 79 } | |
| 80 notifyPropertyChange(#tree, null, tree); | |
| 81 } | |
| 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 } | |
| OLD | NEW |