change button to connect/disconnect

pull/34/head
Zlatin Balevsky 2019-11-14 04:20:57 +00:00
parent 3de058a078
commit 7dc37e3e0d
3 changed files with 14 additions and 2 deletions

View File

@ -15,6 +15,14 @@ class ChatServerController {
@ControllerAction
void disconnect() {
model.core.eventBus.publish(new UIDisconnectChatEvent(host : model.host))
switch(model.buttonText) {
case "Disconnect" :
model.buttonText = "Connect"
model.core.eventBus.publish(new UIDisconnectChatEvent(host : model.host))
break
case "Connect" :
model.connect()
break
}
}
}

View File

@ -24,6 +24,7 @@ class ChatServerModel {
Core core
@Observable boolean disconnectActionEnabled
@Observable String buttonText
@Observable ChatConnectionAttemptStatus status
volatile ChatLink link
@ -70,6 +71,9 @@ class ChatServerModel {
}
if (e.status == ChatConnectionAttemptStatus.SUCCESSFUL) {
runInsideUIAsync {
buttonText = "Disconnect"
}
ChatLink link = e.connection
if (link == null)
return

View File

@ -31,7 +31,7 @@ class ChatServerView {
gridLayout(rows : 1, cols : 3)
panel {}
panel {
button(text : "Disconnect", enabled : bind {model.disconnectActionEnabled}, disconnectAction)
button(text : bind {model.buttonText}, enabled : bind {model.disconnectActionEnabled}, disconnectAction)
}
panel {
label(text : "Connection Status ")