changeset 7769:bbe230959561

[SCENEBUILDER] Added preserveCloneeFxId mode to FXOMCloner.
author Eric Le Ponner <eric.le.ponner@oracle.com>
date Fri, 22 Aug 2014 14:27:06 +0200
parents 9b0ba231846e
children 92969d8fa8b7
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCloner.java
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCloner.java	Fri Aug 22 11:36:16 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCloner.java	Fri Aug 22 14:27:06 2014 +0200
@@ -56,6 +56,10 @@
     }
     
     public FXOMObject clone(FXOMObject clonee) {
+        return clone(clonee, false /* preserveCloneFxId */);
+    }
+    
+    public FXOMObject clone(FXOMObject clonee, boolean preserveCloneeFxId) {
         assert clonee != null;
         assert addedFxIds.isEmpty();
         
@@ -67,7 +71,7 @@
         
         // Renames fxid in the clone so that there is no naming
         // conflict when the clone is hooked to its target document.
-        renameFxIds(result);
+        renameFxIds(result, preserveCloneeFxId);
         
         return result;
     }
@@ -293,10 +297,17 @@
     
     
     
-    private void renameFxIds(FXOMObject clone) {
+    private void renameFxIds(FXOMObject clone, boolean preserveCloneeFxId) {
         
         final Map<String, FXOMObject> fxIds = clone.collectFxIds();
         
+        if (preserveCloneeFxId && (clonee.getFxId() != null)) {
+            // We don't apply renaming to the fx:id of the clonee
+            assert clonee.getFxId().equals(clone.getFxId());
+            assert fxIds.get(clonee.getFxId()) == clone;
+            fxIds.remove(clonee.getFxId());
+        }
+        
         for (String candidateFxId : new PriorityQueue<>(fxIds.keySet())) {
             
             final String renamedFxId = fxIdCollector.importFxId(candidateFxId);