mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 18:21:26 +00:00
Replaced TransformationList by simpler List with listener, because Property Extractor didn't work properly
This commit is contained in:
@@ -15,9 +15,11 @@ import javafx.collections.ObservableList;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.SettingsProvider;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultComponent;
|
||||
import org.cryptomator.common.vaults.VaultList;
|
||||
import org.cryptomator.common.vaults.VaultFactory;
|
||||
import org.cryptomator.common.vaults.VaultListChangeListener;
|
||||
import org.cryptomator.frontend.webdav.WebDavServer;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
@@ -51,8 +53,14 @@ public abstract class CommonsModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static ObservableList<Vault> provideVaultList(VaultList vaultList) {
|
||||
return FXCollections.observableList(vaultList, Vault::observables);
|
||||
static ObservableList<Vault> provideVaultList(Settings settings, VaultFactory vaultFactory) {
|
||||
ObservableList<Vault> list = FXCollections.observableArrayList(Vault::observables);
|
||||
for (VaultSettings s : settings.getDirectories()) {
|
||||
Vault v = vaultFactory.get(s);
|
||||
list.add(v);
|
||||
}
|
||||
list.addListener(new VaultListChangeListener(settings.getDirectories()));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Vault {
|
||||
private final Provider<Volume> volumeProvider;
|
||||
private final StringBinding defaultMountFlags;
|
||||
private final AtomicReference<CryptoFileSystem> cryptoFileSystem;
|
||||
private final ObjectProperty<VaultState> state ;
|
||||
private final ObjectProperty<VaultState> state;
|
||||
private final VaultStats stats;
|
||||
private final ObjectProperty<Path> accessPoint = new SimpleObjectProperty<>(Path.of(""));
|
||||
private final StringBinding displayableName;
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Skymatic UG (haftungsbeschränkt).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the accompanying LICENSE file.
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.common.vaults;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.TransformationList;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Singleton
|
||||
public class VaultList extends TransformationList<Vault, VaultSettings> {
|
||||
|
||||
private final VaultFactory vaultFactory;
|
||||
private final ObservableList<VaultSettings> source;
|
||||
|
||||
@Inject
|
||||
public VaultList(Settings settings, VaultFactory vaultFactory) {
|
||||
super(settings.getDirectories());
|
||||
this.source = settings.getDirectories();
|
||||
this.vaultFactory = vaultFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceIndex(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewIndex(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vault get(int index) {
|
||||
VaultSettings s = source.get(index);
|
||||
return vaultFactory.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Vault element) {
|
||||
source.add(index, element.getVaultSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vault remove(int index) {
|
||||
VaultSettings s = source.remove(index);
|
||||
return vaultFactory.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getSource().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sourceChanged(ListChangeListener.Change<? extends VaultSettings> c) {
|
||||
this.fireChange(new VaultListChange(c));
|
||||
}
|
||||
|
||||
private class VaultListChange extends ListChangeListener.Change<Vault> {
|
||||
|
||||
private final ListChangeListener.Change<? extends VaultSettings> delegate;
|
||||
|
||||
public VaultListChange(ListChangeListener.Change<? extends VaultSettings> delegate) {
|
||||
super(VaultList.this);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
return delegate.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasUpdated() {
|
||||
return delegate.wasUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
delegate.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrom() {
|
||||
return delegate.getFrom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTo() {
|
||||
return delegate.getTo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vault> getRemoved() {
|
||||
return Lists.transform(delegate.getRemoved(), vaultFactory::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasPermutated() {
|
||||
return delegate.wasPermutated();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getPermutation() {
|
||||
if (delegate.wasPermutated()) {
|
||||
return IntStream.range(getFrom(), getTo()).map(delegate::getPermutation).toArray();
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.cryptomator.common.vaults;
|
||||
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
|
||||
/**
|
||||
* This listener makes sure to reflect any changes to the vault list back to the settings.
|
||||
*/
|
||||
public class VaultListChangeListener implements ListChangeListener<Vault> {
|
||||
|
||||
private final ObservableList<VaultSettings> vaultSettingsList;
|
||||
|
||||
public VaultListChangeListener(ObservableList<VaultSettings> vaultSettingsList) {
|
||||
this.vaultSettingsList = vaultSettingsList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(Change<? extends Vault> c) {
|
||||
while(c.next()) {
|
||||
if (c.wasAdded()) {
|
||||
for (int i = c.getFrom(); i < c.getTo(); i++) {
|
||||
Vault v = c.getList().get(i);
|
||||
vaultSettingsList.add(i, v.getVaultSettings());
|
||||
}
|
||||
} else if (c.wasRemoved()) {
|
||||
for (Vault v : c.getRemoved()) {
|
||||
vaultSettingsList.remove(v.getVaultSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,6 @@ import org.cryptomator.ui.model.AppLaunchEvent;
|
||||
import org.cryptomator.ui.model.AutoUnlocker;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultFactory;
|
||||
import org.cryptomator.common.vaults.VaultList;
|
||||
import org.cryptomator.ui.model.upgrade.UpgradeStrategies;
|
||||
import org.cryptomator.ui.model.upgrade.UpgradeStrategy;
|
||||
import org.cryptomator.ui.util.DialogBuilderUtil;
|
||||
@@ -112,7 +111,7 @@ public class MainController implements ViewController {
|
||||
|
||||
@Inject
|
||||
public MainController(@Named("mainWindow") Stage mainWindow, ExecutorService executorService, @Named("launchEventQueue") BlockingQueue<AppLaunchEvent> launchEventQueue, ExitUtil exitUtil, Localization localization,
|
||||
VaultFactory vaultFactoy, ViewControllerLoader viewControllerLoader, UpgradeStrategies upgradeStrategies, VaultList vaults, AutoUnlocker autoUnlocker) {
|
||||
VaultFactory vaultFactoy, ViewControllerLoader viewControllerLoader, UpgradeStrategies upgradeStrategies, ObservableList<Vault> vaults, AutoUnlocker autoUnlocker) {
|
||||
this.mainWindow = mainWindow;
|
||||
this.executorService = executorService;
|
||||
this.launchEventQueue = launchEventQueue;
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui.model;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultList;
|
||||
import org.cryptomator.common.vaults.Volume;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationScoped;
|
||||
import org.cryptomator.cryptolib.api.CryptoException;
|
||||
import org.cryptomator.keychain.KeychainAccess;
|
||||
import org.cryptomator.keychain.KeychainAccessException;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationScoped;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -33,11 +33,11 @@ public class AutoUnlocker {
|
||||
private static final int NAP_TIME_MILLIS = 500;
|
||||
|
||||
private final Optional<KeychainAccess> keychainAccess;
|
||||
private final VaultList vaults;
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
public AutoUnlocker(Optional<KeychainAccess> keychainAccess, VaultList vaults, ExecutorService executor) {
|
||||
public AutoUnlocker(Optional<KeychainAccess> keychainAccess, ObservableList<Vault> vaults, ExecutorService executor) {
|
||||
this.keychainAccess = keychainAccess;
|
||||
this.vaults = vaults;
|
||||
this.executor = executor;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.fxapp.FxApplication;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -23,6 +26,8 @@ import java.util.function.Consumer;
|
||||
|
||||
@TrayMenuScoped
|
||||
class TrayMenuController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TrayMenuController.class);
|
||||
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final FxApplicationStarter fxApplicationStarter;
|
||||
@@ -69,8 +74,12 @@ class TrayMenuController {
|
||||
}
|
||||
|
||||
private void vaultListChanged(@SuppressWarnings("unused") Observable observable) {
|
||||
assert Platform.isFxApplicationThread();
|
||||
rebuildMenu();
|
||||
allVaultsAreLocked.set(vaults.stream().allMatch(Vault::isLocked));
|
||||
boolean allLocked = vaults.stream().allMatch(Vault::isLocked);
|
||||
// TODO remove logging
|
||||
LOG.warn("allLocked: {}", allLocked);
|
||||
allVaultsAreLocked.set(allLocked);
|
||||
}
|
||||
|
||||
private void rebuildMenu() {
|
||||
|
||||
Reference in New Issue
Block a user