From 8f48abba0227728d820861b1c167b0f566320d85 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Mon, 3 Oct 2022 00:32:30 +0200 Subject: [PATCH] fix: Allows Scene Builder conditionally to load FXML files with unresolved imports. There is also a new option (preserve unresolved imports) which also allows to keep the imports in saved FXML files. --- .../app/DocumentWindowController.java | 9 ++- .../preferences/PreferencesRecordGlobal.java | 17 +++++- .../PreferencesWindowController.java | 18 +++++- .../app/i18n/SceneBuilderApp.properties | 1 + .../app/preferences/Preferences.fxml | 61 +++++++++++-------- .../kit/editor/EditorController.java | 12 ++-- .../scenebuilder/kit/fxom/FXOMDocument.java | 36 +++++++++-- .../scenebuilder/kit/fxom/FXOMLoader.java | 34 ++++++++++- .../scenebuilder/kit/fxom/FXOMSaver.java | 11 +++- .../kit/fxom/glue/GlueInstruction.java | 5 ++ .../PreferencesControllerBase.java | 3 +- 11 files changed, 164 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java index 46668a048..74ad1d104 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java @@ -67,6 +67,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup; import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMNodes; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; import com.oracle.javafx.scenebuilder.kit.library.Library; @@ -395,7 +396,13 @@ public SplitController getDocumentSplitController() { public void loadFromFile(File fxmlFile) throws IOException { final URL fxmlURL = fxmlFile.toURI().toURL(); final String fxmlText = FXOMDocument.readContentFromURL(fxmlURL); - editorController.setFxmlTextAndLocation(fxmlText, fxmlURL, false); + + FXOMDocumentSwitch[] options = PreferencesController.getSingleton().getRecordGlobal() + .isPreserveUnresolvedImports() + ? new FXOMDocumentSwitch[] {FXOMDocumentSwitch.PRESERVE_UNRESOLVED_IMPORTS} + : new FXOMDocumentSwitch[0]; + + editorController.setFxmlTextAndLocation(fxmlText, fxmlURL, false, options); updateLoadFileTime(); updateStageTitle(); // No-op if fxml has not been loaded yet updateFromDocumentPreferences(true); diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesRecordGlobal.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesRecordGlobal.java index c5c2fce3f..c8155efad 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesRecordGlobal.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesRecordGlobal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, 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. * @@ -98,6 +98,7 @@ public String toString() { static final int DEFAULT_RECENT_ITEMS_SIZE = 15; static final boolean DEFAULT_ACCORDION_ANIMATION = true; static final boolean DEFAULT_WILDCARD_IMPORTS = false; + static final boolean DEFAULT_PRESERVE_UNRESOLVED_IMPORTS = true; /*************************************************************************** * * @@ -113,6 +114,7 @@ public String toString() { private int recentItemsSize = DEFAULT_RECENT_ITEMS_SIZE; private boolean accordionAnimation = DEFAULT_ACCORDION_ANIMATION; private boolean wildcardImports = DEFAULT_WILDCARD_IMPORTS; + private boolean preserveUnresolvedImports = DEFAULT_PRESERVE_UNRESOLVED_IMPORTS; private final List recentItems = new ArrayList<>(); private LocalDate showUpdateDialogDate = null; @@ -382,6 +384,14 @@ public void setWildcardImports(boolean wildcardImports) { this.wildcardImports = wildcardImports; } + public boolean isPreserveUnresolvedImports() { + return this.preserveUnresolvedImports; + } + + public void setPreserveUnresolvedImports(boolean preserveUnresolvedImports) { + this.preserveUnresolvedImports = preserveUnresolvedImports; + } + /** * Read data from the java preferences DB and initialize properties. */ @@ -468,7 +478,7 @@ public void readFromJavaPreferences() { // Wildcard imports setWildcardImports(applicationRootPreferences.getBoolean(WILDCARD_IMPORT, DEFAULT_WILDCARD_IMPORTS)); - + setPreserveUnresolvedImports(applicationRootPreferences.getBoolean(PRESERVE_UNRESOLVED_IMPORTS, DEFAULT_PRESERVE_UNRESOLVED_IMPORTS)); } public void writeToJavaPreferences(String key) { @@ -535,6 +545,9 @@ public void writeToJavaPreferences(String key) { case WILDCARD_IMPORT: applicationRootPreferences.putBoolean(WILDCARD_IMPORT, isWildcardImports()); break; + case PRESERVE_UNRESOLVED_IMPORTS: + applicationRootPreferences.putBoolean(PRESERVE_UNRESOLVED_IMPORTS, isPreserveUnresolvedImports()); + break; default: super.writeToJavaPreferences(key); break; diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesWindowController.java index fb7564e5f..b45aec5ca 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/preferences/PreferencesWindowController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, 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. * @@ -53,6 +53,7 @@ import static com.oracle.javafx.scenebuilder.app.preferences.PreferencesController.RECENT_ITEMS_SIZE; import static com.oracle.javafx.scenebuilder.app.preferences.PreferencesController.TOOL_THEME; import static com.oracle.javafx.scenebuilder.app.preferences.PreferencesController.WILDCARD_IMPORT; +import static com.oracle.javafx.scenebuilder.app.preferences.PreferencesController.PRESERVE_UNRESOLVED_IMPORTS; import static com.oracle.javafx.scenebuilder.kit.preferences.PreferencesRecordGlobalBase.DEFAULT_ALIGNMENT_GUIDES_COLOR; import static com.oracle.javafx.scenebuilder.kit.preferences.PreferencesRecordGlobalBase.DEFAULT_BACKGROUND_IMAGE; @@ -139,6 +140,8 @@ public class PreferencesWindowController extends AbstractFxmlWindowController { private CheckBox animateAccordion; @FXML private CheckBox wildcardImports; + @FXML + private CheckBox preserveUnresolvedImports; private PaintPicker alignmentColorPicker; private PaintPicker parentRingColorPicker; @@ -259,6 +262,9 @@ protected void controllerDidLoadFxml() { // Wildcard Imports wildcardImports.setSelected(recordGlobal.isWildcardImports()); wildcardImports.selectedProperty().addListener(new WildcardImportListener()); + + preserveUnresolvedImports.setSelected(recordGlobal.isPreserveUnresolvedImports()); + preserveUnresolvedImports.selectedProperty().addListener(new PreserveUnresolvedImportListener()); } /* @@ -576,4 +582,14 @@ public void changed(ObservableValue observable, Boolean oldVa recordGlobal.writeToJavaPreferences(WILDCARD_IMPORT); } } + + private static class PreserveUnresolvedImportListener implements ChangeListener { + @Override + public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { + final PreferencesController preferencesController = PreferencesController.getSingleton(); + final PreferencesRecordGlobal recordGlobal = preferencesController.getRecordGlobal(); + recordGlobal.setPreserveUnresolvedImports(newValue); + recordGlobal.writeToJavaPreferences(PRESERVE_UNRESOLVED_IMPORTS); + } + } } diff --git a/app/src/main/resources/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties b/app/src/main/resources/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties index 761a6db8d..aab0c718d 100644 --- a/app/src/main/resources/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties +++ b/app/src/main/resources/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties @@ -249,6 +249,7 @@ prefs.cssanalyzer.columns.defaults.last = "Defaults" Column Last prefs.recent.items = Recent items : prefs.animate.accordion = Animate Accordion : prefs.wildcard.import = Use Wildcard Imports : +prefs.preserve.unresolved.import = Keep unresolved imports : prefs.reset.default = Reset to Builtin Default Values prefs.document.theme = Default Theme : prefs.document.gluonswatch = Default Gluon Swatch : diff --git a/app/src/main/resources/com/oracle/javafx/scenebuilder/app/preferences/Preferences.fxml b/app/src/main/resources/com/oracle/javafx/scenebuilder/app/preferences/Preferences.fxml index e9b02f042..0129a30e8 100644 --- a/app/src/main/resources/com/oracle/javafx/scenebuilder/app/preferences/Preferences.fxml +++ b/app/src/main/resources/com/oracle/javafx/scenebuilder/app/preferences/Preferences.fxml @@ -37,19 +37,19 @@ - - + + - - - + + + - + - +