mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-19 22:44:32 +00:00
Using enum instead of string to choose between FUSE and WebDAV
This commit is contained in:
@@ -16,6 +16,7 @@ import javax.inject.Singleton;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.StringConverter;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.ui.l10n.Localization;
|
||||
@@ -35,6 +36,7 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
@Singleton
|
||||
public class SettingsController implements ViewController {
|
||||
@@ -83,7 +85,7 @@ public class SettingsController implements ViewController {
|
||||
private Label volumeLabel;
|
||||
|
||||
@FXML
|
||||
private ChoiceBox<String> volume;
|
||||
private ChoiceBox<NioAdapterImpl> volume;
|
||||
|
||||
@FXML
|
||||
private CheckBox debugModeCheckbox;
|
||||
@@ -101,11 +103,10 @@ public class SettingsController implements ViewController {
|
||||
volume.getItems().addAll(getSupportedAdapters());
|
||||
volume.setValue(settings.usedNioAdapterImpl().get());
|
||||
volume.setVisible(true);
|
||||
volume.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends String> observable, String oldVal, String newVal) -> changeNioView(newVal));
|
||||
|
||||
volume.setConverter(new NioAdapterImplStringConverter());
|
||||
|
||||
//WEBDAV
|
||||
webdavVolume.setVisible(settings.usedNioAdapterImpl().getValue().equals(NioAdapterImpl.WEBDAV.name()));
|
||||
webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.WEBDAV));
|
||||
webdavVolume.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
prefGvfsScheme.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
prefGvfsSchemeLabel.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
@@ -123,7 +124,7 @@ public class SettingsController implements ViewController {
|
||||
prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX);
|
||||
|
||||
//FUSE
|
||||
fuseVolume.setVisible(settings.usedNioAdapterImpl().getValue().equals(NioAdapterImpl.FUSE.name()));
|
||||
fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.FUSE));
|
||||
fuseVolume.managedProperty().bind(fuseVolume.visibleProperty());
|
||||
|
||||
debugModeCheckbox.setSelected(settings.debugMode().get());
|
||||
@@ -135,13 +136,8 @@ public class SettingsController implements ViewController {
|
||||
}
|
||||
|
||||
//TODO: how to implement this?
|
||||
private String[] getSupportedAdapters() {
|
||||
return new String[]{NioAdapterImpl.FUSE.name(), NioAdapterImpl.WEBDAV.name()};
|
||||
}
|
||||
|
||||
private void changeNioView(String newVal) {
|
||||
fuseVolume.setVisible(newVal.equalsIgnoreCase(NioAdapterImpl.FUSE.name()));
|
||||
webdavVolume.setVisible(newVal.equalsIgnoreCase(NioAdapterImpl.WEBDAV.name()));
|
||||
private NioAdapterImpl[] getSupportedAdapters() {
|
||||
return new NioAdapterImpl[]{NioAdapterImpl.FUSE, NioAdapterImpl.WEBDAV};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,4 +179,17 @@ public class SettingsController implements ViewController {
|
||||
return Boolean.parseBoolean(System.getProperty("cryptomator.updatesManagedExternally", "false"));
|
||||
}
|
||||
|
||||
private static class NioAdapterImplStringConverter extends StringConverter<NioAdapterImpl> {
|
||||
|
||||
@Override
|
||||
public String toString(NioAdapterImpl object) {
|
||||
return object.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NioAdapterImpl fromString(String string) {
|
||||
return NioAdapterImpl.valueOf(string);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class UnlockController implements ViewController {
|
||||
winDriveLetterLabel.setManaged(false);
|
||||
winDriveLetter.setVisible(false);
|
||||
winDriveLetter.setManaged(false);
|
||||
if(settings.usedNioAdapterImpl().isEqualTo(NioAdapterImpl.WEBDAV.name()).get()){
|
||||
if(NioAdapterImpl.WEBDAV.equals(settings.usedNioAdapterImpl().get())){
|
||||
mountPathLabel.setVisible(false);
|
||||
mountPathLabel.setManaged(false);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,14 @@ public class VaultModule {
|
||||
@Provides
|
||||
@PerVault
|
||||
public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) {
|
||||
NioAdapterImpl impl = NioAdapterImpl.valueOf(settings.usedNioAdapterImpl().get());
|
||||
NioAdapterImpl impl = settings.usedNioAdapterImpl().get();
|
||||
switch (impl) {
|
||||
case WEBDAV:
|
||||
return webDavVolume;
|
||||
case FUSE:
|
||||
return fuseVolume;
|
||||
default:
|
||||
//this should not happen!
|
||||
throw new IllegalStateException("Unsupported NioAdapter: " + settings.usedNioAdapterImpl().get());
|
||||
throw new IllegalStateException("Unsupported NioAdapter: " + impl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user