Search in sources :

Example 1 with ConfigurationStorage

use of com.thecoderscorner.menu.editorui.storage.ConfigurationStorage in project tcMenu by davetcc.

the class AboutDialogTestCases method onStart.

@Start
public void onStart(Stage stage) {
    this.stage = stage;
    ConfigurationStorage storage = mock(ConfigurationStorage.class);
    when(storage.getRegisteredKey()).thenReturn("UnitTesterII");
    when(storage.getVersion()).thenReturn("V1.0.2");
    when(storage.getBuildTimestamp()).thenReturn("20/10/2018 09:30");
    new AboutDialog(storage, stage, false);
}
Also used : AboutDialog(com.thecoderscorner.menu.editorui.dialog.AboutDialog) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) Start(org.testfx.framework.junit5.Start)

Example 2 with ConfigurationStorage

use of com.thecoderscorner.menu.editorui.storage.ConfigurationStorage in project tcMenu by davetcc.

the class MenuEditorTestCases method onStart.

@Start
public void onStart(Stage stage) throws Exception {
    dirHelper.initialise();
    dirHelper.createSketch(TCMENU_DIR, "exampleSketch1", true);
    dirHelper.createSketch(TCMENU_DIR, "exampleSketch2", true);
    var sketch1 = dirHelper.createSketch(SKETCHES_DIR, "sketches1", true);
    var sketch2 = dirHelper.createSketch(SKETCHES_DIR, "sketches2", true);
    dirHelper.createSketch(SKETCHES_DIR, "sketchesIgnore", false);
    // load the main window FXML
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/menuEditor.fxml"));
    Pane myPane = loader.load();
    // we need to mock a few things around the edges to make testing easier.
    editorProjectUI = mock(CurrentProjectEditorUI.class);
    when(editorProjectUI.createPanelForMenuItem(any(), any(), any(), any())).thenReturn(Optional.empty());
    persistor = mock(ProjectPersistor.class);
    installer = mock(ArduinoLibraryInstaller.class);
    simulatedCodeManager = mock(CodePluginManager.class);
    when(simulatedCodeManager.getLoadedPlugins()).thenReturn(Collections.singletonList(generateCodePluginConfig()));
    setUpInstallerLibVersions();
    // create a basic project, that has a few menu items in it.
    project = new CurrentEditorProject(editorProjectUI, persistor, mock(ConfigurationStorage.class));
    ConfigurationStorage storage = mock(ConfigurationStorage.class);
    when(storage.loadRecents()).thenReturn(List.of(sketch1.orElseThrow(), sketch2.orElseThrow(), "filesDoesNotExistRemove.emf"));
    when(storage.getRegisteredKey()).thenReturn("UnitTesterII");
    when(storage.isUsingArduinoIDE()).thenReturn(true);
    when(storage.getArduinoOverrideDirectory()).thenReturn(Optional.empty());
    // both versions same, do not invoke splash screen.
    when(storage.getVersion()).thenReturn("1.1.1");
    when(storage.getLastRunVersion()).thenReturn(new VersionInfo("1.1.1"));
    // set up the controller and stage..
    MenuEditorController controller = loader.getController();
    libDetector = mock(LibraryVersionDetector.class);
    when(libDetector.getReleaseType()).thenReturn(ReleaseType.STABLE);
    controller.initialise(project, installer, editorProjectUI, simulatedCodeManager, storage, libDetector);
    this.stage = stage;
    when(libDetector.availableVersionsAreValid(anyBoolean())).thenReturn(true);
    Scene myScene = new Scene(myPane);
    stage.setScene(myScene);
    stage.show();
}
Also used : LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) MenuEditorController(com.thecoderscorner.menu.editorui.controller.MenuEditorController) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) Pane(javafx.scene.layout.Pane) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) Start(org.testfx.framework.junit5.Start)

Example 3 with ConfigurationStorage

use of com.thecoderscorner.menu.editorui.storage.ConfigurationStorage in project tcMenu by davetcc.

the class MenuEditorApp method start.

@Override
public void start(Stage primaryStage) throws Exception {
    startUpLogging();
    Platform.runLater(() -> {
        final String os = System.getProperty("os.name");
        if (os != null && os.startsWith("Mac")) {
            Desktop desktop = Desktop.getDesktop();
            desktop.setAboutHandler(e -> Platform.runLater(() -> controller.aboutMenuPressed(new ActionEvent())));
            desktop.setQuitStrategy(QuitStrategy.NORMAL_EXIT);
        }
    });
    ConfigurationStorage prefsStore = new PrefsConfigurationStorage();
    createOrUpdateDirectoriesAsNeeded(prefsStore);
    primaryStage.setTitle("Embedded Menu Designer");
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/menuEditor.fxml"));
    Pane myPane = loader.load();
    controller = loader.getController();
    var stream = Preferences.userNodeForPackage(MenuEditorApp.class).get("ReleaseStream", ReleaseType.STABLE.toString());
    var httpClient = new SimpleHttpClient();
    var urlBase = "https://www.thecoderscorner.com";
    if (System.getProperty("localTccService") != null) {
        urlBase = System.getProperty("localTccService");
        System.getLogger("Main").log(WARNING, "Overriding the TCC service to " + urlBase);
    }
    LibraryVersionDetector libraryVersionDetector = new OnlineLibraryVersionDetector(urlBase, httpClient, ReleaseType.valueOf(stream));
    PluginEmbeddedPlatformsImpl platforms = new PluginEmbeddedPlatformsImpl();
    DefaultXmlPluginLoader manager = new DefaultXmlPluginLoader(platforms, prefsStore, true);
    ArduinoLibraryInstaller installer = new ArduinoLibraryInstaller(libraryVersionDetector, manager, prefsStore);
    platforms.setInstallerConfiguration(installer, prefsStore);
    manager.loadPlugins();
    var homeDirectory = System.getProperty("homeDirectoryOverride", System.getProperty("user.home"));
    var editorUI = new CurrentProjectEditorUIImpl(manager, primaryStage, platforms, installer, prefsStore, libraryVersionDetector, homeDirectory);
    FileBasedProjectPersistor persistor = new FileBasedProjectPersistor();
    CurrentEditorProject project = new CurrentEditorProject(editorUI, persistor, prefsStore);
    editorUI.setEditorProject(project);
    controller.initialise(project, installer, editorUI, manager, prefsStore, libraryVersionDetector);
    Scene myScene = new Scene(myPane);
    BaseDialogSupport.getJMetro().setScene(myScene);
    primaryStage.setScene(myScene);
    primaryStage.show();
    primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/img/menu-icon-sm.png"))));
    primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/img/menu-icon.png"))));
    primaryStage.setOnCloseRequest((evt) -> {
        try {
            var streamStr = libraryVersionDetector.getReleaseType().toString();
            Preferences.userNodeForPackage(MenuEditorApp.class).put("ReleaseStream", streamStr);
            controller.persistPreferences();
            if (project.isDirty()) {
                evt.consume();
                Alert alert = new Alert(AlertType.CONFIRMATION, "There are unsaved changes, save first?", ButtonType.YES, ButtonType.NO);
                BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
                alert.setTitle("Are you sure");
                alert.setHeaderText("");
                if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.YES) {
                    project.saveProject(CurrentEditorProject.EditorSaveMode.SAVE);
                }
            }
        } catch (Exception ex) {
        // ignored, we are trying to shutdown so just proceeed anyway.
        }
        Platform.exit();
        System.exit(0);
    });
}
Also used : LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) OnlineLibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector) OnlineLibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector) ActionEvent(javafx.event.ActionEvent) DefaultXmlPluginLoader(com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader) Scene(javafx.scene.Scene) Image(javafx.scene.image.Image) FXMLLoader(javafx.fxml.FXMLLoader) Pane(javafx.scene.layout.Pane) FileBasedProjectPersistor(com.thecoderscorner.menu.editorui.project.FileBasedProjectPersistor) IOException(java.io.IOException) PluginEmbeddedPlatformsImpl(com.thecoderscorner.menu.editorui.generator.plugin.PluginEmbeddedPlatformsImpl) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) PrefsConfigurationStorage(com.thecoderscorner.menu.editorui.storage.PrefsConfigurationStorage) CurrentProjectEditorUIImpl(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUIImpl) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) Alert(javafx.scene.control.Alert) PrefsConfigurationStorage(com.thecoderscorner.menu.editorui.storage.PrefsConfigurationStorage) SimpleHttpClient(com.thecoderscorner.menu.editorui.util.SimpleHttpClient) CurrentEditorProject(com.thecoderscorner.menu.editorui.project.CurrentEditorProject)

Example 4 with ConfigurationStorage

use of com.thecoderscorner.menu.editorui.storage.ConfigurationStorage in project tcMenu by davetcc.

the class UIMenuItemTestBase method init.

@SuppressWarnings("unchecked")
protected void init(Stage stage) {
    manager = mock(CodePluginManager.class);
    ConfigurationStorage storage = mock(ConfigurationStorage.class);
    editorUI = new CurrentProjectEditorUIImpl(manager, stage, mock(EmbeddedPlatforms.class), mock(ArduinoLibraryInstaller.class), storage, mock(LibraryVersionDetector.class), System.getProperty("user.home"));
    menuTree = TestUtils.buildCompleteTree();
    mockedConsumer = mock(BiConsumer.class);
    this.stage = stage;
    dialogPane = new DialogPane();
    dialogPane.setMinSize(500, 500);
    stage.setScene(new Scene(dialogPane));
}
Also used : DialogPane(javafx.scene.control.DialogPane) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) CurrentProjectEditorUIImpl(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUIImpl) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) Scene(javafx.scene.Scene) BiConsumer(java.util.function.BiConsumer)

Aggregations

ConfigurationStorage (com.thecoderscorner.menu.editorui.storage.ConfigurationStorage)4 Scene (javafx.scene.Scene)3 LibraryVersionDetector (com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector)2 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)2 CodePluginManager (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager)2 CurrentProjectEditorUIImpl (com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUIImpl)2 FXMLLoader (javafx.fxml.FXMLLoader)2 Pane (javafx.scene.layout.Pane)2 Start (org.testfx.framework.junit5.Start)2 MenuEditorController (com.thecoderscorner.menu.editorui.controller.MenuEditorController)1 AboutDialog (com.thecoderscorner.menu.editorui.dialog.AboutDialog)1 OnlineLibraryVersionDetector (com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector)1 DefaultXmlPluginLoader (com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader)1 PluginEmbeddedPlatformsImpl (com.thecoderscorner.menu.editorui.generator.plugin.PluginEmbeddedPlatformsImpl)1 CurrentEditorProject (com.thecoderscorner.menu.editorui.project.CurrentEditorProject)1 FileBasedProjectPersistor (com.thecoderscorner.menu.editorui.project.FileBasedProjectPersistor)1 PrefsConfigurationStorage (com.thecoderscorner.menu.editorui.storage.PrefsConfigurationStorage)1 CurrentProjectEditorUI (com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI)1 SimpleHttpClient (com.thecoderscorner.menu.editorui.util.SimpleHttpClient)1 VersionInfo (com.thecoderscorner.menu.persist.VersionInfo)1