changeset 7771:04e7f28714b3

[SCENEBUILDER] Fix for DTL-6825 (Copy command fails when selected object contains references). FXOMNodes.newDocument() now relies on FXOMCloner (the new cloning code). newInstance() methods rom FXOMInstance, FXOMCollection, FXOMIntrinsic and FXOMProperty classes have been removed.
author Eric Le Ponner <eric.le.ponner@oracle.com>
date Fri, 22 Aug 2014 16:32:57 +0200
parents 92969d8fa8b7
children afa6d979fcca
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCollection.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyC.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyT.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardEncoder.java
diffstat 8 files changed, 17 insertions(+), 194 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java	Fri Aug 22 16:32:57 2014 +0200
@@ -82,23 +82,6 @@
         return result;
     }
     
-    public static boolean isArchivable(Collection<FXOMObject> fxomObjects) {
-        
-        // Checks that fxom objects are all self contained
-        int selfContainedCount = 0;
-        FXOMFxIdIndex fxomIndex = null;
-        for (FXOMObject o : fxomObjects) {
-            if ((fxomIndex == null) || (fxomIndex.getFxomDocument() != o.getFxomDocument())) {
-                fxomIndex = new FXOMFxIdIndex(o.getFxomDocument());
-            }
-            if (fxomIndex.isSelfContained(o)) {
-                selfContainedCount++;
-            }
-        }
-        
-        return selfContainedCount == fxomObjects.size();
-    }
-    
     
     public static class Entry implements Serializable {
         
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCollection.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMCollection.java	Fri Aug 22 16:32:57 2014 +0200
@@ -92,33 +92,6 @@
     }    
     
     
-    public static FXOMCollection newInstance(FXOMCollection source, FXOMDocument targetDocument) {
-        final FXOMCollection result;
-        
-        assert source != null;
-        assert targetDocument != null;
-        assert source.getFxomDocument() != targetDocument;
-        
-        
-        result = new FXOMCollection(
-                targetDocument,
-                source.getDeclaredClass());
-        
-        for (FXOMObject sourceItem : source.getItems()) {
-            final FXOMObject newItem = FXOMNodes.newObject(sourceItem, targetDocument);
-            newItem.addToParentCollection(-1, result);
-        }
-        
-        result.setFxConstant(source.getFxConstant());
-        result.setFxController(source.getFxController());
-        result.setFxFactory(source.getFxFactory());
-        result.setFxId(source.getFxId());
-        result.setFxValue(source.getFxValue());
-        
-        return result;
-    }
-    
-    
     /*
      * FXOMObject
      */
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java	Fri Aug 22 16:32:57 2014 +0200
@@ -133,40 +133,6 @@
     public String getType() {
         return getGlueElement().getAttributes().get(FXMLLoader.ROOT_TYPE_ATTRIBUTE);
     }
-        
-    
-    public static FXOMInstance newInstance(FXOMInstance source, FXOMDocument targetDocument) {
-        final FXOMInstance result;
-        
-        assert source != null;
-        assert targetDocument != null;
-        assert source.getFxomDocument() != targetDocument;
-        
-        if (source.getDeclaredClass() == null) {
-            assert source.getSceneGraphObject() == null; // source is unresolved
-            result = new FXOMInstance(
-                    targetDocument,
-                    source.getGlueElement().getTagName());
-        } else {
-            result = new FXOMInstance(
-                    targetDocument,
-                    source.getDeclaredClass());
-        }
-        
-        for (Map.Entry<PropertyName, FXOMProperty> e : source.getProperties().entrySet()) {
-            final FXOMProperty newProperty
-                    = FXOMNodes.newProperty(e.getValue(), targetDocument);
-            newProperty.addToParentInstance(-1, result);
-        }
-        
-        result.setFxConstant(source.getFxConstant());
-        result.setFxController(source.getFxController());
-        result.setFxFactory(source.getFxFactory());
-        result.setFxId(source.getFxId());
-        result.setFxValue(source.getFxValue());
-        
-        return result;
-    }
     
     /*
      * FXOMObject
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java	Fri Aug 22 16:32:57 2014 +0200
@@ -111,28 +111,6 @@
     public Map<PropertyName, FXOMProperty> getProperties() {
         return properties;
     }
-    
-    public static FXOMIntrinsic newInstance(FXOMIntrinsic source, FXOMDocument targetDocument) {
-        final FXOMIntrinsic result;
-        
-        assert source != null;
-        assert targetDocument != null;
-        assert source.getFxomDocument() != targetDocument;
-        
-        result = new FXOMIntrinsic(
-                targetDocument,
-                source.getType(),
-                source.getSource());
-        
-        result.setFxConstant(source.getFxConstant());
-        result.setFxController(source.getFxController());
-        result.setFxFactory(source.getFxFactory());
-        result.setFxId(source.getFxId());
-        result.setFxValue(source.getFxValue());
-        
-        
-        return result;
-    }
 
     /*
      * FXOMObject
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java	Fri Aug 22 16:32:57 2014 +0200
@@ -142,38 +142,6 @@
     
     
     
-    public static FXOMNode newNode(FXOMNode source, FXOMDocument targetDocument) {
-        final FXOMNode result;
-        
-        if (source instanceof FXOMObject) {
-            result = newObject((FXOMObject) source, targetDocument);
-        } else if (source instanceof FXOMProperty) {
-            result = newProperty((FXOMProperty) source, targetDocument);
-        } else {
-            throw new IllegalArgumentException(FXOMNodes.class.getSimpleName()
-                    + " needs some additional implementation"); //NOI18N
-        }
-        
-        return result;
-    }
-    
-    public static FXOMObject newObject(FXOMObject source, FXOMDocument targetDocument) {
-        final FXOMObject result;
-        
-        if (source instanceof FXOMCollection) {
-            result = FXOMCollection.newInstance((FXOMCollection) source, targetDocument);
-        } else if (source instanceof FXOMInstance) {
-            result = FXOMInstance.newInstance((FXOMInstance) source, targetDocument);
-        } else if (source instanceof FXOMIntrinsic) {
-            result = FXOMIntrinsic.newInstance((FXOMIntrinsic) source, targetDocument);
-        } else {
-            throw new IllegalArgumentException(FXOMNodes.class.getSimpleName()
-                    + " needs some additional implementation"); //NOI18N
-        }
-        
-        return result;
-    }
-    
     public static FXOMObject newObject(FXOMDocument targetDocument, File file)
             throws IOException {
         assert targetDocument != null;
@@ -252,27 +220,17 @@
 
         return result;
     }
-
-    public static FXOMProperty newProperty(FXOMProperty source, FXOMDocument targetDocument) {
-        final FXOMProperty result;
-        
-        if (source instanceof FXOMPropertyC) {
-            result = FXOMPropertyC.newInstance((FXOMPropertyC) source, targetDocument);
-        } else if (source instanceof FXOMPropertyT) {
-            result = FXOMPropertyT.newInstance((FXOMPropertyT) source, targetDocument);
-        }else {
-            throw new IllegalArgumentException(FXOMNodes.class.getSimpleName()
-                    + " needs some additional implementation");
-        }
-        
-        return result;
-    }
     
     public static FXOMDocument newDocument(FXOMObject source) {
         assert source != null;
         
         final FXOMDocument result = new FXOMDocument();
         
+        /*
+         * If source's document contains unresolved objects,
+         * then clones import instructions from the source document
+         * to the new document.
+         */
         final FXOMDocument sourceDocument 
                 = source.getFxomDocument();
         assert sourceDocument.getFxomRoot() != null; // contains at least source
@@ -288,10 +246,20 @@
             }
         }
         
+        /*
+         * Clones source to the new document
+         */
+        final FXOMCloner cloner = new FXOMCloner(result);
+        final FXOMObject sourceClone = cloner.clone(source);
+        
+        /*
+         * Setup new document : sourceClone is the root, 
+         * same location, same class loader.
+         */
         result.beginUpdate();
         result.setLocation(sourceDocument.getLocation());
         result.setClassLoader(sourceDocument.getClassLoader());
-        result.setFxomRoot(FXOMNodes.newObject(source, result));
+        result.setFxomRoot(sourceClone);
         if (result.getFxomRoot() instanceof FXOMInstance) {
             trimStaticProperties((FXOMInstance) result.getFxomRoot());
         }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyC.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyC.java	Fri Aug 22 16:32:57 2014 +0200
@@ -106,26 +106,6 @@
     public GlueElement getGlueElement() {
         return glueElement;
     }
-
-    public static FXOMPropertyC newInstance(FXOMPropertyC source, FXOMDocument targetDocument) {
-        final FXOMPropertyC result;
-        
-        assert source != null;
-        assert targetDocument != null;
-        assert source.getFxomDocument() != targetDocument;
-        
-        
-        result = new FXOMPropertyC(
-                targetDocument,
-                source.getName());
-        
-        for (FXOMObject sourceValue : source.getValues()) {
-            final FXOMObject newValue = FXOMNodes.newObject(sourceValue, targetDocument);
-            newValue.addToParentProperty(-1, result);
-        }
-        
-        return result;
-    }
     
     
     
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyT.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/FXOMPropertyT.java	Fri Aug 22 16:32:57 2014 +0200
@@ -135,23 +135,6 @@
     public GlueElement getValueElement() {
         return valueElement;
     }
-    
-    public static FXOMPropertyT newInstance(FXOMPropertyT source, FXOMDocument targetDocument) {
-        final FXOMPropertyT result;
-        
-        assert source != null;
-        assert targetDocument != null;
-        assert source.getFxomDocument() != targetDocument;
-        
-        
-        result = new FXOMPropertyT(
-                targetDocument,
-                source.getName(),
-                source.getValue());
-        
-        
-        return result;
-    }
 
     /*
      * FXOMProperty
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardEncoder.java	Fri Aug 22 08:12:41 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardEncoder.java	Fri Aug 22 16:32:57 2014 +0200
@@ -60,15 +60,7 @@
     }
     
     public boolean isEncodable() {
-        final boolean result;
-        
-        if (fxomObjects.isEmpty()) {
-            result = false;
-        } else {
-            result = FXOMArchive.isArchivable(fxomObjects);
-        }
-        
-        return result;
+        return fxomObjects.isEmpty() == false;
     }
     
     public ClipboardContent makeEncoding() {