From 4aa2a8ea18b959591603ed2b651ba9ee355ace90 Mon Sep 17 00:00:00 2001 From: Viktor Kolomeyko Date: Wed, 13 Dec 2017 10:30:26 +0000 Subject: [PATCH] ENT-1240: Only add IOUView when applicable. (#189) --- .../src/main/kotlin/net/corda/explorer/Main.kt | 12 +++++++++++- .../net/corda/explorer/model/CordaViewModel.kt | 6 +++++- .../main/kotlin/net/corda/explorer/views/MainView.kt | 2 +- .../corda/explorer/views/cordapps/iou/IOUViewer.kt | 8 ++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt index 3c5237515e..4750b08b05 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt @@ -65,10 +65,21 @@ class Main : App(MainView::class) { if (!isLoggedIn) { stage.hide() loginView.login() + addOptionalViews() + (find(primaryView) as MainView).initializeControls() stage.show() } } + private fun addOptionalViews() { + val iouView = find() + Models.get(Main::class).apply { + if (iouView.isEnabledForNode()) { + registerView(iouView) + } + } + } + private fun asInteger(s: String?): Int? { try { return s?.toInt() @@ -105,7 +116,6 @@ class Main : App(MainView::class) { registerView() // CordApps Views. registerView() - registerView() // Tools. registerView() registerView() diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/model/CordaViewModel.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/model/CordaViewModel.kt index 248656b0f9..8a9498c8d3 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/model/CordaViewModel.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/model/CordaViewModel.kt @@ -11,9 +11,13 @@ class CordaViewModel { val registeredViews = mutableListOf().observable() inline fun registerView() where T : CordaView { + registerView(find()) + } + + fun registerView(view: CordaView) { // Note: this is weirdly very important, as it forces the initialisation of Views. Therefore this is the entry // point to the top level observable/stream wiring! Any events sent before this init may be lost! - registeredViews.add(find().apply { root }) + registeredViews.add(view.apply { root }) } } diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/MainView.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/MainView.kt index 2369a5dfc5..9a180c7f40 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/MainView.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/MainView.kt @@ -48,7 +48,7 @@ class MainView : View(WINDOW_TITLE) { private val menuItemArrowCSS = "sidebar-menu-item-arrow" private val menuItemSelectedCSS = "$menuItemCSS-selected" - init { + fun initializeControls() { // Header userButton.textProperty().bind(myIdentity.map { it?.let { PartyNameFormatter.short.format(it.name) } }) exit.setOnAction { diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/iou/IOUViewer.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/iou/IOUViewer.kt index 689c314582..3dd6afa82b 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/iou/IOUViewer.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/iou/IOUViewer.kt @@ -4,7 +4,9 @@ import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView import javafx.scene.input.MouseButton import javafx.scene.layout.BorderPane +import net.corda.core.utilities.Try import net.corda.explorer.model.CordaView +import net.corda.explorer.model.MembershipListModel import tornadofx.* class IOUViewer : CordaView("IOU") { @@ -24,4 +26,10 @@ class IOUViewer : CordaView("IOU") { } } } + + fun isEnabledForNode(): Boolean = Try.on { + // Assuming if the model can be initialized - the CorDapp is installed + val allParties = MembershipListModel().allParties + allParties[0] + }.isSuccess } \ No newline at end of file