changeset 7883:96fb6a5bd1fc

[SCENEBUILDER] Going on fixing DTL-6783: RemovePropertyValueJob now removes the property after removing the last value. This enables to simplify DeleteObjectJob.
author eric.le.ponner@oracle.com
date Wed, 27 Aug 2014 16:27:20 +0200
parents a707fa9c9186
children 3840e47bc78c
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/RemovePropertyJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemovePropertyValueJob.java
diffstat 3 files changed, 27 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DeleteObjectJob.java	Wed Aug 27 15:33:43 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DeleteObjectJob.java	Wed Aug 27 16:27:20 2014 +0200
@@ -32,13 +32,11 @@
 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.RemovePropertyJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.RemovePropertyValueJob;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMCollection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMIntrinsic;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
-import com.oracle.javafx.scenebuilder.kit.fxom.FXOMPropertyC;
 import java.util.ArrayList;
 import java.util.List;
 import javafx.scene.chart.Axis;
@@ -87,29 +85,6 @@
 
         } else {
 
-            /*
-             * Two cases:
-             *    1) targetFxomObject is the last value of its parent property
-             *       => the property itself must be removed from its parent instance
-             *    2) targetFxomObject is not the last value of its parent property
-             *       => targetFxomObject is removed from its parent property
-             *
-             * Note : in case #1, we also remove targetFxomObject from its 
-             *   parent property ; like this, it can safely be reinserted else
-             *   in the FXOM tree.
-             */
-
-            final FXOMPropertyC parentProperty = targetFxomObject.getParentProperty();
-            final FXOMInstance parentInstance = parentProperty.getParentInstance();
-
-            if ((parentProperty.getValues().size() == 1) && (parentInstance != null)) {
-                // We make a job for removing the property
-                final Job removePropJob = new RemovePropertyJob(
-                        targetFxomObject.getParentProperty(),
-                        getEditorController());
-                result.add(removePropJob);
-            }
-
             // Then we make a job for removing the value
             final Job removeValueJob = new RemovePropertyValueJob(
                     targetFxomObject,
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemovePropertyJob.java	Wed Aug 27 15:33:43 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemovePropertyJob.java	Wed Aug 27 16:27:20 2014 +0200
@@ -53,7 +53,10 @@
         this.targetProperty = targetProperty;
     }
     
-    
+    public FXOMProperty getTargetProperty() {
+        return targetProperty;
+    }
+
 
     /*
      * Job
@@ -67,6 +70,7 @@
     @Override
     public void execute() {
         assert parentInstance == null;
+        assert isExecutable();
         
         parentInstance = targetProperty.getParentInstance();
         indexInParentInstance = targetProperty.getIndexInParentInstance();
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemovePropertyValueJob.java	Wed Aug 27 15:33:43 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/v2/RemovePropertyValueJob.java	Wed Aug 27 16:27:20 2014 +0200
@@ -45,6 +45,7 @@
     
     private FXOMPropertyC parentProperty;
     private int indexInParentProperty;
+    private RemovePropertyJob removePropertyJob;
 
     public RemovePropertyValueJob(FXOMObject value, EditorController editorController) {
         super(editorController);
@@ -58,18 +59,30 @@
     
     @Override
     public boolean isExecutable() {
-        final FXOMPropertyC p = targetValue.getParentProperty();
-        return (p != null) && (p.getValues().size() >= 2);
+        return targetValue.getParentProperty() != null;
     }
 
     @Override
     public void execute() {
         assert parentProperty == null;
+        assert isExecutable();
         
         parentProperty = targetValue.getParentProperty();
         indexInParentProperty = targetValue.getIndexInParentProperty();
+        if ((parentProperty.getValues().size() == 1) && (parentProperty.getParentInstance() != null)) {
+            // targetValue is the last value of its parent property
+            // => parent property must also be removed from its parent instance
+            removePropertyJob = new RemovePropertyJob(parentProperty, getEditorController());
+        }
         
-        redo();
+        // Note : below we may have to run removePropertyJob.execute() so
+        // we cannot re-use redo() here.
+        getEditorController().getFxomDocument().beginUpdate();
+        if (removePropertyJob != null) {
+            removePropertyJob.execute();
+        }
+        targetValue.removeFromParentProperty();
+        getEditorController().getFxomDocument().endUpdate();
     }
 
     @Override
@@ -78,6 +91,9 @@
         
         getEditorController().getFxomDocument().beginUpdate();
         targetValue.addToParentProperty(indexInParentProperty, parentProperty);
+        if (removePropertyJob != null) {
+            removePropertyJob.undo();
+        }
         getEditorController().getFxomDocument().endUpdate();
 
         assert targetValue.getParentProperty() == parentProperty;
@@ -89,8 +105,10 @@
         assert targetValue.getParentProperty() == parentProperty;
         assert targetValue.getIndexInParentProperty() == indexInParentProperty;
         
-        getEditorController().getSelection().clear();
         getEditorController().getFxomDocument().beginUpdate();
+        if (removePropertyJob != null) {
+            removePropertyJob.redo();
+        }
         targetValue.removeFromParentProperty();
         getEditorController().getFxomDocument().endUpdate();