Removed alert when adding new user

This commit is contained in:
Maximilian P. Käfer 2020-08-23 17:24:55 +02:00
parent dbf69c7cc1
commit f77795edb1
2 changed files with 8 additions and 17 deletions

View File

@ -122,21 +122,13 @@ public class ContactSearchTab {
final var user = userList.getSelectionModel().getSelectedItem(); final var user = userList.getSelectionModel().getSelectedItem();
if (user != null) { if (user != null) {
currentlySelectedUser = user; currentlySelectedUser = user;
alert = new Alert(AlertType.CONFIRMATION); final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD);
alert.setTitle("Add User to Contact List"); // Sends the event to the server
alert.setHeaderText("Add the user " + currentlySelectedUser.getName() + " to your contact list?"); eventBus.dispatch(new SendEvent(event));
// Normally, this would be total BS (we are already on the FX Thread), however // Removes the chosen user and updates the UI
// it could be proven that the creation of this dialog wrapped in userList.getItems().remove(currentlySelectedUser);
// Platform.runLater is less error-prone than without it eventBus.dispatch(event);
Platform.runLater(() -> alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> { logger.log(Level.INFO, "Added user " + currentlySelectedUser);
final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD);
// Sends the event to the server
eventBus.dispatch(new SendEvent(event));
// Removes the chosen user and updates the UI
userList.getItems().remove(currentlySelectedUser);
eventBus.dispatch(event);
logger.log(Level.INFO, "Added user " + currentlySelectedUser);
}));
} }
} }

View File

@ -5,7 +5,6 @@
<?import javafx.scene.control.ContextMenu?> <?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
@ -43,7 +42,7 @@
<Insets left="10.0" right="10.0" /> <Insets left="10.0" right="10.0" />
</VBox.margin> </VBox.margin>
<padding> <padding>
<Insets bottom="10.0" top="5.0" /> <Insets bottom="17.0" top="5.0" />
</padding> </padding>
</HBox> </HBox>
<ListView id="chatList" fx:id="userList" focusTraversable="false" onMouseClicked="#userListClicked" prefWidth="316.0" VBox.vgrow="ALWAYS"> <ListView id="chatList" fx:id="userList" focusTraversable="false" onMouseClicked="#userListClicked" prefWidth="316.0" VBox.vgrow="ALWAYS">