| 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 part of app; | |
| 6 | |
| 7 /// A [Pane] controls the user interface of Observatory. At any given time | |
| 8 /// one pane will be the current pane. Panes are registered at startup. | |
| 9 /// When the user navigates within the application, each pane is asked if it | |
| 10 /// can handle the current location, the first pane to say yes, wins. | |
| 11 abstract class Pane extends Observable { | |
| 12 final ObservatoryApplication app; | |
| 13 | |
| 14 @observable ObservatoryElement element; | |
| 15 | |
| 16 Pane(this.app); | |
| 17 | |
| 18 /// Called when the pane is installed, this callback must initialize | |
| 19 /// [element]. | |
| 20 void onInstall(); | |
| 21 | |
| 22 /// Called when the pane is uninstalled, this callback must clear | |
| 23 /// [element]. | |
| 24 void onUninstall() { | |
| 25 element = null; | |
| 26 } | |
| 27 | |
| 28 /// Called when the pane should update its state based on [url]. | |
| 29 /// NOTE: Only called when the pane is installed. | |
| 30 void visit(String url); | |
| 31 | |
| 32 /// Called to test whether this pane can visit [url]. | |
| 33 bool canVisit(String url); | |
| 34 } | |
| 35 | |
| 36 /// A general service object viewer. | |
| 37 class ServiceObjectPane extends Pane { | |
| 38 ServiceObjectPane(app) : super(app); | |
| 39 | |
| 40 void onInstall() { | |
| 41 if (element == null) { | |
| 42 /// Lazily create pane. | |
| 43 element = new Element.tag('service-view'); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void visit(String url) { | |
| 48 assert(element != null); | |
| 49 assert(canVisit(url)); | |
| 50 if (url == '') { | |
| 51 // Nothing requested. | |
| 52 return; | |
| 53 } | |
| 54 /// Request url from VM and display it. | |
| 55 app.vm.get(url).then((obj) { | |
| 56 ServiceObjectViewElement pane = element; | |
| 57 pane.object = obj; | |
| 58 }).catchError((e) { | |
| 59 Logger.root.severe('ServiceObjectPane visit error: $e'); | |
| 60 }); | |
| 61 } | |
| 62 | |
| 63 /// Catch all. | |
| 64 bool canVisit(String url) => true; | |
| 65 } | |
| 66 | |
| 67 /// Class tree pane. | |
| 68 class ClassTreePane extends Pane { | |
| 69 static const _urlPrefix = 'class-tree/'; | |
| 70 | |
| 71 ClassTreePane(app) : super(app); | |
| 72 | |
| 73 void onInstall() { | |
| 74 if (element == null) { | |
| 75 element = new Element.tag('class-tree'); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void visit(String url) { | |
| 80 assert(element != null); | |
| 81 assert(canVisit(url)); | |
| 82 // ClassTree urls are 'class-tree/isolate-id', chop off prefix, leaving | |
| 83 // isolate url. | |
| 84 url = url.substring(_urlPrefix.length); | |
| 85 /// Request the isolate url. | |
| 86 app.vm.get(url).then((i) { | |
| 87 if (element != null) { | |
| 88 /// Update the pane. | |
| 89 ClassTreeElement pane = element; | |
| 90 pane.isolate = i; | |
| 91 } | |
| 92 }).catchError((e) { | |
| 93 Logger.root.severe('ClassTreePane visit error: $e'); | |
| 94 }); | |
| 95 } | |
| 96 | |
| 97 /// Catch all. | |
| 98 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 99 } | |
| 100 | |
| 101 class ErrorViewPane extends Pane { | |
| 102 ErrorViewPane(app) : super(app); | |
| 103 | |
| 104 void onInstall() { | |
| 105 if (element == null) { | |
| 106 /// Lazily create pane. | |
| 107 element = new Element.tag('service-view'); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void visit(String url) { | |
| 112 assert(element != null); | |
| 113 assert(canVisit(url)); | |
| 114 (element as ServiceObjectViewElement).object = app.lastErrorOrException; | |
| 115 } | |
| 116 | |
| 117 bool canVisit(String url) => url.startsWith('error/'); | |
| 118 } | |
| 119 | |
| 120 class VMConnectPane extends Pane { | |
| 121 VMConnectPane(app) : super(app); | |
| 122 | |
| 123 void onInstall() { | |
| 124 if (element == null) { | |
| 125 element = new Element.tag('vm-connect'); | |
| 126 } | |
| 127 assert(element != null); | |
| 128 } | |
| 129 | |
| 130 void visit(String url) { | |
| 131 assert(element != null); | |
| 132 assert(canVisit(url)); | |
| 133 } | |
| 134 | |
| 135 bool canVisit(String url) => url.startsWith('vm-connect/'); | |
| 136 } | |
| OLD | NEW |