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 @ControllerAction
void disconnect() { 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 Core core
@Observable boolean disconnectActionEnabled @Observable boolean disconnectActionEnabled
@Observable String buttonText
@Observable ChatConnectionAttemptStatus status @Observable ChatConnectionAttemptStatus status
volatile ChatLink link volatile ChatLink link
@ -70,6 +71,9 @@ class ChatServerModel {
} }
if (e.status == ChatConnectionAttemptStatus.SUCCESSFUL) { if (e.status == ChatConnectionAttemptStatus.SUCCESSFUL) {
runInsideUIAsync {
buttonText = "Disconnect"
}
ChatLink link = e.connection ChatLink link = e.connection
if (link == null) if (link == null)
return return

View File

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