Parcourir la source

make eventView independent, but singleton window

Armin Schrenk il y a 4 mois
Parent
commit
74ef8d915d

+ 4 - 4
src/main/java/org/cryptomator/ui/eventview/EventViewComponent.java

@@ -1,12 +1,10 @@
 package org.cryptomator.ui.eventview;
 
-import dagger.BindsInstance;
 import dagger.Lazy;
 import dagger.Subcomponent;
 import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlScene;
 
-import javax.inject.Named;
 import javafx.scene.Scene;
 import javafx.stage.Stage;
 
@@ -20,16 +18,18 @@ public interface EventViewComponent {
 	@FxmlScene(FxmlFile.EVENT_VIEW)
 	Lazy<Scene> scene();
 
-	default void showEventViewerWindow() {
+	default Stage showEventViewerWindow() {
 		Stage stage = window();
 		stage.setScene(scene().get());
 		stage.sizeToScene();
 		stage.show();
+		stage.requestFocus();
+		return stage;
 	}
 
 	@Subcomponent.Factory
 	interface Factory {
 
-		EventViewComponent create(@BindsInstance @Named("owner") Stage owner);
+		EventViewComponent create();
 	}
 }

+ 1 - 3
src/main/java/org/cryptomator/ui/eventview/EventViewModule.java

@@ -12,7 +12,6 @@ import org.cryptomator.ui.common.FxmlLoaderFactory;
 import org.cryptomator.ui.common.FxmlScene;
 import org.cryptomator.ui.common.StageFactory;
 
-import javax.inject.Named;
 import javax.inject.Provider;
 import javafx.scene.Scene;
 import javafx.stage.Modality;
@@ -26,12 +25,11 @@ abstract class EventViewModule {
 	@Provides
 	@EventViewScoped
 	@EventViewWindow
-	static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle, @Named("owner") Stage owner) {
+	static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle) {
 		Stage stage = factory.create();
 		stage.setTitle("TODO EVENTVIEWER");
 		stage.setResizable(true);
 		stage.initModality(Modality.NONE);
-		stage.initOwner(owner);
 		return stage;
 	}
 

+ 6 - 0
src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java

@@ -68,4 +68,10 @@ abstract class FxApplicationModule {
 		return builder.build();
 	}
 
+	@Provides
+	@FxApplicationScoped
+	static EventViewComponent provideEventViewComponent(EventViewComponent.Factory factory) {
+		return factory.create();
+	}
+
 }

+ 7 - 13
src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java

@@ -52,7 +52,7 @@ public class FxApplicationWindows {
 	private final UpdateReminderComponent.Factory updateReminderWindowFactory;
 	private final LockComponent.Factory lockWorkflowFactory;
 	private final ErrorComponent.Factory errorWindowFactory;
-	private final EventViewComponent.Factory eventViewWindow;
+	private final Lazy<EventViewComponent> eventViewWindow;
 	private final ExecutorService executor;
 	private final VaultOptionsComponent.Factory vaultOptionsWindow;
 	private final ShareVaultComponent.Factory shareVaultWindow;
@@ -71,7 +71,7 @@ public class FxApplicationWindows {
 								ErrorComponent.Factory errorWindowFactory, //
 								VaultOptionsComponent.Factory vaultOptionsWindow, //
 								ShareVaultComponent.Factory shareVaultWindow, //
-								EventViewComponent.Factory eventViewWindow, //
+								Lazy<EventViewComponent> eventViewWindow, //
 								ExecutorService executor, //
 								Dialogs dialogs) {
 		this.primaryStage = primaryStage;
@@ -186,6 +186,11 @@ public class FxApplicationWindows {
 				});
 	}
 
+
+	public CompletionStage<Stage> showEventViewer() {
+		return CompletableFuture.supplyAsync(() -> eventViewWindow.get().showEventViewerWindow(), Platform::runLater).whenComplete(this::reportErrors);
+	}
+
 	/**
 	 * Displays the generic error scene in the given window.
 	 *
@@ -203,15 +208,4 @@ public class FxApplicationWindows {
 			LOG.error("Failed to display stage", error);
 		}
 	}
-
-	public CompletionStage<Object> showEventViewer(@Nullable Stage owner) {
-		return CompletableFuture.supplyAsync(() -> {
-			eventViewWindow.create(owner).showEventViewerWindow();
-			return null;
-		}, Platform::runLater).exceptionally(t -> {
-			LOG.error("Unable to display event viewer.", t);
-
-			return null;
-		});
-	}
 }

+ 1 - 1
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java

@@ -266,7 +266,7 @@ public class VaultListController implements FxController {
 
 	@FXML
 	public void showEventViewer() {
-		appWindows.showEventViewer(mainWindow);
+		appWindows.showEventViewer();
 	}
 	// Getter and Setter