async connect button

This commit is contained in:
sirjonasxx 2019-01-16 18:22:03 +01:00
parent c522db40da
commit 0ca71ad174

View File

@ -23,8 +23,6 @@ public class Connection extends SubForm {
public CheckBox cbx_autodetect;
public TextField txtfield_hotelversion;
private boolean isBusy = false;
public void initialize() {
inpPort.getEditor().textProperty().addListener(observable -> {
updateInputUI();
@ -77,6 +75,7 @@ public class Connection extends SubForm {
public void onParentSet(){
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> {
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
Platform.runLater(() -> {
if (newState == HConnection.State.NOT_CONNECTED) {
updateInputUI();
lblState.setText("Not connected");
@ -97,19 +96,24 @@ public class Connection extends SubForm {
if (newState == HConnection.State.WAITING_FOR_CLIENT) {
lblState.setText("Waiting for connection");
}
});
}));
}
public void btnConnect_clicked(ActionEvent actionEvent) {
if (!isBusy) {
isBusy = true;
if (getHConnection().getState() == HConnection.State.NOT_CONNECTED) {
btnConnect.setDisable(true);
new Thread(() -> {
if (cbx_autodetect.isSelected()) {
getHConnection().prepare();
}
else {
getHConnection().prepare(inpHost.getEditor().getText(), Integer.parseInt(inpPort.getEditor().getText()));
}
Platform.runLater(() -> btnConnect.setDisable(false));
if (HConnection.DEBUG) System.out.println("connecting");
@ -120,10 +124,11 @@ public class Connection extends SubForm {
e.printStackTrace();
}
}).start();
}).start();
}
else {
getHConnection().abort();
isBusy = false;
}
}