From 893a4bcae99a0ee9a80b013e9f936a3787e26c76 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 19 Mar 2025 12:25:26 +0100 Subject: [PATCH] the great rename --- .../org/cryptomator/common/vaults/Vault.java | 10 +++--- .../event/FileSystemEventBucket.java | 21 ++++++++++++ ...sMap.java => FileSystemEventRegistry.java} | 12 +++---- .../org/cryptomator/event/VaultEvent.java | 21 ------------ .../ui/eventview/EventListCellController.java | 22 ++++++------ .../ui/eventview/EventListCellFactory.java | 10 +++--- .../ui/eventview/EventViewController.java | 34 +++++++++---------- .../ui/mainwindow/VaultListController.java | 10 +++--- 8 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 src/main/java/org/cryptomator/event/FileSystemEventBucket.java rename src/main/java/org/cryptomator/event/{VaultEventsMap.java => FileSystemEventRegistry.java} (93%) delete mode 100644 src/main/java/org/cryptomator/event/VaultEvent.java diff --git a/src/main/java/org/cryptomator/common/vaults/Vault.java b/src/main/java/org/cryptomator/common/vaults/Vault.java index bac33151f..0bf2128c5 100644 --- a/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -10,7 +10,7 @@ package org.cryptomator.common.vaults; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.Constants; -import org.cryptomator.event.VaultEventsMap; +import org.cryptomator.event.FileSystemEventRegistry; import org.cryptomator.common.mount.Mounter; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; @@ -76,7 +76,7 @@ public class Vault { private final ObjectBinding mountPoint; private final Mounter mounter; private final Settings settings; - private final VaultEventsMap vaultEventsMap; + private final FileSystemEventRegistry fileSystemEventRegistry; private final BooleanProperty showingStats; private final AtomicReference mountHandle = new AtomicReference<>(null); @@ -89,7 +89,7 @@ public class Vault { @Named("lastKnownException") ObjectProperty lastKnownException, // VaultStats stats, // Mounter mounter, Settings settings, // - VaultEventsMap vaultEventsMap) { + FileSystemEventRegistry fileSystemEventRegistry) { this.vaultSettings = vaultSettings; this.configCache = configCache; this.cryptoFileSystem = cryptoFileSystem; @@ -106,7 +106,7 @@ public class Vault { this.mountPoint = Bindings.createObjectBinding(this::getMountPoint, state); this.mounter = mounter; this.settings = settings; - this.vaultEventsMap = vaultEventsMap; + this.fileSystemEventRegistry = fileSystemEventRegistry; this.showingStats = new SimpleBooleanProperty(false); this.quickAccessEntry = new AtomicReference<>(null); } @@ -259,7 +259,7 @@ public class Vault { private void consumeVaultEvent(FilesystemEvent e) { - vaultEventsMap.enque(this, e); + fileSystemEventRegistry.enque(this, e); } // ****************************************************************************** diff --git a/src/main/java/org/cryptomator/event/FileSystemEventBucket.java b/src/main/java/org/cryptomator/event/FileSystemEventBucket.java new file mode 100644 index 000000000..4e6639886 --- /dev/null +++ b/src/main/java/org/cryptomator/event/FileSystemEventBucket.java @@ -0,0 +1,21 @@ +package org.cryptomator.event; + +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.cryptofs.event.FilesystemEvent; + +public record FileSystemEventBucket(Vault v, FilesystemEvent mostRecent, int count) implements Comparable { + + @Override + public int compareTo(FileSystemEventBucket other) { + var timeResult = mostRecent.getTimestamp().compareTo(other.mostRecent().getTimestamp()); + if (timeResult != 0) { + return timeResult; + } + var vaultIdResult = v.getId().compareTo(other.v.getId()); + if (vaultIdResult != 0) { + return vaultIdResult; + } + return this.mostRecent.getClass().getName().compareTo(other.mostRecent.getClass().getName()); + } + +} diff --git a/src/main/java/org/cryptomator/event/VaultEventsMap.java b/src/main/java/org/cryptomator/event/FileSystemEventRegistry.java similarity index 93% rename from src/main/java/org/cryptomator/event/VaultEventsMap.java rename to src/main/java/org/cryptomator/event/FileSystemEventRegistry.java index 26290ff44..ffd79276e 100644 --- a/src/main/java/org/cryptomator/event/VaultEventsMap.java +++ b/src/main/java/org/cryptomator/event/FileSystemEventRegistry.java @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @Singleton -public class VaultEventsMap { +public class FileSystemEventRegistry { private static final int MAX_MAP_SIZE = 400; @@ -51,7 +51,7 @@ public class VaultEventsMap { private final AtomicBoolean queueHasElements; @Inject - public VaultEventsMap(ScheduledExecutorService scheduledExecutorService) { + public FileSystemEventRegistry(ScheduledExecutorService scheduledExecutorService) { this.queue = new ConcurrentHashMap<>(); this.lruCache = new TreeSet<>(this::compareKeys); this.map = FXCollections.observableHashMap(); @@ -85,19 +85,19 @@ public class VaultEventsMap { /** - * Lists all entries in this map as {@link VaultEvent}. The list is sorted ascending by the timestamp of event occurral (and more if it is the same timestamp). + * Lists all entries in this map as {@link FileSystemEventBucket}. The list is sorted ascending by the timestamp of event occurral (and more if it is the same timestamp). * Must be executed on the JavaFX application thread * * @return a list of vault events, mainly sorted ascending by the event timestamp * @implNote Method is not synchronized, because it is only executed if executed by JavaFX application thread */ - public List listAll() { + public List listAll() { if (!Platform.isFxApplicationThread()) { throw new IllegalStateException("Listing map entries must be performed on JavaFX application thread"); } return lruCache.stream().map(key -> { var value = map.get(key); - return new VaultEvent(key.vault(), value.mostRecentEvent(), value.count()); + return new FileSystemEventBucket(key.vault(), value.mostRecentEvent(), value.count()); }).toList(); } @@ -225,7 +225,7 @@ public class VaultEventsMap { * @param event Actual {@link FilesystemEvent} * @return a {@link Key} used in the map and lru cache */ - private Key computeKey(Vault v, FilesystemEvent event) { + private static Key computeKey(Vault v, FilesystemEvent event) { var p = switch (event) { case DecryptionFailedEvent(_, Path ciphertextPath, _) -> ciphertextPath; case ConflictResolvedEvent(_, _, _, _, Path resolvedCiphertext) -> resolvedCiphertext; diff --git a/src/main/java/org/cryptomator/event/VaultEvent.java b/src/main/java/org/cryptomator/event/VaultEvent.java deleted file mode 100644 index a967cf330..000000000 --- a/src/main/java/org/cryptomator/event/VaultEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.cryptomator.event; - -import org.cryptomator.common.vaults.Vault; -import org.cryptomator.cryptofs.event.FilesystemEvent; - -public record VaultEvent(Vault v, FilesystemEvent actualEvent, int count) implements Comparable { - - @Override - public int compareTo(VaultEvent other) { - var timeResult = actualEvent.getTimestamp().compareTo(other.actualEvent().getTimestamp()); - if (timeResult != 0) { - return timeResult; - } - var vaultIdResult = v.getId().compareTo(other.v.getId()); - if (vaultIdResult != 0) { - return vaultIdResult; - } - return this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName()); - } - -} diff --git a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java index a566bed7b..7c7f91dd9 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java @@ -1,6 +1,6 @@ package org.cryptomator.ui.eventview; -import org.cryptomator.event.VaultEventsMap; +import org.cryptomator.event.FileSystemEventRegistry; import org.cryptomator.common.Nullable; import org.cryptomator.common.ObservableUtil; import org.cryptomator.cryptofs.CryptoPath; @@ -9,7 +9,7 @@ import org.cryptomator.cryptofs.event.BrokenFileNodeEvent; import org.cryptomator.cryptofs.event.ConflictResolutionFailedEvent; import org.cryptomator.cryptofs.event.ConflictResolvedEvent; import org.cryptomator.cryptofs.event.DecryptionFailedEvent; -import org.cryptomator.event.VaultEvent; +import org.cryptomator.event.FileSystemEventBucket; import org.cryptomator.integrations.revealpath.RevealFailedException; import org.cryptomator.integrations.revealpath.RevealPathService; import org.cryptomator.ui.common.FxController; @@ -51,11 +51,11 @@ public class EventListCellController implements FxController { private static final DateTimeFormatter LOCAL_DATE_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); private static final DateTimeFormatter LOCAL_TIME_FORMATTER = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); - private final VaultEventsMap vaultEventsMap; + private final FileSystemEventRegistry fileSystemEventRegistry; @Nullable private final RevealPathService revealService; private final ResourceBundle resourceBundle; - private final ObjectProperty event; + private final ObjectProperty event; private final StringProperty eventMessage; private final StringProperty eventDescription; private final ObjectProperty eventIcon; @@ -77,8 +77,8 @@ public class EventListCellController implements FxController { Button eventActionsButton; @Inject - public EventListCellController(VaultEventsMap vaultEventsMap, Optional revealService, ResourceBundle resourceBundle) { - this.vaultEventsMap = vaultEventsMap; + public EventListCellController(FileSystemEventRegistry fileSystemEventRegistry, Optional revealService, ResourceBundle resourceBundle) { + this.fileSystemEventRegistry = fileSystemEventRegistry; this.revealService = revealService.orElseGet(() -> null); this.resourceBundle = resourceBundle; this.event = new SimpleObjectProperty<>(null); @@ -87,8 +87,8 @@ public class EventListCellController implements FxController { this.eventIcon = new SimpleObjectProperty<>(); this.eventCount = ObservableUtil.mapWithDefault(event, e -> e.count() == 1? "" : "("+ e.count() +")", ""); this.vaultUnlocked = ObservableUtil.mapWithDefault(event.flatMap(e -> e.v().unlockedProperty()), Function.identity(), false); - this.readableTime = ObservableUtil.mapWithDefault(event, e -> LOCAL_TIME_FORMATTER.format(e.actualEvent().getTimestamp()), ""); - this.readableDate = ObservableUtil.mapWithDefault(event, e -> LOCAL_DATE_FORMATTER.format(e.actualEvent().getTimestamp()), ""); + this.readableTime = ObservableUtil.mapWithDefault(event, e -> LOCAL_TIME_FORMATTER.format(e.mostRecent().getTimestamp()), ""); + this.readableDate = ObservableUtil.mapWithDefault(event, e -> LOCAL_DATE_FORMATTER.format(e.mostRecent().getTimestamp()), ""); this.message = Bindings.createStringBinding(this::selectMessage, vaultUnlocked, eventMessage); this.description = Bindings.createStringBinding(this::selectDescription, vaultUnlocked, eventDescription); this.icon = Bindings.createObjectBinding(this::selectIcon, vaultUnlocked, eventIcon); @@ -108,13 +108,13 @@ public class EventListCellController implements FxController { return vaultUnlocked.getValue() && (eventActionsMenu.isShowing() || root.isHover()); } - public void setEvent(@NotNull VaultEvent item) { + public void setEvent(@NotNull FileSystemEventBucket item) { event.set(item); eventActionsMenu.hide(); eventActionsMenu.getItems().clear(); eventTooltip.setText(item.v().getDisplayName()); - addAction("generic.action.dismiss", () -> vaultEventsMap.remove(item.v(),item.actualEvent())); - switch (item.actualEvent()) { + addAction("generic.action.dismiss", () -> fileSystemEventRegistry.remove(item.v(),item.mostRecent())); + switch (item.mostRecent()) { case ConflictResolvedEvent fse -> this.adjustToConflictResolvedEvent(fse); case ConflictResolutionFailedEvent fse -> this.adjustToConflictEvent(fse); case DecryptionFailedEvent fse -> this.adjustToDecryptionFailedEvent(fse); diff --git a/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java b/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java index 102bbfa05..3a84fcde8 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java @@ -1,6 +1,6 @@ package org.cryptomator.ui.eventview; -import org.cryptomator.event.VaultEvent; +import org.cryptomator.event.FileSystemEventBucket; import org.cryptomator.ui.common.FxmlLoaderFactory; import javax.inject.Inject; @@ -14,7 +14,7 @@ import java.io.IOException; import java.io.UncheckedIOException; @EventViewScoped -public class EventListCellFactory implements Callback, ListCell> { +public class EventListCellFactory implements Callback, ListCell> { private static final String FXML_PATH = "/fxml/eventview_cell.fxml"; @@ -27,7 +27,7 @@ public class EventListCellFactory implements Callback, List @Override - public ListCell call(ListView eventListView) { + public ListCell call(ListView eventListView) { try { FXMLLoader fxmlLoader = fxmlLoaders.load(FXML_PATH); return new Cell(fxmlLoader.getRoot(), fxmlLoader.getController()); @@ -36,7 +36,7 @@ public class EventListCellFactory implements Callback, List } } - private static class Cell extends ListCell { + private static class Cell extends ListCell { private final Parent root; private final EventListCellController controller; @@ -47,7 +47,7 @@ public class EventListCellFactory implements Callback, List } @Override - protected void updateItem(VaultEvent item, boolean empty) { + protected void updateItem(FileSystemEventBucket item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { diff --git a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java index 25061ec34..b40589584 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java @@ -1,8 +1,8 @@ package org.cryptomator.ui.eventview; -import org.cryptomator.event.VaultEventsMap; +import org.cryptomator.event.FileSystemEventRegistry; import org.cryptomator.common.vaults.Vault; -import org.cryptomator.event.VaultEvent; +import org.cryptomator.event.FileSystemEventBucket; import org.cryptomator.ui.common.FxController; import javax.inject.Inject; @@ -23,11 +23,11 @@ import java.util.ResourceBundle; @EventViewScoped public class EventViewController implements FxController { - private final VaultEventsMap vaultEventsMap; - private final ObservableList eventList; - private final FilteredList filteredEventList; + private final FileSystemEventRegistry fileSystemEventRegistry; + private final ObservableList eventList; + private final FilteredList filteredEventList; private final ObservableList vaults; - private final SortedList reversedEventList; + private final SortedList reversedEventList; private final ObservableList choiceBoxEntries; private final ResourceBundle resourceBundle; private final EventListCellFactory cellFactory; @@ -35,11 +35,11 @@ public class EventViewController implements FxController { @FXML ChoiceBox vaultFilterChoiceBox; @FXML - ListView eventListView; + ListView eventListView; @Inject - public EventViewController(VaultEventsMap vaultEventsMap, ObservableList vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) { - this.vaultEventsMap = vaultEventsMap; + public EventViewController(FileSystemEventRegistry fileSystemEventRegistry, ObservableList vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) { + this.fileSystemEventRegistry = fileSystemEventRegistry; this.eventList = FXCollections.observableArrayList(); this.filteredEventList = eventList.filtered(_ -> true); this.vaults = vaults; @@ -60,8 +60,8 @@ public class EventViewController implements FxController { } }); - eventList.addAll(vaultEventsMap.listAll()); - vaultEventsMap.addListener((MapChangeListener) this::updateList); + eventList.addAll(fileSystemEventRegistry.listAll()); + fileSystemEventRegistry.addListener((MapChangeListener) this::updateList); eventListView.setCellFactory(cellFactory); eventListView.setItems(reversedEventList); @@ -70,16 +70,16 @@ public class EventViewController implements FxController { vaultFilterChoiceBox.setConverter(new VaultConverter(resourceBundle)); } - private void updateList(MapChangeListener.Change change) { + private void updateList(MapChangeListener.Change change) { var vault = change.getKey().vault(); if (change.wasAdded() && change.wasRemoved()) { //entry updated - eventList.remove(new VaultEvent(vault, change.getValueRemoved().mostRecentEvent(), change.getValueRemoved().count())); - eventList.addLast(new VaultEvent(vault, change.getValueAdded().mostRecentEvent(), change.getValueAdded().count())); + eventList.remove(new FileSystemEventBucket(vault, change.getValueRemoved().mostRecentEvent(), change.getValueRemoved().count())); + eventList.addLast(new FileSystemEventBucket(vault, change.getValueAdded().mostRecentEvent(), change.getValueAdded().count())); } else if (change.wasAdded()) { - eventList.addLast(new VaultEvent(vault, change.getValueAdded().mostRecentEvent(), change.getValueAdded().count())); + eventList.addLast(new FileSystemEventBucket(vault, change.getValueAdded().mostRecentEvent(), change.getValueAdded().count())); } else { //removed - eventList.remove(new VaultEvent(vault, change.getValueRemoved().mostRecentEvent(), change.getValueRemoved().count())); + eventList.remove(new FileSystemEventBucket(vault, change.getValueRemoved().mostRecentEvent(), change.getValueRemoved().count())); } } @@ -93,7 +93,7 @@ public class EventViewController implements FxController { @FXML void clearEvents() { - vaultEventsMap.clear(); + fileSystemEventRegistry.clear(); } private static class VaultConverter extends StringConverter { diff --git a/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index 0e6a49ff9..3b5973354 100644 --- a/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java @@ -1,7 +1,7 @@ package org.cryptomator.ui.mainwindow; import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.event.VaultEventsMap; +import org.cryptomator.event.FileSystemEventRegistry; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultListManager; @@ -68,7 +68,7 @@ public class VaultListController implements FxController { private final VaultListCellFactory cellFactory; private final AddVaultWizardComponent.Builder addVaultWizard; private final BooleanBinding emptyVaultList; - private final VaultEventsMap vaultEventsMap; + private final FileSystemEventRegistry fileSystemEventRegistry; private final BooleanProperty newEventsPresent; private final VaultListManager vaultListManager; private final BooleanProperty draggingVaultOver = new SimpleBooleanProperty(); @@ -96,7 +96,7 @@ public class VaultListController implements FxController { FxApplicationWindows appWindows, // Settings settings, // Dialogs dialogs, // - VaultEventsMap vaultEventsMap) { + FileSystemEventRegistry fileSystemEventRegistry) { this.mainWindow = mainWindow; this.vaults = vaults; this.selectedVault = selectedVault; @@ -109,9 +109,9 @@ public class VaultListController implements FxController { this.dialogs = dialogs; this.emptyVaultList = Bindings.isEmpty(vaults); - this.vaultEventsMap = vaultEventsMap; + this.fileSystemEventRegistry = fileSystemEventRegistry; this.newEventsPresent = new SimpleBooleanProperty(false); - vaultEventsMap.addListener((MapChangeListener) change -> { + fileSystemEventRegistry.addListener((MapChangeListener) change -> { if (change.wasAdded()) { newEventsPresent.setValue(true); }