diff --git a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java index b60b4cb81..994cf3441 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java @@ -4,7 +4,7 @@ import org.cryptomator.common.vaults.Vault; import org.cryptomator.event.FSEventBucket; import org.cryptomator.event.FSEventBucketContent; import org.cryptomator.ui.common.FxController; -import org.cryptomator.ui.fxapp.EventsUpdateCheck; +import org.cryptomator.ui.fxapp.FxFSEventList; import javax.inject.Inject; import javafx.beans.value.ObservableValue; @@ -36,8 +36,8 @@ public class EventViewController implements FxController { ListView> eventListView; @Inject - public EventViewController(EventsUpdateCheck eventsUpdateCheck, ObservableList vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) { - this.filteredEventList = eventsUpdateCheck.getList().filtered(_ -> true); + public EventViewController(FxFSEventList fxFSEventList, ObservableList vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) { + this.filteredEventList = fxFSEventList.getObservableList().filtered(_ -> true); this.vaults = vaults; this.sortedEventList = new SortedList<>(filteredEventList, this::compareBuckets); this.choiceBoxEntries = FXCollections.observableArrayList(); diff --git a/src/main/java/org/cryptomator/ui/eventview/EventViewModule.java b/src/main/java/org/cryptomator/ui/eventview/EventViewModule.java index e2f7d43b0..94829023f 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventViewModule.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventViewModule.java @@ -11,10 +11,9 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlLoaderFactory; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.StageFactory; +import org.cryptomator.ui.fxapp.FxFSEventList; -import javax.inject.Named; import javax.inject.Provider; -import javafx.beans.property.BooleanProperty; import javafx.scene.Scene; import javafx.stage.Modality; import javafx.stage.Stage; @@ -27,7 +26,7 @@ abstract class EventViewModule { @Provides @EventViewScoped @EventViewWindow - static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle, @Named("unreadEventsAvailable") BooleanProperty unreadEvents) { + static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle, FxFSEventList fxFSEventList) { Stage stage = factory.create(); stage.setHeight(498); stage.setTitle(resourceBundle.getString("eventView.title")); @@ -35,7 +34,7 @@ abstract class EventViewModule { stage.initModality(Modality.NONE); stage.focusedProperty().addListener((_,_,isFocused) -> { if(isFocused) { - unreadEvents.setValue(false); + fxFSEventList.unreadEventsProperty().setValue(false); } }); return stage; diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index a76b994a0..1544d205f 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -29,10 +29,10 @@ public class FxApplication { private final FxApplicationStyle applicationStyle; private final FxApplicationTerminator applicationTerminator; private final AutoUnlocker autoUnlocker; - private final EventsUpdateCheck eventsUpdateCheck; //not unused! By injecting it here, the object gets initiated the service starts + private final FxFSEventList fxFSEventList; //not unused! By injecting it here, the object gets initiated the service starts @Inject - FxApplication(@Named("startupTime") long startupTime, Environment environment, Settings settings, AppLaunchEventHandler launchEventHandler, Lazy trayMenu, FxApplicationWindows appWindows, FxApplicationStyle applicationStyle, FxApplicationTerminator applicationTerminator, AutoUnlocker autoUnlocker, EventsUpdateCheck eventsUpdateCheck) { + FxApplication(@Named("startupTime") long startupTime, Environment environment, Settings settings, AppLaunchEventHandler launchEventHandler, Lazy trayMenu, FxApplicationWindows appWindows, FxApplicationStyle applicationStyle, FxApplicationTerminator applicationTerminator, AutoUnlocker autoUnlocker, FxFSEventList fxFSEventList) { this.startupTime = startupTime; this.environment = environment; this.settings = settings; @@ -42,7 +42,7 @@ public class FxApplication { this.applicationStyle = applicationStyle; this.applicationTerminator = applicationTerminator; this.autoUnlocker = autoUnlocker; - this.eventsUpdateCheck = eventsUpdateCheck; + this.fxFSEventList = fxFSEventList; } public void start() { diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java index 35cbf13ca..9110f8d50 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java @@ -77,11 +77,4 @@ abstract class FxApplicationModule { return factory.create(); } - @Provides - @FxApplicationScoped - @Named("unreadEventsAvailable") - static BooleanProperty provideUnreadEventsAvailable() { - return new SimpleBooleanProperty(false); - } - } \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java b/src/main/java/org/cryptomator/ui/fxapp/FxFSEventList.java similarity index 71% rename from src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java rename to src/main/java/org/cryptomator/ui/fxapp/FxFSEventList.java index 8d5a144eb..1af084970 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxFSEventList.java @@ -5,9 +5,9 @@ import org.cryptomator.event.FSEventBucketContent; import org.cryptomator.event.FileSystemEventAggregator; import javax.inject.Inject; -import javax.inject.Named; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import java.util.Map; @@ -17,37 +17,37 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @FxApplicationScoped -public class EventsUpdateCheck { +public class FxFSEventList { private final ObservableList> events; - private final FileSystemEventAggregator eventRegistry; + private final FileSystemEventAggregator eventAggregator; private final ScheduledFuture scheduledTask; private final BooleanProperty unreadEvents; @Inject - public EventsUpdateCheck(FileSystemEventAggregator eventRegistry, ScheduledExecutorService scheduler, @Named("unreadEventsAvailable") BooleanProperty unreadEvents) { + public FxFSEventList(FileSystemEventAggregator fsEventAggregator, ScheduledExecutorService scheduler) { this.events = FXCollections.observableArrayList(); - this.eventRegistry = eventRegistry; - this.unreadEvents = unreadEvents; + this.eventAggregator = fsEventAggregator; + this.unreadEvents = new SimpleBooleanProperty(false); this.scheduledTask = scheduler.scheduleWithFixedDelay(() -> { - if (eventRegistry.hasUpdates()) { + if (fsEventAggregator.hasUpdates()) { flush(); } }, 1000, 1000, TimeUnit.MILLISECONDS); //TODO: allow the task to be canceled (to enable ui actions, e.g. when the contextMenu is open, the list should not be updated } - public ObservableList> getList() { + public ObservableList> getObservableList() { return events; } /** - * Clones the registry into the observable list + * Clones the aggregator into the observable list */ private void flush() { var latch = new CountDownLatch(1); Platform.runLater(() -> { - eventRegistry.cloneTo(events); + eventAggregator.cloneTo(events); unreadEvents.setValue(true); latch.countDown(); }); @@ -58,6 +58,9 @@ public class EventsUpdateCheck { } } + public BooleanProperty unreadEventsProperty() { + return unreadEvents; + } } diff --git a/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index 684e8540e..2d6cdc6cf 100644 --- a/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java @@ -6,18 +6,17 @@ import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultListManager; import org.cryptomator.cryptofs.CryptoFileSystemProvider; import org.cryptomator.cryptofs.DirStructure; -import org.cryptomator.event.FileSystemEventRegistry; import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.VaultService; import org.cryptomator.ui.dialogs.Dialogs; +import org.cryptomator.ui.fxapp.FxFSEventList; import org.cryptomator.ui.fxapp.FxApplicationWindows; import org.cryptomator.ui.preferences.SelectedPreferencesTab; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; -import javax.inject.Named; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; import javafx.beans.property.BooleanProperty; @@ -25,7 +24,6 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; -import javafx.collections.MapChangeListener; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.geometry.Side; @@ -69,7 +67,7 @@ public class VaultListController implements FxController { private final VaultListCellFactory cellFactory; private final AddVaultWizardComponent.Builder addVaultWizard; private final BooleanBinding emptyVaultList; - private final BooleanProperty newEventsPresent; + private final BooleanProperty unreadEvents; private final VaultListManager vaultListManager; private final BooleanProperty draggingVaultOver = new SimpleBooleanProperty(); private final ResourceBundle resourceBundle; @@ -96,7 +94,7 @@ public class VaultListController implements FxController { FxApplicationWindows appWindows, // Settings settings, // Dialogs dialogs, // - @Named("unreadEventsAvailable") BooleanProperty unreadEvents) { + FxFSEventList fxFSEventList) { this.mainWindow = mainWindow; this.vaults = vaults; this.selectedVault = selectedVault; @@ -109,7 +107,7 @@ public class VaultListController implements FxController { this.dialogs = dialogs; this.emptyVaultList = Bindings.isEmpty(vaults); - this.newEventsPresent = unreadEvents; + this.unreadEvents = fxFSEventList.unreadEventsProperty(); selectedVault.addListener(this::selectedVaultDidChange); cellSize = settings.compactMode.map(compact -> compact ? 30.0 : 60.0); @@ -272,7 +270,7 @@ public class VaultListController implements FxController { @FXML public void showEventViewer() { appWindows.showEventViewer(); - newEventsPresent.setValue(false); + unreadEvents.setValue(false); } // Getter and Setter @@ -300,11 +298,11 @@ public class VaultListController implements FxController { return cellSize.getValue(); } - public ObservableValue newEventsPresentProperty() { - return newEventsPresent; + public ObservableValue unreadEventsPresentProperty() { + return unreadEvents; } - public boolean getNewEventsPresent() { - return newEventsPresent.getValue(); + public boolean getUnreadEventsPresent() { + return unreadEvents.getValue(); } } diff --git a/src/main/resources/fxml/vault_list.fxml b/src/main/resources/fxml/vault_list.fxml index f6a6e03af..6706ec293 100644 --- a/src/main/resources/fxml/vault_list.fxml +++ b/src/main/resources/fxml/vault_list.fxml @@ -56,7 +56,7 @@ - +