changeset 7879:60236c9b4be4

[SCENEBUILDER] Going on fixing DTL-6783: Rationalize job implementation between Hierarchy and Content Panels => Adapt Insert As Accessory and Insert As Subcomponent job
author slions
date Wed, 27 Aug 2014 12:14:51 +0200
parents 427fa460c27c
children 850d81afb10f
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsAccessoryJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsSubComponentJob.java
diffstat 2 files changed, 76 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsAccessoryJob.java	Wed Aug 27 11:37:45 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsAccessoryJob.java	Wed Aug 27 12:14:51 2014 +0200
@@ -34,6 +34,8 @@
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.AddPropertyJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.AddPropertyValueJob;
+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.FXOMCollection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
@@ -43,18 +45,20 @@
 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask;
 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask.Accessory;
 import com.oracle.javafx.scenebuilder.kit.metadata.util.PropertyName;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * Job used to insert new FXOM objects into an accessory location.
  *
  */
-public class InsertAsAccessoryJob extends Job {
+public class InsertAsAccessoryJob extends BatchSelectionJob {
 
     private final FXOMObject newObject;
     private final FXOMObject targetObject;
     private final Accessory accessory;
-    private BatchJob subJob; // Initialized by execute()
-    private String description; // final but initialized lazily
 
     public InsertAsAccessoryJob(
             FXOMObject newObject,
@@ -74,103 +78,76 @@
         this.accessory = accessory;
     }
 
-    FXOMObject getNewObject() {
-        return newObject;
-    }
-    
-    /*
-     * Job
-     */
     @Override
-    public boolean isExecutable() {
-        final boolean result;
+    protected List<Job> makeSubJobs() {
+        final List<Job> result = new ArrayList<>();
         if (targetObject instanceof FXOMInstance) {
+
             final DesignHierarchyMask mask = new DesignHierarchyMask(targetObject);
-            result = mask.isAcceptingAccessory(accessory, newObject)
-                    && mask.getAccessory(accessory) == null;
-        } else {
-            // TODO(elp): someday we should support insering in FXOMCollection
-            result = false;
+            if (mask.isAcceptingAccessory(accessory, newObject)
+                    && mask.getAccessory(accessory) == null) { // (1)
+
+                final FXOMDocument fxomDocument = getEditorController().getFxomDocument();
+                final FXOMInstance targetInstance = (FXOMInstance) targetObject;
+                final PropertyName accessoryName = mask.getPropertyNameForAccessory(accessory);
+                assert accessoryName != null;
+
+                // Property has no value yet because of (1)
+                FXOMProperty targetProperty = new FXOMPropertyC(fxomDocument, accessoryName);
+
+                final Job addValueJob
+                        = new AddPropertyValueJob(newObject,
+                                (FXOMPropertyC) targetProperty,
+                                -1,
+                                getEditorController());
+                result.add(addValueJob);
+
+                if (targetProperty.getParentInstance() == null) {
+                    assert targetObject instanceof FXOMInstance;
+                    final Job addPropertyJob
+                            = new AddPropertyJob(targetProperty, targetInstance,
+                                    -1, getEditorController());
+                    result.add(addPropertyJob);
+                }
+
+                final Job pruneJob = new PrunePropertiesJob(newObject, targetObject,
+                        getEditorController());
+                if (pruneJob.isExecutable()) {
+                    result.add(0, pruneJob);
+                }
+            }
         }
         return result;
     }
 
     @Override
-    public void execute() {
-        assert isExecutable(); // (1)
+    protected String makeDescription() {
+        final String result;
+        final StringBuilder sb = new StringBuilder();
 
-        final FXOMDocument fxomDocument = getEditorController().getFxomDocument();
-        final FXOMInstance targetInstance = (FXOMInstance) targetObject;
-        final DesignHierarchyMask mask = new DesignHierarchyMask(targetObject);
-        final PropertyName accessoryName = mask.getPropertyNameForAccessory(accessory);
-        assert accessoryName != null;
+        sb.append("Insert ");
 
-        // Property has no value yet because of (1)
-        FXOMProperty targetProperty = new FXOMPropertyC(fxomDocument, accessoryName);
-
-        subJob = new BatchJob(getEditorController(),
-                true /* shouldUpdateSceneGraph */, null);
-        final Job addValueJob
-                = new AddPropertyValueJob(newObject,
-                        (FXOMPropertyC) targetProperty,
-                        -1,
-                        getEditorController());
-        subJob.addSubJob(addValueJob);
-
-        if (targetProperty.getParentInstance() == null) {
-            assert targetObject instanceof FXOMInstance;
-            final Job addPropertyJob
-                    = new AddPropertyJob(targetProperty, targetInstance,
-                            -1, getEditorController());
-            subJob.addSubJob(addPropertyJob);
+        if (newObject instanceof FXOMInstance) {
+            final Object sceneGraphObject = newObject.getSceneGraphObject();
+            if (sceneGraphObject != null) {
+                sb.append(sceneGraphObject.getClass().getSimpleName());
+            } else {
+                sb.append("Unresolved Object");
+            }
+        } else if (newObject instanceof FXOMCollection) {
+            sb.append("Collection");
+        } else {
+            assert false;
+            sb.append(newObject.getClass().getSimpleName());
         }
-
-        final Job pruneJob = new PrunePropertiesJob(newObject, targetObject, 
-                getEditorController());
-        if (pruneJob.isExecutable()) {
-            subJob.prependSubJob(pruneJob);
-        }
-            
-        /*
-         * Executes the subjob.
-         */
-        subJob.execute();
+        result = sb.toString();
+        return result;
     }
 
     @Override
-    public void undo() {
-        assert subJob != null;
-        subJob.undo();
-    }
-
-    @Override
-    public void redo() {
-        assert subJob != null;
-        subJob.redo();
-    }
-
-    @Override
-    public String getDescription() {
-        if (description == null) {
-            final StringBuilder sb = new StringBuilder();
-
-            sb.append("Insert ");
-
-            if (newObject instanceof FXOMInstance) {
-                final Object sceneGraphObject = newObject.getSceneGraphObject();
-                if (sceneGraphObject != null) {
-                    sb.append(sceneGraphObject.getClass().getSimpleName());
-                } else {
-                    sb.append("Unresolved Object");
-                }
-            } else if (newObject instanceof FXOMCollection) {
-                sb.append("Collection");
-            } else {
-                assert false;
-                sb.append(newObject.getClass().getSimpleName());
-            }
-            description = sb.toString();
-        }
-        return description;
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        final Set<FXOMObject> newObjects = new HashSet<>();
+        newObjects.add(newObject);
+        return new ObjectSelectionGroup(newObjects, newObject, null);
     }
 }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsSubComponentJob.java	Wed Aug 27 11:37:45 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/InsertAsSubComponentJob.java	Wed Aug 27 12:14:51 2014 +0200
@@ -34,9 +34,9 @@
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.AddPropertyJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.AddPropertyValueJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.v2.CompositeJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.v2.RemovePropertyJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.v2.UpdateSelectionJob;
+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.FXOMCollection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
@@ -48,13 +48,15 @@
 import com.oracle.javafx.scenebuilder.kit.metadata.util.PropertyName;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * Job used to insert new FXOM objects into a sub component location.
  *
  */
-public class InsertAsSubComponentJob extends CompositeJob {
+public class InsertAsSubComponentJob extends BatchSelectionJob {
 
     private final FXOMObject newObject;
     private final FXOMObject targetObject;
@@ -78,17 +80,6 @@
         this.targetIndex = targetIndex;
     }
 
-    public FXOMObject getTargetObject() {
-        return targetObject;
-    }
-
-    FXOMObject getNewObject() {
-        return newObject;
-    }
-    
-    /*
-     * CompositeJob
-     */
     @Override
     protected List<Job> makeSubJobs() {
         final List<Job> result;
@@ -164,11 +155,6 @@
             }
             
             /*
-             * UpdateSelectionJob
-             */
-            result.add(new UpdateSelectionJob(newObject, getEditorController()));
-            
-            /*
              * PrunePropertiesJob
              */
             final Job pruneJob = new PrunePropertiesJob(newObject, targetObject, 
@@ -206,4 +192,11 @@
         
         return sb.toString();
     }
+
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        final Set<FXOMObject> newObjects = new HashSet<>();
+        newObjects.add(newObject);
+        return new ObjectSelectionGroup(newObjects, newObject, null);
+    }
 }