Replace the internal event bus with Event Bus 0.0.3
The Event class has been retrofitted to implement IEvent, so that no event implementations had to be changed.
This commit is contained in:
@@ -1,26 +1,21 @@
|
||||
package envoy.client.ui.controller;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.*;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
|
||||
import envoy.client.event.BackEvent;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.client.ui.listcell.ContactControl;
|
||||
import envoy.client.ui.listcell.ListCellFactory;
|
||||
import envoy.client.event.*;
|
||||
import envoy.client.ui.listcell.*;
|
||||
import envoy.data.User;
|
||||
import envoy.event.ElementOperation;
|
||||
import envoy.event.EventBus;
|
||||
import envoy.event.contact.ContactOperation;
|
||||
import envoy.event.contact.UserSearchRequest;
|
||||
import envoy.event.contact.UserSearchResult;
|
||||
import envoy.event.contact.*;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
import dev.kske.eventbus.*;
|
||||
|
||||
/**
|
||||
* Provides a search bar in which a user name (substring) can be entered. The
|
||||
* users with a matching name are then displayed inside a list view. A
|
||||
@@ -39,7 +34,7 @@ import envoy.util.EnvoyLog;
|
||||
* @author Maximilian Käfer
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
public class ContactSearchTab {
|
||||
public class ContactSearchTab implements EventListener {
|
||||
|
||||
@FXML
|
||||
private TextArea searchBar;
|
||||
@@ -48,26 +43,29 @@ public class ContactSearchTab {
|
||||
private ListView<User> userList;
|
||||
|
||||
private Alert alert = new Alert(AlertType.CONFIRMATION);
|
||||
|
||||
private User currentlySelectedUser;
|
||||
|
||||
private final Consumer<ContactOperation> handler = e -> {
|
||||
final var contact = e.get();
|
||||
if (e.getOperationType() == ElementOperation.ADD) Platform.runLater(() -> {
|
||||
userList.getItems().remove(contact);
|
||||
if (currentlySelectedUser != null && currentlySelectedUser.equals(contact) && alert.isShowing()) alert.close();
|
||||
});
|
||||
};
|
||||
|
||||
private static final EventBus eventBus = EventBus.getInstance();
|
||||
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
eventBus.registerListener(this);
|
||||
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
|
||||
eventBus.register(UserSearchResult.class,
|
||||
response -> Platform.runLater(() -> { userList.getItems().clear(); userList.getItems().addAll(response.get()); }));
|
||||
eventBus.register(ContactOperation.class, handler);
|
||||
}
|
||||
|
||||
@Event
|
||||
private void onUserSearchResult(UserSearchResult result) {
|
||||
Platform.runLater(() -> { userList.getItems().clear(); userList.getItems().addAll(result.get()); });
|
||||
}
|
||||
|
||||
@Event
|
||||
private void onContactOperation(ContactOperation operation) {
|
||||
final var contact = operation.get();
|
||||
if (operation.getOperationType() == ElementOperation.ADD) Platform.runLater(() -> {
|
||||
userList.getItems().remove(contact);
|
||||
if (currentlySelectedUser != null && currentlySelectedUser.equals(contact) && alert.isShowing()) alert.close();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user