mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-17 20:56:02 +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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:id="eventListCell"
|
||||
fx:controller="org.cryptomator.ui.eventview.EventListCellController"
|
||||
prefHeight="60"
|
||||
prefWidth="200"
|
||||
spacing="12"
|
||||
alignment="CENTER_LEFT">
|
||||
<!-- Remark Check the containing list view for a fixed cell size before editing height properties -->
|
||||
<VBox alignment="CENTER" minWidth="20">
|
||||
<FontAwesome5IconView fx:id="eventIcon" glyph="BELL" HBox.hgrow="NEVER" glyphSize="16"/>
|
||||
</VBox>
|
||||
<VBox spacing="4" HBox.hgrow="ALWAYS">
|
||||
<Label styleClass="header-label" text="Hey, listen!"/>
|
||||
</VBox>
|
||||
</HBox>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:controller="org.cryptomator.ui.eventview.UpdateEventViewController"
|
||||
alignment="TOP_CENTER"
|
||||
spacing="9">
|
||||
|
||||
<Text>Update Available!</Text>
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user