diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibrary.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibrary.java index 19b28bb55..f4fcb7df7 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibrary.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -403,7 +403,7 @@ private void addCustomizedItem(Class componentClass, String section, private void addItem(String name, String fxmlText, String section, String iconName) { final URL iconURL = ImageUtils.getNodeIconURL(iconName + ".png"); //NOI18N final LibraryItem item = new LibraryItem(name, section, fxmlText, iconURL, this); - itemsProperty.add(item); + getItems().add(item); } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/Library.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/Library.java index 2bebd56eb..9c270327f 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/Library.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/Library.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -39,20 +40,13 @@ import javafx.collections.ObservableList; /** - * - * + * A collection of [LibraryItem]. */ public abstract class Library { - protected final ObservableList itemsProperty - = FXCollections.observableArrayList(); - protected final ObjectProperty classLoaderProperty - = new SimpleObjectProperty<>(); + private final ObservableList itemsProperty = FXCollections.observableArrayList(); + private final ObjectProperty classLoaderProperty = new SimpleObjectProperty<>(); - /* - * Public - */ - public ObservableList getItems() { return itemsProperty; } @@ -60,10 +54,14 @@ public ObservableList getItems() { public ReadOnlyProperty classLoaderProperty() { return classLoaderProperty; } - + public ClassLoader getClassLoader() { return classLoaderProperty.getValue(); } + + protected void setClassLoader(ClassLoader loader) { + classLoaderProperty.set(loader); + } public abstract Comparator getSectionComparator(); } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/user/UserLibrary.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/user/UserLibrary.java index d3a17793e..e31c08438 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/user/UserLibrary.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/user/UserLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Gluon and/or its affiliates. + * Copyright (c) 2017, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -326,17 +326,17 @@ void updateFxmlFileReports(Collection newFxmlFileReports) { void setItems(Collection items) { if (Platform.isFxApplicationThread()) { - itemsProperty.setAll(items); + getItems().setAll(items); } else { - Platform.runLater(() -> itemsProperty.setAll(items)); + Platform.runLater(() -> getItems().setAll(items)); } } void addItems(Collection items) { if (Platform.isFxApplicationThread()) { - itemsProperty.addAll(items); + getItems().addAll(items); } else { - Platform.runLater(() -> itemsProperty.addAll(items)); + Platform.runLater(() -> getItems().addAll(items)); } } @@ -404,7 +404,7 @@ private void changeClassLoader(ClassLoader newClassLoader) { * we invoke URLClassLoader.close() on the existing one * so that it releases its associated jar files. */ - final ClassLoader classLoader = classLoaderProperty.get(); + final ClassLoader classLoader = getClassLoader(); if (classLoader instanceof URLClassLoader) { final URLClassLoader urlClassLoader = (URLClassLoader) classLoader; try { @@ -415,7 +415,7 @@ private void changeClassLoader(ClassLoader newClassLoader) { } // Now moves to the new class loader - classLoaderProperty.set(newClassLoader); + setClassLoader(newClassLoader); } /* diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibraryTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibraryTest.java new file mode 100644 index 000000000..3ce82b8cd --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/library/BuiltinLibraryTest.java @@ -0,0 +1,55 @@ +/* + * 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 and Gluon 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.library; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +public class BuiltinLibraryTest { + + @Test + public void builtin_lib_has_default_items() { + var lib = BuiltinLibrary.getLibrary(); + + assertNull(lib.getClassLoader()); + assertFalse(lib.getItems().isEmpty()); + + for (var item : lib.getItems()) { + assertThat(item.getLibrary()).isEqualTo(lib); + assertFalse(item.getName().isEmpty()); + assertFalse(item.getSection().isEmpty()); + assertFalse(item.getFxmlText().isEmpty()); + } + } +} \ No newline at end of file