Improved SystemCommand mechanism, added Alert- and ShutdownHelper, and
... added askForConfirmation option
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
|
||||
import envoy.client.event.*;
|
||||
import envoy.client.helper.AlertHelper;
|
||||
import envoy.client.ui.listcell.*;
|
||||
import envoy.data.User;
|
||||
import envoy.event.ElementOperation;
|
||||
@@ -42,9 +43,10 @@ public class ContactSearchTab implements EventListener {
|
||||
@FXML
|
||||
private ListView<User> userList;
|
||||
|
||||
private Alert alert = new Alert(AlertType.CONFIRMATION);
|
||||
private User currentlySelectedUser;
|
||||
|
||||
private final Alert alert = new Alert(AlertType.CONFIRMATION);
|
||||
|
||||
private static final EventBus eventBus = EventBus.getInstance();
|
||||
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
||||
|
||||
@@ -52,6 +54,7 @@ public class ContactSearchTab implements EventListener {
|
||||
private void initialize() {
|
||||
eventBus.registerListener(this);
|
||||
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
|
||||
alert.setTitle("Add User?");
|
||||
}
|
||||
|
||||
@Event
|
||||
@@ -102,17 +105,24 @@ public class ContactSearchTab implements EventListener {
|
||||
private void userListClicked() {
|
||||
final var user = userList.getSelectionModel().getSelectedItem();
|
||||
if (user != null) {
|
||||
currentlySelectedUser = user;
|
||||
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);
|
||||
currentlySelectedUser = user;
|
||||
alert.setContentText("Add user " + currentlySelectedUser.getName() + " to your contacts?");
|
||||
AlertHelper.confirmAction(alert, this::addAsContact);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAsContact() {
|
||||
|
||||
// Sends the event to the server
|
||||
final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD);
|
||||
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);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void backButtonClicked() { eventBus.dispatch(new BackEvent()); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user