mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-17 20:56:02 +00:00
add choicebox to filter for single vaults
This commit is contained in:
@@ -1,36 +1,74 @@
|
||||
package org.cryptomator.ui.eventview;
|
||||
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
import javafx.collections.transformation.SortedList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.util.StringConverter;
|
||||
import java.util.Comparator;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@EventViewScoped
|
||||
public class EventViewController implements FxController {
|
||||
|
||||
private final SortedList<VaultEvent> reversedEventList;
|
||||
private final ObservableList<VaultEvent> eventList;
|
||||
private final FilteredList<VaultEvent> filteredEventList;
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final SortedList<VaultEvent> reversedEventList;
|
||||
private final ObservableList<Vault> choiceBoxEntries;
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final EventListCellFactory cellFactory;
|
||||
|
||||
@FXML
|
||||
ChoiceBox<Vault> vaultFilterChoiceBox;
|
||||
@FXML
|
||||
ListView<VaultEvent> eventListView;
|
||||
|
||||
@Inject
|
||||
public EventViewController(ObservableList<VaultEvent> eventList, EventListCellFactory cellFactory) {
|
||||
reversedEventList = new SortedList<>(eventList, Comparator.reverseOrder());
|
||||
public EventViewController(ObservableList<VaultEvent> eventList, ObservableList<Vault> vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) {
|
||||
this.eventList = eventList;
|
||||
this.filteredEventList = eventList.filtered(_ -> true);
|
||||
this.vaults = vaults;
|
||||
this.reversedEventList = new SortedList<>(filteredEventList, Comparator.reverseOrder());
|
||||
this.choiceBoxEntries = FXCollections.observableArrayList();
|
||||
this.resourceBundle = resourceBundle;
|
||||
this.cellFactory = cellFactory;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
choiceBoxEntries.add(null);
|
||||
choiceBoxEntries.addAll(vaults);
|
||||
vaults.addListener((ListChangeListener<? super Vault>) c -> {
|
||||
while (c.next()) {
|
||||
choiceBoxEntries.removeAll(c.getRemoved());
|
||||
choiceBoxEntries.addAll(c.getAddedSubList());
|
||||
}
|
||||
});
|
||||
eventListView.setCellFactory(cellFactory);
|
||||
eventListView.setItems(reversedEventList);
|
||||
|
||||
vaultFilterChoiceBox.setItems(choiceBoxEntries);
|
||||
vaultFilterChoiceBox.valueProperty().addListener(this::applyVaultFilter);
|
||||
vaultFilterChoiceBox.setConverter(new VaultConverter(resourceBundle));
|
||||
}
|
||||
|
||||
private void applyVaultFilter(ObservableValue<? extends Vault> v, Vault oldV, Vault newV) {
|
||||
if (newV == null) {
|
||||
filteredEventList.setPredicate(_ -> true);
|
||||
} else {
|
||||
filteredEventList.setPredicate(e -> e.v().equals(newV));
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -38,5 +76,27 @@ public class EventViewController implements FxController {
|
||||
eventList.clear();
|
||||
}
|
||||
|
||||
private static class VaultConverter extends StringConverter<Vault> {
|
||||
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
VaultConverter(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Vault v) {
|
||||
if (v == null) {
|
||||
return resourceBundle.getString("eventView.filter.allVaults");
|
||||
} else {
|
||||
return v.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vault fromString(String displayLanguage) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,20 @@
|
||||
<?import javafx.scene.layout.Region?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:controller="org.cryptomator.ui.eventview.EventViewController"
|
||||
minWidth="300"
|
||||
minHeight="450"
|
||||
prefWidth="300"
|
||||
prefHeight="450"
|
||||
styleClass="event-window"
|
||||
>
|
||||
<HBox styleClass="button-bar">
|
||||
<HBox styleClass="button-bar" alignment="CENTER">
|
||||
<padding>
|
||||
<Insets left="6" />
|
||||
</padding>
|
||||
<ChoiceBox fx:id="vaultFilterChoiceBox"/>
|
||||
<Region HBox.hgrow="ALWAYS"/>
|
||||
<Button styleClass="button-right" onAction="#clearEventList" contentDisplay="GRAPHIC_ONLY">
|
||||
<graphic>
|
||||
@@ -23,5 +27,5 @@
|
||||
</graphic>
|
||||
</Button>
|
||||
</HBox>
|
||||
<ListView fx:id="eventListView" fixedCellSize="60"/>
|
||||
<ListView fx:id="eventListView" fixedCellSize="60" VBox.vgrow="ALWAYS"/>
|
||||
</VBox>
|
||||
|
||||
@@ -582,6 +582,7 @@ shareVault.hub.instruction.2=2. Grant access to team member in Cryptomator Hub.
|
||||
shareVault.hub.openHub=Open Cryptomator Hub
|
||||
|
||||
# Event View
|
||||
eventView.filter.allVaults=All
|
||||
event.vaultLocked.message=***********
|
||||
event.vaultLocked.description=Unlock vault "%s" for details
|
||||
event.conflictResolved.description=Resolved conflict
|
||||
|
||||
Reference in New Issue
Block a user