changeset 7761:0b9b9d26f990

[SCENEBUILDER] Going on fixing DTL-6783: Rationalize job implementation between Hierarchy and Content Panels => Adapt Duplicate Selection jobs
author slions
date Fri, 22 Aug 2014 09:48:22 +0200
parents 9f8ee0e84baf
children 191aab1d374d
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DuplicateSelectionJob.java
diffstat 1 files changed, 16 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DuplicateSelectionJob.java	Fri Aug 22 09:46:48 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/DuplicateSelectionJob.java	Fri Aug 22 09:48:22 2014 +0200
@@ -34,9 +34,6 @@
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
 import com.oracle.javafx.scenebuilder.kit.editor.i18n.I18N;
 import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.v2.ClearSelectionJob;
-import com.oracle.javafx.scenebuilder.kit.editor.job.v2.CompositeJob;
-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.editor.selection.Selection;
@@ -55,18 +52,15 @@
 /**
  *
  */
-public class DuplicateSelectionJob extends CompositeJob {
+public class DuplicateSelectionJob extends BatchSelectionJob {
 
     private final static double offset = 10;
-    private int numOfDuplicatedObjects = 0;
+    final Map<FXOMObject, FXOMObject> newFxomObjects = new HashMap<>();
 
     public DuplicateSelectionJob(EditorController editorController) {
         super(editorController);
     }
 
-    /*
-     * CompositeJob
-     */
     @Override
     protected List<Job> makeSubJobs() {
         final List<Job> result = new ArrayList<>();
@@ -81,7 +75,6 @@
             final FXOMObject targetObject = osg.getAncestor();
             assert targetObject != null; // Because of (1)
             final FXOMDocument targetDocument = getEditorController().getFxomDocument();
-            final Map<FXOMObject, FXOMObject> newFxomObjects = new HashMap<>();
             for (FXOMObject selectedObject : osg.getItems()) {
                 final FXOMDocument newDocument = FXOMNodes.newDocument(selectedObject);
                 final FXOMObject newObject = newDocument.getFxomRoot();
@@ -94,7 +87,6 @@
             // Build InsertAsSubComponent jobs
             final DesignHierarchyMask targetMask = new DesignHierarchyMask(targetObject);
             if (targetMask.isAcceptingSubComponent(newFxomObjects.keySet())) {
-                result.add(new ClearSelectionJob(getEditorController()));
                 for (Map.Entry<FXOMObject, FXOMObject> entry : newFxomObjects.entrySet()) {
                     final FXOMObject selectedFxomObject = entry.getKey();
                     final FXOMObject newFxomObject = entry.getValue();
@@ -104,7 +96,6 @@
                             targetMask.getSubComponentCount(),
                             getEditorController());
                     result.add(insertSubJob);
-                    numOfDuplicatedObjects++;
                     final Object selectedSceneGraphObject = selectedFxomObject.getSceneGraphObject();
                     // Relocate duplicated objects if needed
                     if (selectedSceneGraphObject instanceof Node) {
@@ -121,7 +112,6 @@
                     }
                 }
                 result.add(new AdjustAllToggleGroupJob(getEditorController()));
-                result.add(new UpdateSelectionJob(newFxomObjects.values(), getEditorController()));
             }
         }
         return result;
@@ -130,8 +120,8 @@
     @Override
     protected String makeDescription() {
         final String result;
-        assert getSubJobs().isEmpty() == false;
-        if (numOfDuplicatedObjects == 1) {
+        assert newFxomObjects.values().isEmpty() == false;
+        if (newFxomObjects.values().size() == 1) {
             result = makeSingleSelectionDescription();
         } else {
             result = makeMultipleSelectionDescription();
@@ -140,6 +130,16 @@
         return result;
     }
 
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        assert newFxomObjects != null; // But possibly empty
+        if (newFxomObjects.isEmpty()) {
+            return null;
+        } else {
+            return new ObjectSelectionGroup(newFxomObjects.values(), newFxomObjects.values().iterator().next(), null);
+        }
+    }
+
     private boolean canDuplicate() {
         final FXOMDocument fxomDocument = getEditorController().getFxomDocument();
         if (fxomDocument == null) {
@@ -169,10 +169,7 @@
     private String makeSingleSelectionDescription() {
         final String result;
 
-        final Job subJob0 = getSubJobs().get(1);// ClearSelectionJob + Insert + UpdateSelectionJob
-        assert subJob0 instanceof InsertAsSubComponentJob;
-        final InsertAsSubComponentJob insertJob = (InsertAsSubComponentJob) subJob0;
-        final FXOMObject newObject = insertJob.getNewObject();
+        final FXOMObject newObject = newFxomObjects.values().iterator().next();
         if (newObject instanceof FXOMInstance) {
             final Object sceneGraphObject = newObject.getSceneGraphObject();
             if (sceneGraphObject != null) {
@@ -191,6 +188,6 @@
     }
 
     private String makeMultipleSelectionDescription() {
-        return I18N.getString("label.action.edit.duplicate.n", numOfDuplicatedObjects);
+        return I18N.getString("label.action.edit.duplicate.n", newFxomObjects.values().size());
     }
 }