changeset 8042:12530777d84a

[SCENEBUILDER] SetDocumentRootJob now takes responsibility to invoke UsePredefinedSizeJob (part of DTL-6783). This removes some code duplication and avoids creating some BatchJob instances.
author Eric Le Ponner <eric.le.ponner@oracle.com>
date Thu, 11 Sep 2014 18:54:15 +0200
parents b0a08e558789
children 554c4bdd3c5f
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/drag/target/RootDropTarget.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SetDocumentRootJob.java
diffstat 3 files changed, 34 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java	Thu Sep 11 18:12:59 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java	Thu Sep 11 18:54:15 2014 +0200
@@ -61,7 +61,6 @@
 import com.oracle.javafx.scenebuilder.kit.editor.job.gridpane.MoveColumnJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.gridpane.MoveRowJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.gridpane.v2.SpanJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.atomic.UpdateSelectionJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.wrap.AbstractWrapInJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.wrap.UnwrapJob;
 import com.oracle.javafx.scenebuilder.kit.editor.messagelog.MessageLog;
@@ -1583,18 +1582,10 @@
         newObject.moveToFxomDocument(getFxomDocument());
         final FXOMObject rootObject = getFxomDocument().getFxomRoot();
         if (rootObject == null) { // Empty document
-            job = new BatchJob(this, true,
-                    I18N.getString("drop.job.insert.library.item", libraryItem.getName()));
-            ((BatchJob) job).addSubJob(new SetDocumentRootJob(newObject, this));
-            // New root container may need a resize
-            final DesignHierarchyMask mask = new DesignHierarchyMask(newObject);
-            if (mask.needResizeWhenTopElement()) {
-                ((BatchJob) job).addSubJob(new UsePredefinedSizeJob(this,
-                        EditorController.Size.SIZE_DEFAULT, newObject));
-            }
-                        
-            // As for non root element the inserted object is selected.
-            ((BatchJob) job).addSubJob(new UpdateSelectionJob(newObject, this));
+            final String description
+                    = I18N.getString("drop.job.insert.library.item", libraryItem.getName());
+            job = new SetDocumentRootJob(newObject, true /* usePredefinedSize */, description, this);
+
         } else {
             if (selection.isEmpty() || selection.isSelected(rootObject)) {
                 // No selection or root is selected -> we insert below root
@@ -1637,7 +1628,7 @@
                 final FXOMObject rootObject = getFxomDocument().getFxomRoot();
                 if (rootObject == null) { // Empty document
                     final SetDocumentRootJob job = new SetDocumentRootJob(
-                            newItemRoot, this);
+                            newItemRoot, true /* usePredefinedSize */, "unused", this); //NOI18N
                     result = job.isExecutable();
                 } else {
                     if (selection.isEmpty() || selection.isSelected(rootObject)) {
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/drag/target/RootDropTarget.java	Thu Sep 11 18:12:59 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/drag/target/RootDropTarget.java	Thu Sep 11 18:54:15 2014 +0200
@@ -35,10 +35,8 @@
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
 import com.oracle.javafx.scenebuilder.kit.editor.drag.source.AbstractDragSource;
 import com.oracle.javafx.scenebuilder.kit.editor.drag.source.LibraryDragSource;
-import com.oracle.javafx.scenebuilder.kit.editor.job.BatchJob;
 import com.oracle.javafx.scenebuilder.kit.editor.job.Job;
 import com.oracle.javafx.scenebuilder.kit.editor.job.SetDocumentRootJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.UsePredefinedSizeJob;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask;
 
@@ -68,30 +66,8 @@
         assert dragSource.getDraggedObjects().size() == 1;
         
         final FXOMObject newRoot = dragSource.getDraggedObjects().get(0);
-        
-        /*
-         * Containers coming from the library are automatically resized.
-         */
-        final UsePredefinedSizeJob resizeJob;
-        if (dragSource instanceof LibraryDragSource) {
-            final DesignHierarchyMask mask = new DesignHierarchyMask(newRoot);
-            if (mask.needResizeWhenTopElement()) {
-                resizeJob = new UsePredefinedSizeJob(editorController, 
-                        EditorController.Size.SIZE_DEFAULT, newRoot);
-            } else {
-                resizeJob = null;
-            }
-        } else {
-            resizeJob = null;
-        }
-        
-        final BatchJob result = new BatchJob(editorController, true, dragSource.makeDropJobDescription());
-        result.addSubJob(new SetDocumentRootJob(newRoot, editorController));
-        if ((resizeJob != null) && resizeJob.isExecutable()) {
-            result.addSubJob(resizeJob);
-        }
-        
-        return result ;
+        return new SetDocumentRootJob(newRoot, true /* usePredefinedSize */, 
+                dragSource.makeDropJobDescription(), editorController);
     }
     
     @Override
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SetDocumentRootJob.java	Thu Sep 11 18:12:59 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SetDocumentRootJob.java	Thu Sep 11 18:54:15 2014 +0200
@@ -36,6 +36,7 @@
 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.FXOMObject;
+import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -45,14 +46,27 @@
 public class SetDocumentRootJob extends BatchSelectionJob {
 
     private final FXOMObject newRoot;
+    private final boolean usePredefinedSize;
+    private final String description;
 
-    public SetDocumentRootJob(FXOMObject newRoot, EditorController editorController) {
+    public SetDocumentRootJob(FXOMObject newRoot, 
+            boolean usePredefinedSize, 
+            String description,
+            EditorController editorController) {
         super(editorController);
 
         assert editorController.getFxomDocument() != null;
         assert (newRoot == null) || (newRoot.getFxomDocument() == editorController.getFxomDocument());
+        assert description != null;
 
         this.newRoot = newRoot;
+        this.usePredefinedSize = usePredefinedSize;
+        this.description = description;
+    }
+    
+    public SetDocumentRootJob(FXOMObject newRoot, EditorController editorController) {
+        this(newRoot, false /* usePredefinedSize */, 
+                SetDocumentRootJob.class.getSimpleName(), editorController);
     }
 
     public FXOMObject getNewRoot() {
@@ -69,15 +83,25 @@
             if (newRoot != null) {
                 result.add(new PrunePropertiesJob(newRoot, null, getEditorController()));
             }
+            
+            // Adds job that effectively modifes the root
             result.add(new SetFxomRootJob(newRoot, getEditorController()));
+            
+            // If need, we add a job for resizing the root object
+            if ((newRoot != null) && usePredefinedSize) {
+                final DesignHierarchyMask mask = new DesignHierarchyMask(newRoot);
+                if (mask.needResizeWhenTopElement()) {
+                    result.add(new UsePredefinedSizeJob(getEditorController(), 
+                            EditorController.Size.SIZE_DEFAULT, newRoot));
+                }
+            }
         }
         return result;
     }
 
     @Override
     protected String makeDescription() {
-        // Not expected to reach the user
-        return getClass().getSimpleName();
+        return description;
     }
 
     @Override