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