mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-22 04:31:27 +00:00
use same listCell factory pattern as in vault list
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package org.cryptomator.ui.eventview;
|
||||
|
||||
import org.cryptomator.common.ObservableUtil;
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.controls.FontAwesome5IconView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
public class EventListCellController implements FxController {
|
||||
|
||||
private final ObjectProperty<Event> event;
|
||||
private final ObservableValue<String> description;
|
||||
|
||||
public FontAwesome5IconView eventIcon;
|
||||
public HBox eventListCell;
|
||||
|
||||
@Inject
|
||||
public EventListCellController() {
|
||||
this.event = new SimpleObjectProperty<>(null);
|
||||
this.description = ObservableUtil.mapWithDefault(event, e -> e.getClass().getName(),"");
|
||||
}
|
||||
|
||||
public void setEvent(Event item) {
|
||||
event.set(item);
|
||||
}
|
||||
|
||||
public ObservableValue<String> descriptionProperty() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description.getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.cryptomator.ui.eventview;
|
||||
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.ui.common.FxmlLoaderFactory;
|
||||
import org.cryptomator.ui.mainwindow.VaultListCellController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ContentDisplay;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.util.Callback;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
public class EventListCellFactory implements Callback<ListView<Event>, ListCell<Event>> {
|
||||
|
||||
private static final String FXML_PATH = "/fxml/eventview_cell.fxml";
|
||||
|
||||
private final FxmlLoaderFactory fxmlLoaders;
|
||||
|
||||
@Inject
|
||||
EventListCellFactory(@EventViewWindow FxmlLoaderFactory fxmlLoaders) {
|
||||
this.fxmlLoaders = fxmlLoaders;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ListCell<Event> call(ListView<Event> eventListView) {
|
||||
try {
|
||||
FXMLLoader fxmlLoader = fxmlLoaders.load(FXML_PATH);
|
||||
return new Cell(fxmlLoader.getRoot(), fxmlLoader.getController());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to load %s.".formatted(FXML_PATH), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Cell extends ListCell<Event> {
|
||||
|
||||
private final Parent root;
|
||||
private final EventListCellController controller;
|
||||
|
||||
public Cell(Parent root, EventListCellController controller) {
|
||||
this.root = root;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(Event item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
if (empty) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
} else {
|
||||
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
|
||||
setGraphic(root);
|
||||
controller.setEvent(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,21 @@ public class EventViewController implements FxController {
|
||||
|
||||
private final SortedList<Event> reversedEventList;
|
||||
private final ObservableList<Event> eventList;
|
||||
private final EventListCellFactory cellFactory;
|
||||
|
||||
@FXML
|
||||
ListView<Event> eventListView;
|
||||
|
||||
@Inject
|
||||
public EventViewController(ObservableList<Event> eventList) {
|
||||
public EventViewController(ObservableList<Event> eventList, EventListCellFactory cellFactory) {
|
||||
reversedEventList = new SortedList<>(eventList, Comparator.reverseOrder());
|
||||
this.eventList = eventList;
|
||||
this.cellFactory = cellFactory;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
eventListView.setCellFactory(cellFactory);
|
||||
eventListView.setItems(reversedEventList);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,6 @@ abstract class EventViewModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(UpdateEventViewController.class)
|
||||
abstract FxController bindUpdateEventViewController(UpdateEventViewController controller);
|
||||
@FxControllerKey(EventListCellController.class)
|
||||
abstract FxController bindEventListCellController(EventListCellController controller);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user