changeset 7885:a5c10d255438

[SCENEBUILDER] DeleteObjectJob now uses RemoveObjectJob. This fixes a latent bug and will ease work of references (DTL-6774).
author eric.le.ponner@oracle.com
date Wed, 27 Aug 2014 17:38:42 +0200
parents 3840e47bc78c
children eedae2717d3c
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DeleteObjectJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveCollectionItemJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveNodeJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveObjectJob.java
diffstat 4 files changed, 296 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DeleteObjectJob.java	Wed Aug 27 17:32:12 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DeleteObjectJob.java	Wed Aug 27 17:38:42 2014 +0200
@@ -32,7 +32,7 @@
 package com.oracle.javafx.scenebuilder.kit.editor.job;
 
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.job.v2.RemovePropertyValueJob;
+import com.oracle.javafx.scenebuilder.kit.editor.job.v2.RemoveObjectJob;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMCollection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMIntrinsic;
@@ -77,7 +77,8 @@
     protected List<Job> makeAndExecuteSubJobs() {
 
         final List<Job> result = new ArrayList<>();
-        if (targetFxomObject.getParentProperty() == null) {
+        if ((targetFxomObject.getParentProperty() == null) &&
+            (targetFxomObject.getParentCollection() == null)) {
             /*
              * targetFxomObject is the root object
              */
@@ -85,11 +86,11 @@
 
         } else {
 
-            // Then we make a job for removing the value
-            final Job removeValueJob = new RemovePropertyValueJob(
+            // Then we make a job for removing the object
+            final Job removeObjectJob = new RemoveObjectJob(
                     targetFxomObject,
                     getEditorController());
-            result.add(removeValueJob);
+            result.add(removeObjectJob);
         }
 
         for (Job subJob : result) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveCollectionItemJob.java	Wed Aug 27 17:38:42 2014 +0200
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2012, 2014, Oracle 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.editor.job.v2;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.Job;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMCollection;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
+
+/**
+ *
+ */
+public class RemoveCollectionItemJob extends Job {
+
+    private final FXOMObject targetValue;
+    
+    private FXOMCollection parentCollection;
+    private int indexInParentCollection;
+
+    public RemoveCollectionItemJob(FXOMObject value, EditorController editorController) {
+        super(editorController);
+        this.targetValue = value;
+    }
+    
+    
+    /*
+     * Job
+     */
+    
+    @Override
+    public boolean isExecutable() {
+        return targetValue.getParentCollection() != null;
+    }
+
+    @Override
+    public void execute() {
+        assert parentCollection == null;
+        assert isExecutable();
+        
+        parentCollection = targetValue.getParentCollection();
+        indexInParentCollection = targetValue.getIndexInParentCollection();
+        
+        // Now same as redo()
+        redo();
+    }
+
+    @Override
+    public void undo() {
+        assert targetValue.getParentCollection() == null;
+        
+        getEditorController().getFxomDocument().beginUpdate();
+        targetValue.addToParentCollection(indexInParentCollection, parentCollection);
+        getEditorController().getFxomDocument().endUpdate();
+
+        assert targetValue.getParentCollection() == parentCollection;
+        assert targetValue.getIndexInParentCollection() == indexInParentCollection;
+    }
+
+    @Override
+    public void redo() {
+        assert targetValue.getParentCollection() == parentCollection;
+        assert targetValue.getIndexInParentCollection() == indexInParentCollection;
+        
+        getEditorController().getFxomDocument().beginUpdate();
+        targetValue.removeFromParentCollection();
+        getEditorController().getFxomDocument().endUpdate();
+
+        assert targetValue.getParentCollection() == null;
+    }
+
+    @Override
+    public String getDescription() {
+        // Should normally not reach the user
+        return getClass().getSimpleName() 
+                + "[" //NOI18N
+                + targetValue.getGlueElement().getTagName()
+                + "]"; //NOI18N
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveNodeJob.java	Wed Aug 27 17:38:42 2014 +0200
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2012, 2014, Oracle 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.editor.job.v2;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.Job;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMNode;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMProperty;
+
+/**
+ *
+ */
+public class RemoveNodeJob extends Job {
+    
+    private final Job subJob;
+    
+    public RemoveNodeJob(FXOMNode targetNode, EditorController editorController) {
+        super(editorController);
+        
+        assert (targetNode instanceof FXOMObject) || (targetNode instanceof FXOMProperty);
+        
+        if (targetNode instanceof FXOMObject) {
+            subJob = new RemoveObjectJob((FXOMObject)targetNode, editorController);
+        } else {
+            assert targetNode instanceof FXOMProperty;
+            subJob = new RemovePropertyJob((FXOMProperty)targetNode, editorController);
+        }
+    }
+    
+    
+    /*
+     * Job
+     */
+
+    @Override
+    public boolean isExecutable() {
+        return subJob.isExecutable();
+    }
+
+    @Override
+    public void execute() {
+        subJob.execute();
+    }
+
+    @Override
+    public void undo() {
+        subJob.undo();
+    }
+
+    @Override
+    public void redo() {
+        subJob.redo();
+    }
+
+    @Override
+    public String getDescription() {
+        return getClass().getSimpleName(); // Should not reach end user
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemoveObjectJob.java	Wed Aug 27 17:38:42 2014 +0200
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2012, 2014, Oracle 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.editor.job.v2;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.Job;
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
+
+/**
+ *
+ */
+public class RemoveObjectJob extends Job {
+    
+    private final Job subJob;
+    
+    public RemoveObjectJob(FXOMObject targetObject, EditorController editorController) {
+        super(editorController);
+        
+        assert targetObject != null;
+        assert (targetObject.getParentProperty() != null) || (targetObject.getParentCollection() != null);
+        
+        if (targetObject.getParentProperty() != null) {
+            subJob = new RemovePropertyValueJob(targetObject, editorController);
+        } else {
+            assert targetObject.getParentCollection() != null;
+            subJob = new RemoveCollectionItemJob(targetObject, editorController);
+        }
+    }
+    
+    
+    /*
+     * Job
+     */
+
+    @Override
+    public boolean isExecutable() {
+        return subJob.isExecutable();
+    }
+
+    @Override
+    public void execute() {
+        subJob.execute();
+    }
+
+    @Override
+    public void undo() {
+        subJob.undo();
+    }
+
+    @Override
+    public void redo() {
+        subJob.redo();
+    }
+
+    @Override
+    public String getDescription() {
+        return getClass().getSimpleName(); // Should not reach end user
+    }
+    
+}