Make flow initiator view code more generic.

This commit is contained in:
Katarzyna Streich 2017-05-03 16:23:41 +01:00
parent c734f625ad
commit ab0bc8b8d0
2 changed files with 137 additions and 164 deletions

View File

@ -135,53 +135,42 @@ class StateMachineViewer : CordaView("Flow Triage") {
private inner class StateMachineDetailsView(val smmData: StateMachineData) : Fragment() { private inner class StateMachineDetailsView(val smmData: StateMachineData) : Fragment() {
override val root by fxml<Parent>() override val root by fxml<Parent>()
private val flowNamePane by fxid<TitledPane>() private val flowNameLabel by fxid<Label>()
private val flowProgressPane by fxid<TitledPane>() private val flowProgressPane by fxid<TitledPane>()
private val flowInitiatorPane by fxid<TitledPane>() private val flowInitiatorGrid by fxid<GridPane>()
private val flowResultPane by fxid<TitledPane>() private val flowResultVBox by fxid<VBox>()
init { init {
flowNamePane.apply { flowNameLabel.apply {
content = label {
text = FlowNameFormatter.boring.format(smmData.stateMachineName) text = FlowNameFormatter.boring.format(smmData.stateMachineName)
} }
}
flowProgressPane.apply { flowProgressPane.apply {
content = label { content = label {
text = smmData.stateMachineStatus.value?.status // TODO later we can do some magic with showing progress steps with subflows text = smmData.stateMachineStatus.value?.status // TODO later we can do some magic with showing progress steps with subflows
} }
} }
flowInitiatorPane.apply { when (smmData.flowInitiator) {
//TODO use fxml to access initiatorGridPane is FlowInitiator.Shell -> makeShellGrid(flowInitiatorGrid) // TODO Extend this when we will have more information on shell user.
// initiatorGridPane.apply {when... is FlowInitiator.Peer -> makePeerGrid(flowInitiatorGrid, smmData.flowInitiator as FlowInitiator.Peer)
content = when (smmData.flowInitiator) { is FlowInitiator.RPC -> makeRPCGrid(flowInitiatorGrid, smmData.flowInitiator as FlowInitiator.RPC)
is FlowInitiator.Shell -> ShellNode() // TODO Extend this when we will have more information on shell user. is FlowInitiator.Scheduled -> makeScheduledGrid(flowInitiatorGrid, smmData.flowInitiator as FlowInitiator.Scheduled)
is FlowInitiator.Peer -> PeerNode(smmData.flowInitiator as FlowInitiator.Peer)
is FlowInitiator.RPC -> RPCNode(smmData.flowInitiator as FlowInitiator.RPC)
is FlowInitiator.Scheduled -> ScheduledNode(smmData.flowInitiator as FlowInitiator.Scheduled)
} }
}
flowResultPane.apply {
val status = smmData.addRmStatus.value val status = smmData.addRmStatus.value
if (status is StateMachineStatus.Removed) { if (status is StateMachineStatus.Removed) {
content = status.result.match(onValue = { ResultNode(it) }, onError = { ErrorNode(it) }) status.result.match(onValue = { makeResultVBox(flowResultVBox, it) }, onError = { makeErrorVBox(flowResultVBox, it) })
}
} }
} }
} }
// TODO make that Vbox part of FXML private fun <T>makeResultVBox(vbox: VBox, result: T) {
private inner class ResultNode<T>(result: T) : VBox() {
init {
spacing = 10.0
padding = Insets(5.0, 5.0, 5.0, 5.0)
if (result == null) { if (result == null) {
label("No return value from flow.") vbox.apply { label("No return value from flow.") }
} else if (result is SignedTransaction) { } else if (result is SignedTransaction) {
// scrollpane { // scrollpane {
// hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED // hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED
// vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER // vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
// TODO Make link to transaction view // TODO Make link to transaction view
vbox.apply {
label("Signed transaction") label("Signed transaction")
label { label {
text = result.id.toString() text = result.id.toString()
@ -189,22 +178,18 @@ class StateMachineViewer : CordaView("Flow Triage") {
tooltip = identiconToolTip(result.id) tooltip = identiconToolTip(result.id)
} }
// } // }
}
} else if (result is Unit) { } else if (result is Unit) {
label("Flow completed with success.") vbox.apply { label("Flow completed with success.") }
} }
else { else {
// TODO Here we could have sth different than SignedTransaction // TODO Here we could have sth different than SignedTransaction
label(result.toString()) vbox.apply { label(result.toString()) }
}
} }
} }
// TODO make that Vbox part of FXML private fun makeErrorVBox(vbox: VBox, error: Throwable) {
private inner class ErrorNode(val error: Throwable) : VBox() { vbox.apply {
init {
vbox {
spacing = 10.0
padding = Insets(5.0, 5.0, 5.0, 5.0)
label("Error") { label("Error") {
graphic = FontAwesomeIconView(FontAwesomeIcon.BOLT).apply { graphic = FontAwesomeIconView(FontAwesomeIcon.BOLT).apply {
glyphSize = 30 glyphSize = 30
@ -212,42 +197,35 @@ class StateMachineViewer : CordaView("Flow Triage") {
style = "-fx-fill: -color-4" style = "-fx-fill: -color-4"
} }
} }
// TODO think of border styling }
// TODO border styling?
vbox.apply {
vbox { vbox {
spacing = 10.0 spacing = 10.0
label { text = error::class.simpleName } label { text = error::class.simpleName }
scrollpane { scrollpane { //TODO do that error scroll pane nicely
hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED
vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
label { text = error.message } label { text = error.message }
} }
} }
} }
}
// TODO test
private fun makeShellGrid(gridPane: GridPane) {
val title = gridPane.lookup("#flowInitiatorTitle") as Label
title.apply {
text = "Flow started by shell user"
} }
} }
private inner class ShellNode : Label() { private fun makePeerGrid(gridPane: GridPane, initiator: FlowInitiator.Peer) {
init { val title = gridPane.lookup("#flowInitiatorTitle") as Label
label("Flow started by shell user") title.apply {
} text = "Flow started by a peer node"
}
// TODO make it more generic, reuse gridpane definition - to fxml
private inner class PeerNode(val initiator: FlowInitiator.Peer): GridPane() {
init {
gridpane {
padding = Insets(0.0, 5.0, 10.0, 10.0)
vgap = 10.0
hgap = 10.0
row {
label("Flow started by a peer node") {
gridpaneConstraints {
columnSpan = 2
hAlignment = HPos.CENTER
}
}
} }
gridPane.apply{
// scrollpane { // TODO scrollbar vbox + hbox // scrollpane { // TODO scrollbar vbox + hbox
// hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED // hbarPolicy = ScrollPane.ScrollBarPolicy.AS_NEEDED
// vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER // vbarPolicy = ScrollPane.ScrollBarPolicy.NEVER
@ -271,22 +249,13 @@ class StateMachineViewer : CordaView("Flow Triage") {
} }
} }
} }
}
private inner class RPCNode(val initiator: FlowInitiator.RPC) : GridPane() { private fun makeRPCGrid(gridPane: GridPane, initiator: FlowInitiator.RPC) {
init { val title = gridPane.lookup("#flowInitiatorTitle") as Label
gridpane { title.apply {
padding = Insets(0.0, 5.0, 10.0, 10.0) text = "Flow started by a RPC user"
vgap = 10.0
hgap = 10.0
row {
label("Flow started by a RPC user") {
gridpaneConstraints {
columnSpan = 2
hAlignment = HPos.CENTER
}
}
} }
gridPane.apply {
row { row {
label("User name: ") { label("User name: ") {
gridpaneConstraints { hAlignment = HPos.LEFT } gridpaneConstraints { hAlignment = HPos.LEFT }
@ -297,22 +266,14 @@ class StateMachineViewer : CordaView("Flow Triage") {
} }
} }
} }
}
// TODO test // TODO test
private inner class ScheduledNode(val initiator: FlowInitiator.Scheduled) : GridPane() { private fun makeScheduledGrid(gridPane: GridPane, initiator: FlowInitiator.Scheduled) {
init { val title = gridPane.lookup("flowInitiatorTitle") as Label
gridpane { title.apply {
padding = Insets(0.0, 5.0, 10.0, 10.0) text = "Flow started as scheduled activity"
vgap = 10.0
hgap = 10.0
row {
label("Flow started as scheduled activity")
gridpaneConstraints {
columnSpan = 2
hAlignment = HPos.CENTER
}
} }
gridPane.apply {
row { row {
label("Scheduled state: ") { label("Scheduled state: ") {
gridpaneConstraints { hAlignment = HPos.LEFT } gridpaneConstraints { hAlignment = HPos.LEFT }
@ -332,4 +293,3 @@ class StateMachineViewer : CordaView("Flow Triage") {
} }
} }
} }
}

View File

@ -4,24 +4,37 @@
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.TitledPane?> <?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<GridPane stylesheets="@../css/corda.css" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1"> <GridPane stylesheets="@../css/corda.css" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<padding> <padding>
<Insets bottom="5" left="5" right="5" top="5" /> <Insets bottom="5" left="5" right="5" top="5" />
</padding> </padding>
<TitledPane fx:id="flowNamePane" collapsible="false" text="Flow name" GridPane.columnSpan="2" GridPane.fillWidth="true" GridPane.rowIndex="0"> <TitledPane fx:id="flowNamePane" collapsible="false" text="Flow name" GridPane.columnSpan="2" GridPane.fillWidth="true" GridPane.rowIndex="0">
<!--TODO text styling-->
<Label fx:id="flowNameLabel"/> <Label fx:id="flowNameLabel"/>
</TitledPane> </TitledPane>
<TitledPane fx:id="flowInitiatorPane" collapsible="false" maxHeight="Infinity" text="Flow initiator" <TitledPane fx:id="flowInitiatorPane" collapsible="false" maxHeight="Infinity" text="Flow initiator"
GridPane.columnIndex="0" GridPane.fillWidth="true" GridPane.rowIndex="1"> GridPane.columnIndex="0" GridPane.fillWidth="true" GridPane.rowIndex="1">
<!-- todo add gridpane - from code! --> <GridPane fx:id="flowInitiatorGrid" vgap="10.0" hgap="10.0">
<padding>
<Insets bottom="5.0" left="5.0" right="10.0" top="10.0" />
</padding>
<!--TODO text styling-->
<Label fx:id="flowInitiatorTitle" GridPane.columnSpan="2" GridPane.rowIndex="0" GridPane.columnIndex="1" GridPane.halignment="LEFT"/>
</GridPane>
</TitledPane> </TitledPane>
<TitledPane fx:id="flowResultPane" collapsible="false" maxHeight="Infinity" text="Result" GridPane.columnIndex="1" GridPane.rowIndex="1"> <TitledPane fx:id="flowResultPane" collapsible="false" maxHeight="Infinity" text="Result" GridPane.columnIndex="1" GridPane.rowIndex="1">
<!-- todo add vbox - from code! --> <VBox fx:id="flowResultVBox" spacing="10.0">
<padding>
<Insets bottom="5" left="5" right="5" top="5"/>
</padding>
</VBox>
</TitledPane> </TitledPane>
<TitledPane fx:id="flowProgressPane" collapsible="false" maxWidth="Infinity" text="Progress steps" GridPane.columnSpan="2" GridPane.rowIndex="2"> <TitledPane fx:id="flowProgressPane" collapsible="false" maxWidth="Infinity" text="Progress steps" GridPane.columnSpan="2" GridPane.rowIndex="2">
<!--TODO add progress graph-->
</TitledPane> </TitledPane>
<columnConstraints> <columnConstraints>
<ColumnConstraints minWidth="450.0"/> <ColumnConstraints minWidth="450.0"/>