Renamed nioAdapterImpl to volumeImpl.

This commit is contained in:
Sebastian Stenzel
2018-03-17 16:08:58 +01:00
parent a666c80ef5
commit 7c1a0b5fdf
8 changed files with 63 additions and 38 deletions
@@ -1,8 +0,0 @@
package org.cryptomator.common.settings;
public enum NioAdapterImpl {
WEBDAV,
FUSE
}
@@ -32,7 +32,7 @@ public class Settings {
public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3;
public static final String DEFAULT_GVFS_SCHEME = "dav";
public static final boolean DEFAULT_DEBUG_MODE = false;
public static final NioAdapterImpl DEFAULT_NIO_ADAPTER = NioAdapterImpl.WEBDAV;
public static final VolumeImpl DEFAULT_VOLUME_IMPL = VolumeImpl.WEBDAV;
private final ObservableList<VaultSettings> directories = FXCollections.observableArrayList(VaultSettings::observables);
private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES);
@@ -40,7 +40,7 @@ public class Settings {
private final IntegerProperty numTrayNotifications = new SimpleIntegerProperty(DEFAULT_NUM_TRAY_NOTIFICATIONS);
private final StringProperty preferredGvfsScheme = new SimpleStringProperty(DEFAULT_GVFS_SCHEME);
private final BooleanProperty debugMode = new SimpleBooleanProperty(DEFAULT_DEBUG_MODE);
private final ObjectProperty<NioAdapterImpl> nioAdapterImpl = new SimpleObjectProperty<>(DEFAULT_NIO_ADAPTER);
private final ObjectProperty<VolumeImpl> volumeImpl = new SimpleObjectProperty<>(DEFAULT_VOLUME_IMPL);
private Consumer<Settings> saveCmd;
@@ -54,7 +54,7 @@ public class Settings {
numTrayNotifications.addListener(this::somethingChanged);
preferredGvfsScheme.addListener(this::somethingChanged);
debugMode.addListener(this::somethingChanged);
nioAdapterImpl.addListener(this::somethingChanged);
volumeImpl.addListener(this::somethingChanged);
}
void setSaveCmd(Consumer<Settings> saveCmd) {
@@ -97,8 +97,8 @@ public class Settings {
return debugMode;
}
public ObjectProperty<NioAdapterImpl> usedNioAdapterImpl() {
return nioAdapterImpl;
public ObjectProperty<VolumeImpl> volumeImpl() {
return volumeImpl;
}
}
@@ -33,7 +33,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
out.name("numTrayNotifications").value(value.numTrayNotifications().get());
out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get());
out.name("debugMode").value(value.debugMode().get());
out.name("nioAdapterImpl").value(value.usedNioAdapterImpl().get().name());
out.name("volumeImpl").value(value.volumeImpl().get().name());
out.endObject();
}
@@ -71,8 +71,8 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
case "debugMode":
settings.debugMode().set(in.nextBoolean());
break;
case "nioAdapterImpl":
settings.usedNioAdapterImpl().set(parseNioAdapterName(in.nextString()));
case "volumeImpl":
settings.volumeImpl().set(parseNioAdapterName(in.nextString()));
break;
default:
LOG.warn("Unsupported vault setting found in JSON: " + name);
@@ -84,11 +84,11 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
return settings;
}
private NioAdapterImpl parseNioAdapterName(String nioAdapterName) {
private VolumeImpl parseNioAdapterName(String nioAdapterName) {
try {
return NioAdapterImpl.valueOf(nioAdapterName);
return VolumeImpl.valueOf(nioAdapterName);
} catch (IllegalArgumentException e) {
return Settings.DEFAULT_NIO_ADAPTER;
return Settings.DEFAULT_VOLUME_IMPL;
}
}
@@ -0,0 +1,33 @@
package org.cryptomator.common.settings;
import java.util.Arrays;
public enum VolumeImpl {
WEBDAV("WebDAV"),
FUSE("FUSE");
private String displayName;
VolumeImpl(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
/**
* Finds a VolumeImpl by display name.
*
* @param displayName Display name of the VolumeImpl
* @return VolumeImpl with the given <code>displayName</code>.
* @throws IllegalArgumentException if not volumeImpl with the given <code>displayName</code> was found.
*/
public static VolumeImpl forDisplayName(String displayName) throws IllegalArgumentException {
return Arrays.stream(values()) //
.filter(impl -> impl.displayName.equals(displayName)) //
.findAny() //
.orElseThrow(IllegalArgumentException::new);
}
}
@@ -22,7 +22,7 @@ public class SettingsJsonAdapterTest {
+ "\"checkForUpdatesEnabled\": true,"//
+ "\"port\": 8080,"//
+ "\"numTrayNotifications\": 42,"//
+ "\"nioAdapterImpl\": \"webdav\"}";
+ "\"volumeImpl\": \"FUSE\"}";
Settings settings = adapter.fromJson(json);
@@ -31,7 +31,7 @@ public class SettingsJsonAdapterTest {
Assert.assertEquals(8080, settings.port().get());
Assert.assertEquals(42, settings.numTrayNotifications().get());
Assert.assertEquals("dav", settings.preferredGvfsScheme().get());
Assert.assertEquals(NioAdapterImpl.WEBDAV, settings.usedNioAdapterImpl().get());
Assert.assertEquals(VolumeImpl.FUSE, settings.volumeImpl().get());
}
}
@@ -30,7 +30,7 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.util.StringConverter;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.NioAdapterImpl;
import org.cryptomator.common.settings.VolumeImpl;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.ui.l10n.Localization;
@@ -81,7 +81,7 @@ public class SettingsController implements ViewController {
private Label volumeLabel;
@FXML
private ChoiceBox<NioAdapterImpl> volume;
private ChoiceBox<VolumeImpl> volume;
@FXML
private CheckBox debugModeCheckbox;
@@ -97,12 +97,12 @@ public class SettingsController implements ViewController {
//NIOADAPTER
volume.getItems().addAll(getSupportedAdapters());
volume.setValue(settings.usedNioAdapterImpl().get());
volume.setValue(settings.volumeImpl().get());
volume.setVisible(true);
volume.setConverter(new NioAdapterImplStringConverter());
//WEBDAV
webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.WEBDAV));
webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(VolumeImpl.WEBDAV));
webdavVolume.managedProperty().bind(webdavVolume.visibleProperty());
prefGvfsScheme.managedProperty().bind(webdavVolume.visibleProperty());
prefGvfsSchemeLabel.managedProperty().bind(webdavVolume.visibleProperty());
@@ -120,20 +120,20 @@ public class SettingsController implements ViewController {
prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX);
//FUSE
fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.FUSE));
fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(VolumeImpl.FUSE));
fuseVolume.managedProperty().bind(fuseVolume.visibleProperty());
debugModeCheckbox.setSelected(settings.debugMode().get());
settings.checkForUpdates().bind(checkForUpdatesCheckbox.selectedProperty());
settings.preferredGvfsScheme().bind(prefGvfsScheme.valueProperty());
settings.usedNioAdapterImpl().bind(volume.valueProperty());
settings.volumeImpl().bind(volume.valueProperty());
settings.debugMode().bind(debugModeCheckbox.selectedProperty());
}
//TODO: how to implement this?
private NioAdapterImpl[] getSupportedAdapters() {
return new NioAdapterImpl[]{NioAdapterImpl.FUSE, NioAdapterImpl.WEBDAV};
private VolumeImpl[] getSupportedAdapters() {
return new VolumeImpl[]{VolumeImpl.FUSE, VolumeImpl.WEBDAV};
}
@Override
@@ -175,16 +175,16 @@ public class SettingsController implements ViewController {
return Boolean.parseBoolean(System.getProperty("cryptomator.updatesManagedExternally", "false"));
}
private static class NioAdapterImplStringConverter extends StringConverter<NioAdapterImpl> {
private static class NioAdapterImplStringConverter extends StringConverter<VolumeImpl> {
@Override
public String toString(NioAdapterImpl object) {
return object.name();
public String toString(VolumeImpl object) {
return object.getDisplayName();
}
@Override
public NioAdapterImpl fromString(String string) {
return NioAdapterImpl.valueOf(string);
public VolumeImpl fromString(String string) {
return VolumeImpl.forDisplayName(string);
}
}
@@ -21,7 +21,7 @@ import javafx.beans.binding.Bindings;
import javafx.scene.layout.HBox;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.NioAdapterImpl;
import org.cryptomator.common.settings.VolumeImpl;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.VaultSettings;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
@@ -175,7 +175,7 @@ public class UnlockController implements ViewController {
winDriveLetterLabel.setManaged(false);
winDriveLetter.setVisible(false);
winDriveLetter.setManaged(false);
if(NioAdapterImpl.WEBDAV.equals(settings.usedNioAdapterImpl().get())){
if(VolumeImpl.WEBDAV.equals(settings.volumeImpl().get())){
mountPathLabel.setVisible(false);
mountPathLabel.setManaged(false);
}
@@ -12,7 +12,7 @@ import java.util.Objects;
import javax.inject.Scope;
import org.cryptomator.common.settings.NioAdapterImpl;
import org.cryptomator.common.settings.VolumeImpl;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.VaultSettings;
@@ -44,7 +44,7 @@ public class VaultModule {
@Provides
@PerVault
public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) {
NioAdapterImpl impl = settings.usedNioAdapterImpl().get();
VolumeImpl impl = settings.volumeImpl().get();
switch (impl) {
case WEBDAV:
return webDavVolume;