mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 18:51:26 +00:00
Hooked up "add vault" wizard
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import javafx.stage.Window;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.FxControllerKey;
|
||||
import org.cryptomator.ui.mainwindow.MainWindow;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowController;
|
||||
import org.cryptomator.ui.mainwindow.VaultDetailController;
|
||||
import org.cryptomator.ui.mainwindow.VaultListController;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import java.util.Map;
|
||||
|
||||
@Module
|
||||
public abstract class AddVaultModule {
|
||||
|
||||
@Provides
|
||||
@AddVaultWizard
|
||||
@AddVaultWizardScoped
|
||||
static FXMLLoaderFactory provideFxmlLoaderFactory(Map<Class<? extends FxController>, Provider<FxController>> factories) {
|
||||
return new FXMLLoaderFactory(factories);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@AddVaultWizard
|
||||
@AddVaultWizardScoped
|
||||
static Stage provideStage(@MainWindow Stage owner) {
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(500);
|
||||
stage.setMinHeight(500);
|
||||
stage.initStyle(StageStyle.DECORATED);
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.initOwner(owner);
|
||||
return stage;
|
||||
}
|
||||
|
||||
// ------------------
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(AddVaultWelcomeController.class)
|
||||
abstract FxController bindWelcomeController(AddVaultWelcomeController controller);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@AddVaultWizardScoped
|
||||
public class AddVaultWelcomeController implements FxController {
|
||||
|
||||
@Inject
|
||||
AddVaultWelcomeController() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface AddVaultWizard {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* 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.ui.addvaultwizard;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
|
||||
@AddVaultWizardScoped
|
||||
@Subcomponent(modules = {AddVaultModule.class})
|
||||
public interface AddVaultWizardComponent {
|
||||
|
||||
@AddVaultWizard
|
||||
Stage window();
|
||||
|
||||
@AddVaultWizard
|
||||
FXMLLoaderFactory fxmlLoaders();
|
||||
|
||||
default void showAddVaultWizard() {
|
||||
Stage stage = window();
|
||||
fxmlLoaders().setScene("/fxml/addvault_welcome.fxml", stage);
|
||||
stage.sizeToScene();
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
|
||||
AddVaultWizardComponent build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import javax.inject.Scope;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Scope
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface AddVaultWizardScoped {
|
||||
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package org.cryptomator.ui.common;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@@ -20,6 +22,9 @@ public class FXMLLoaderFactory {
|
||||
this.resourceBundle = ResourceBundle.getBundle("i18n.strings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A new FXMLLoader instance
|
||||
*/
|
||||
public FXMLLoader construct() {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setControllerFactory(this::constructController);
|
||||
@@ -27,6 +32,12 @@ public class FXMLLoaderFactory {
|
||||
return loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the FXML given fxml resource in a new FXMLLoader instance.
|
||||
* @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}).
|
||||
* @return The FXMLLoader used to load the file
|
||||
* @throws IOException if an error occurs while loading the FXML file
|
||||
*/
|
||||
public FXMLLoader load(String fxmlResourceName) throws IOException {
|
||||
FXMLLoader loader = construct();
|
||||
try (InputStream in = getClass().getResourceAsStream(fxmlResourceName)) {
|
||||
@@ -35,6 +46,23 @@ public class FXMLLoaderFactory {
|
||||
return loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #load(String) Loads} the FXML file and sets the given stage's scene to a new Scene containing the loaded ui.
|
||||
* @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}).
|
||||
* @param stage The stage which should get a new scene
|
||||
* @throws UncheckedIOException wrapping any IOException thrown by {@link #load(String)).
|
||||
*/
|
||||
public void setScene(String fxmlResourceName, Stage stage) throws UncheckedIOException {
|
||||
final FXMLLoader loader;
|
||||
try {
|
||||
loader = load(fxmlResourceName);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to load " + fxmlResourceName, e);
|
||||
} Parent root = loader.getRoot();
|
||||
Scene scene = new Scene(root);
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private FxController constructController(Class<?> aClass) {
|
||||
if (!factories.containsKey(aClass)) {
|
||||
throw new IllegalArgumentException("ViewController not registered: " + aClass);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface MainWindow {
|
||||
|
||||
}
|
||||
@@ -6,33 +6,23 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@MainWindowScoped
|
||||
@Subcomponent(modules = {MainWindowModule.class})
|
||||
public interface MainWindowComponent {
|
||||
|
||||
Stage mainWindow();
|
||||
@MainWindow
|
||||
Stage window();
|
||||
|
||||
@MainWindow
|
||||
FXMLLoaderFactory fxmlLoaders();
|
||||
|
||||
default void showMainWindow() {
|
||||
try {
|
||||
Parent root = fxmlLoaders().load("/fxml/main_window.fxml").getRoot();
|
||||
Stage stage = mainWindow();
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to load main_window.fxml", e);
|
||||
}
|
||||
Stage stage = window();
|
||||
fxmlLoaders().setScene("/fxml/main_window.fxml", stage);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Subcomponent.Builder
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MainWindowController implements FxController {
|
||||
private double yOffset;
|
||||
|
||||
@Inject
|
||||
public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, Stage window, FxApplication application) {
|
||||
public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, @MainWindow Stage window, FxApplication application) {
|
||||
this.shutdownLatch = shutdownLatch;
|
||||
this.window = window;
|
||||
this.application = application;
|
||||
|
||||
@@ -6,6 +6,7 @@ import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.FxControllerKey;
|
||||
@@ -13,16 +14,18 @@ import org.cryptomator.ui.common.FxControllerKey;
|
||||
import javax.inject.Provider;
|
||||
import java.util.Map;
|
||||
|
||||
@Module
|
||||
@Module(subcomponents = {AddVaultWizardComponent.class})
|
||||
public abstract class MainWindowModule {
|
||||
|
||||
@Provides
|
||||
@MainWindow
|
||||
@MainWindowScoped
|
||||
static FXMLLoaderFactory provideFxmlLoaderFactory(Map<Class<? extends FxController>, Provider<FxController>> factories) {
|
||||
return new FXMLLoaderFactory(factories);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@MainWindow
|
||||
@MainWindowScoped
|
||||
static Stage provideStage() {
|
||||
Stage stage = new Stage();
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.cryptomator.ui.mainwindow;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
|
||||
@@ -16,13 +16,15 @@ public class VaultListController implements FxController {
|
||||
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final ObjectProperty<Vault> selectedVault;
|
||||
private final AddVaultWizardComponent.Builder addVaultWizard;
|
||||
public ListView vaultList;
|
||||
public AnchorPane onboardingOverlay;
|
||||
|
||||
@Inject
|
||||
public VaultListController(ObservableList<Vault> vaults, ObjectProperty<Vault> selectedVault) {
|
||||
VaultListController(ObservableList<Vault> vaults, ObjectProperty<Vault> selectedVault, AddVaultWizardComponent.Builder addVaultWizard) {
|
||||
this.vaults = vaults;
|
||||
this.selectedVault = selectedVault;
|
||||
this.addVaultWizard = addVaultWizard;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
@@ -31,9 +33,10 @@ public class VaultListController implements FxController {
|
||||
selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty());
|
||||
}
|
||||
|
||||
public void didClickAddVault(ActionEvent actionEvent) {
|
||||
public void didClickAddVault() {
|
||||
addVaultWizard.build().showAddVaultWizard();
|
||||
}
|
||||
|
||||
public void didClickRemoveVault(ActionEvent actionEvent) {
|
||||
public void didClickRemoveVault() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,32 +6,23 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowModule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@PreferencesScoped
|
||||
@Subcomponent(modules = {PreferencesModule.class})
|
||||
public interface PreferencesComponent {
|
||||
|
||||
Stage preferencesWindow();
|
||||
@PreferencesWindow
|
||||
Stage window();
|
||||
|
||||
@PreferencesWindow
|
||||
FXMLLoaderFactory fxmlLoaders();
|
||||
|
||||
default void showPreferencesWindow() {
|
||||
try {
|
||||
Parent root = fxmlLoaders().load("/fxml/preferences.fxml").getRoot();
|
||||
Stage stage = preferencesWindow();
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to load main_window.fxml", e);
|
||||
}
|
||||
Stage stage = window();
|
||||
fxmlLoaders().setScene("/fxml/preferences.fxml", stage);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Subcomponent.Builder
|
||||
|
||||
@@ -17,12 +17,14 @@ import java.util.Map;
|
||||
public abstract class PreferencesModule {
|
||||
|
||||
@Provides
|
||||
@PreferencesWindow
|
||||
@PreferencesScoped
|
||||
static FXMLLoaderFactory provideFxmlLoaderFactory(Map<Class<? extends FxController>, Provider<FxController>> factories) {
|
||||
return new FXMLLoaderFactory(factories);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@PreferencesWindow
|
||||
@PreferencesScoped
|
||||
static Stage provideStage() {
|
||||
Stage stage = new Stage();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface PreferencesWindow {
|
||||
|
||||
}
|
||||
12
main/ui/src/main/resources/fxml/addvault_welcome.fxml
Normal file
12
main/ui/src/main/resources/fxml/addvault_welcome.fxml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.addvaultwizard.AddVaultWelcomeController"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
|
||||
<Label text="TODO new vault or existing vault?"/>
|
||||
|
||||
</AnchorPane>
|
||||
Reference in New Issue
Block a user