DemoBench: address review comments and fix refresh bug

This commit is contained in:
Mike Hearn 2017-04-19 16:00:48 +02:00
parent 2c6163ecb9
commit 691b622cf0
9 changed files with 27 additions and 41 deletions
tools/demobench

@ -38,10 +38,6 @@ repositories {
}
}
compileKotlin {
kotlinOptions.jvmTarget= "1.8"
}
dependencies {
// TornadoFX: A lightweight Kotlin framework for working with JavaFX UI's.
compile "no.tornado:tornadofx:$tornadofx_version"

@ -5,8 +5,6 @@ import net.corda.demobench.views.DemoBenchView
import tornadofx.*
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets.UTF_8
import javax.swing.SwingUtilities
import javax.swing.UIManager
/**
* README!
@ -38,7 +36,6 @@ import javax.swing.UIManager
*/
class DemoBench : App(DemoBenchView::class) {
/*
* This entry point is needed by JavaPackager, as
* otherwise the packaged application cannot run.

@ -25,7 +25,6 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() {
private var baseDir: Path = baseDirFor(ManagementFactory.getRuntimeMXBean().startTime)
private val cordaPath: Path = jvm.applicationDir.resolve("corda").resolve("corda.jar")
//private val command = arrayOf("/usr/local/bin/fish")
private val command = jvm.commandFor(cordaPath).toTypedArray()
private val nodes = LinkedHashMap<String, NodeConfig>()

@ -11,7 +11,7 @@ import java.nio.charset.StandardCharsets.UTF_8
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class R3Pty(val name: String, settings: SettingsProvider, dimension: Dimension, val onExit: () -> Unit) : AutoCloseable {
class R3Pty(val name: String, settings: SettingsProvider, dimension: Dimension, val onExit: (Int) -> Unit) : AutoCloseable {
private companion object {
val log = loggerFor<R3Pty>()
}
@ -57,7 +57,7 @@ class R3Pty(val name: String, settings: SettingsProvider, dimension: Dimension,
executor.submit {
val exitValue = connector.waitFor()
log.info("Terminal has exited (value={})", exitValue)
onExit()
onExit(exitValue)
}
val session = terminal.createTerminalSession(connector)

@ -21,7 +21,6 @@ import net.corda.demobench.model.*
import net.corda.demobench.ui.CloseableTab
import tornadofx.*
import java.nio.file.Path
import java.text.DecimalFormat
import java.util.*
class NodeTabView : Fragment() {
@ -34,13 +33,7 @@ class NodeTabView : Fragment() {
const val textWidth = 465.0
const val maxNameLength = 15
val integerFormat = DecimalFormat()
val jvm by inject<JVMConfig>()
init {
integerFormat.isGroupingUsed = false
}
}
private val nodeController by inject<NodeController>()
@ -215,7 +208,6 @@ class NodeTabView : Fragment() {
val config = nodeController.validate(model.item)
if (config != null) {
nodeConfigView.isVisible = false
nodeTab.graphic = ImageView(flags.get()[model.nearestCity.value.countryCode]).apply { fitWidth = 24.0; isPreserveRatio = true }
config.install(cordapps)
launchNode(config)
}
@ -230,22 +222,24 @@ class NodeTabView : Fragment() {
}
private fun launchNode(config: NodeConfig) {
val countryCode = CityDatabase.cityMap[config.nearestCity]?.countryCode
if (countryCode != null) {
nodeTab.graphic = ImageView(flags.get()[countryCode]).apply { fitWidth = 24.0; isPreserveRatio = true }
}
nodeTab.text = config.legalName
nodeTerminalView.open(config, onExit = { onTerminalExit(config) })
nodeTerminalView.open(config) { exitCode ->
Platform.runLater {
if (exitCode == 0)
nodeTab.requestClose()
nodeController.dispose(config)
main.forceAtLeastOneTab()
}
}
nodeTab.setOnSelectionChanged {
if (nodeTab.isSelected) {
// Doesn't work yet
nodeTerminalView.refreshTerminal()
nodeTerminalView.takeFocus()
}
}
}
private fun onTerminalExit(config: NodeConfig) {
Platform.runLater {
nodeTab.requestClose()
nodeController.dispose(config)
main.forceAtLeastOneTab()
}
}
}

@ -22,7 +22,6 @@ import net.corda.demobench.ui.PropertyLabel
import net.corda.demobench.web.DBViewer
import net.corda.demobench.web.WebServerController
import tornadofx.*
import java.awt.Color
import java.awt.Dimension
import java.util.logging.Level
import javax.swing.SwingUtilities
@ -50,12 +49,12 @@ class NodeTerminalView : Fragment() {
private var rpc: NodeRPC? = null
private var pty: R3Pty? = null
private lateinit var logo: ImageView
private lateinit var swingTerminal: SwingNode
fun open(config: NodeConfig, onExit: () -> Unit) {
fun open(config: NodeConfig, onExit: (Int) -> Unit) {
nodeName.text = config.legalName
launchWebButton.text = "Launch\nWeb Server\n(Port ${config.webPort})"
val swingTerminal = SwingNode()
swingTerminal = SwingNode()
swingTerminal.setOnMouseClicked {
swingTerminal.requestFocus()
}
@ -139,6 +138,7 @@ class NodeTerminalView : Fragment() {
webServer.open(config, onExit = {
launchWebButton.isDisable = false
app.hostServices.showDocument("http://localhost:${config.webPort}/")
})
}
}
@ -174,8 +174,12 @@ class NodeTerminalView : Fragment() {
}
}
fun refreshTerminal() {
// TODO - Force a repaint somehow? My naive attempts have not worked.
fun takeFocus() {
// Request focus. This also forces a repaint, without this, for some reason the terminal has gone to sleep
// and is no longer updating in response to new data from the pty.
Platform.runLater {
swingTerminal.requestFocus()
}
}
// TODO - Will change when we modify RPC Observables handling.

@ -68,5 +68,4 @@ class WebServer internal constructor(private val webServerController: WebServerC
log.error("Failed to close stream: '{}'", e.message)
}
}
}

@ -4,7 +4,6 @@ import net.corda.demobench.model.JVMConfig
import tornadofx.*
class WebServerController : Controller() {
private val jvm by inject<JVMConfig>()
private val webserverPath = jvm.applicationDir.resolve("corda").resolve("corda-webserver.jar")
@ -15,5 +14,4 @@ class WebServerController : Controller() {
internal fun process() = jvm.processFor(webserverPath)
fun webServer() = WebServer(this)
}

@ -3,17 +3,16 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import net.corda.demobench.ui.*?>
<VBox visible="false" prefHeight="953.0" prefWidth="1363.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" styleClass="terminal-vbox">
<VBox visible="false" prefHeight="953.0" prefWidth="1363.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" styleClass="terminal-vbox">
<HBox prefHeight="95.0" prefWidth="800.0" styleClass="header">
<VBox prefHeight="66.0" HBox.hgrow="ALWAYS">
<Label fx:id="nodeName" style="-fx-font-size: 40; -fx-text-fill: red;" minWidth="NaN"/>
<Label fx:id="nodeName" style="-fx-font-size: 40; -fx-text-fill: red;"/>
</VBox>
<VBox prefHeight="93.0" prefWidth="267.0">
<PropertyLabel fx:id="states" name="States in vault: "/>
<PropertyLabel fx:id="transactions" name="Known transactions: "/>
<PropertyLabel fx:id="balance" name="Balance: "/>
</VBox>
<!--<Pane prefHeight="200.0" prefWidth="200.0"/>-->
<Button fx:id="viewDatabaseButton" disable="true" mnemonicParsing="false" prefHeight="92.0" prefWidth="115.0"
styleClass="big-button" text="View&#10;Database" textAlignment="CENTER"/>
<Button fx:id="launchWebButton" disable="true" mnemonicParsing="false" prefHeight="92.0" prefWidth="115.0"