From 2e591128a756ae6ba7dd5ae9f630a9fdf3d58f9f Mon Sep 17 00:00:00 2001 From: Almas Baimagambetov Date: Sun, 20 Feb 2022 17:11:08 +0000 Subject: [PATCH] refactor: Removed null field and logic from Template enum (#516) --- .../scenebuilder/app/SceneBuilderApp.java | 10 ++-- .../scenebuilder/kit/template/Template.java | 22 +-------- .../kit/template/EmptyApplication.fxml | 0 .../kit/template/TemplateTest.java | 47 +++++++++++++++++++ 4 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 kit/src/main/resources/com/oracle/javafx/scenebuilder/kit/template/EmptyApplication.fxml create mode 100644 kit/src/test/java/com/oracle/javafx/scenebuilder/kit/template/TemplateTest.java diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/SceneBuilderApp.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/SceneBuilderApp.java index 7c285949b..291a16fd5 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/SceneBuilderApp.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/SceneBuilderApp.java @@ -626,11 +626,13 @@ private void performNewTemplateInNewWindow(Template template) { } private void loadTemplateInWindow(Template template, DocumentWindowController documentWindowController) { - final URL url = template.getFXMLURL(); - if (url != null) { - documentWindowController.loadFromURL(url, template.getType() != Type.PHONE); + documentWindowController.loadFromURL(template.getFXMLURL(), template.getType() != Type.PHONE); + + if (template.getType() == Type.PHONE) { + documentWindowController.getEditorController().performEditAction(EditorController.EditAction.SET_SIZE_335x600); + documentWindowController.getEditorController().setTheme(EditorPlatform.Theme.GLUON_MOBILE_LIGHT); } - Template.prepareDocument(documentWindowController.getEditorController(), template); + documentWindowController.openWindow(); } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/template/Template.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/template/Template.java index 00f9b32a5..11e655c93 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/template/Template.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/template/Template.java @@ -32,9 +32,6 @@ package com.oracle.javafx.scenebuilder.kit.template; -import com.oracle.javafx.scenebuilder.kit.editor.EditorController; -import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; - import java.net.URL; import static com.oracle.javafx.scenebuilder.kit.template.Type.DESKTOP; @@ -42,7 +39,7 @@ public enum Template { - EMPTY_APP(DESKTOP, null), + EMPTY_APP(DESKTOP, "EmptyApplication.fxml"), BASIC_DESKTOP_APP (DESKTOP, "BasicDesktopApplication.fxml"), COMPLEX_DESKTOP_APP (DESKTOP, "ComplexDesktopApplication.fxml"), EMPTY_PHONE_APP (PHONE, "EmptyPhoneApplication.fxml"), @@ -60,22 +57,7 @@ public Type getType() { return type; } - public String getFXMLFileName() { - return fxmlFileName; - } - public URL getFXMLURL() { - final String name = getFXMLFileName(); - if (name == null) { - return null; - } - return Template.class.getResource(name); - } - - public static void prepareDocument(EditorController editorController, Template template) { - if (template.getType() == Type.PHONE) { - editorController.performEditAction(EditorController.EditAction.SET_SIZE_335x600); - editorController.setTheme(EditorPlatform.Theme.GLUON_MOBILE_LIGHT); - } + return Template.class.getResource(fxmlFileName); } } diff --git a/kit/src/main/resources/com/oracle/javafx/scenebuilder/kit/template/EmptyApplication.fxml b/kit/src/main/resources/com/oracle/javafx/scenebuilder/kit/template/EmptyApplication.fxml new file mode 100644 index 000000000..e69de29bb diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/template/TemplateTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/template/TemplateTest.java new file mode 100644 index 000000000..a2140eb14 --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/template/TemplateTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022, Gluon and/or its affiliates. + * All rights reserved. Use is subject to license terms. + * + * This file is available and licensed under the following license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of Oracle Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.javafx.scenebuilder.kit.template; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static org.junit.jupiter.api.Assertions.*; + +public class TemplateTest { + + @ParameterizedTest + @EnumSource(Template.class) + public void template_fields_are_not_null(Template template) { + assertNotNull(template.getType()); + assertNotNull(template.getFXMLURL()); + } +} \ No newline at end of file