changeset 8005:41a343a71f48

[SCENEBUILDER] Fix DTL-6862 : Arrange commands used with multi-selection have degraded since 1.1
author slions
date Tue, 09 Sep 2014 08:58:09 +0200
parents 15709eaf63bb
children 0332535f0cb2
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringForwardJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringToFrontJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendBackwardJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendToBackJob.java
diffstat 4 files changed, 101 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringForwardJob.java	Tue Sep 09 08:51:09 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringForwardJob.java	Tue Sep 09 08:58:09 2014 +0200
@@ -33,54 +33,62 @@
 
 import com.oracle.javafx.scenebuilder.kit.editor.job.atomic.ReIndexObjectJob;
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.selection.GridSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.Selection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  *
  */
-public class BringForwardJob extends BatchDocumentJob {
+public class BringForwardJob extends InlineDocumentJob {
 
     public BringForwardJob(EditorController editorController) {
         super(editorController);
     }
 
     @Override
-    protected List<Job> makeSubJobs() {
+    public boolean isExecutable() {
+        final Selection selection = getEditorController().getSelection();
+        if (selection.getGroup() instanceof ObjectSelectionGroup == false) {
+            return false;
+        }
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        for (FXOMObject item : osg.getSortedItems()) {
+            final FXOMObject nextSlibing = item.getNextSlibing();
+            if (nextSlibing == null) {
+                return false;
+            }
+        }
+        return true;
+    }
 
+    @Override
+    protected List<Job> makeAndExecuteSubJobs() {
+
+        assert isExecutable(); // (1)
         final List<Job> result = new ArrayList<>();
 
-        final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
-        if (selection.getGroup() instanceof ObjectSelectionGroup) {
-            final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
-            candidates.addAll(osg.getFlattenItems());
-        } else if (selection.getGroup() instanceof GridSelectionGroup) {
-            // GridPane rows / columns are selected : BringForwardJob is meaningless
-            // Just do nothing
-        } else {
-            assert selection.getGroup() == null :
-                    "Add implementation for " + selection.getGroup();
-        }
+        assert selection.getGroup() instanceof ObjectSelectionGroup; // Because of (1)
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        final List<FXOMObject> candidates = osg.getSortedItems();
 
-        for (FXOMObject candidate : candidates) {
+        for (int i = candidates.size() - 1; i >= 0; i--) {
+            final FXOMObject candidate = candidates.get(i);
             final FXOMObject nextSlibing = candidate.getNextSlibing();
             if (nextSlibing != null) {
                 final FXOMObject beforeChild = nextSlibing.getNextSlibing();
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, beforeChild, getEditorController());
                 if (subJob.isExecutable()) {
+                    subJob.execute();
                     result.add(subJob);
                 }
             }
         }
-        
+
         return result;
     }
 
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringToFrontJob.java	Tue Sep 09 08:51:09 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringToFrontJob.java	Tue Sep 09 08:58:09 2014 +0200
@@ -33,40 +33,47 @@
 
 import com.oracle.javafx.scenebuilder.kit.editor.job.atomic.ReIndexObjectJob;
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.selection.GridSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.Selection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  *
  */
-public class BringToFrontJob extends BatchDocumentJob {
+public class BringToFrontJob extends InlineDocumentJob {
 
     public BringToFrontJob(EditorController editorController) {
         super(editorController);
     }
+
     @Override
-    protected List<Job> makeSubJobs() {
+    public boolean isExecutable() {
+        final Selection selection = getEditorController().getSelection();
+        if (selection.getGroup() instanceof ObjectSelectionGroup == false) {
+            return false;
+        }
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        for (FXOMObject item : osg.getSortedItems()) {
+            final FXOMObject nextSlibing = item.getNextSlibing();
+            if (nextSlibing == null) {
+                return false;
+            }
+        }
+        return true;
+    }
 
+    @Override
+    protected List<Job> makeAndExecuteSubJobs() {
+
+        assert isExecutable(); // (1)
         final List<Job> result = new ArrayList<>();
 
-        final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
-        if (selection.getGroup() instanceof ObjectSelectionGroup) {
-            final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
-            candidates.addAll(osg.getFlattenItems());
-        } else if (selection.getGroup() instanceof GridSelectionGroup) {
-            // GridPane rows / columns are selected : BringToFrontJob is meaningless
-            // Just do nothing
-        } else {
-            assert selection.getGroup() == null :
-                    "Add implementation for " + selection.getGroup();
-        }
+        assert selection.getGroup() instanceof ObjectSelectionGroup; // Because of (1)
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        final List<FXOMObject> candidates = osg.getSortedItems();
 
         for (FXOMObject candidate : candidates) {
             final FXOMObject nextSlibing = candidate.getNextSlibing();
@@ -74,11 +81,12 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, null, getEditorController());
                 if (subJob.isExecutable()) {
+                    subJob.execute();
                     result.add(subJob);
                 }
             }
         }
-        
+
         return result;
     }
 
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendBackwardJob.java	Tue Sep 09 08:51:09 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendBackwardJob.java	Tue Sep 09 08:58:09 2014 +0200
@@ -33,41 +33,47 @@
 
 import com.oracle.javafx.scenebuilder.kit.editor.job.atomic.ReIndexObjectJob;
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.selection.GridSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.Selection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  *
  */
-public class SendBackwardJob extends BatchDocumentJob {
+public class SendBackwardJob extends InlineDocumentJob {
 
     public SendBackwardJob(EditorController editorController) {
         super(editorController);
     }
 
     @Override
-    protected List<Job> makeSubJobs() {
+    public boolean isExecutable() {
+        final Selection selection = getEditorController().getSelection();
+        if (selection.getGroup() instanceof ObjectSelectionGroup == false) {
+            return false;
+        }
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        for (FXOMObject item : osg.getSortedItems()) {
+            final FXOMObject previousSlibing = item.getPreviousSlibing();
+            if (previousSlibing == null) {
+                return false;
+            }
+        }
+        return true;
+    }
 
+    @Override
+    protected List<Job> makeAndExecuteSubJobs() {
+
+        assert isExecutable(); // (1)
         final List<Job> result = new ArrayList<>();
 
-        final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
-        if (selection.getGroup() instanceof ObjectSelectionGroup) {
-            final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
-            candidates.addAll(osg.getFlattenItems());
-        } else if (selection.getGroup() instanceof GridSelectionGroup) {
-            // GridPane rows / columns are selected : SendBackwardJob is meaningless
-            // Just do nothing
-        } else {
-            assert selection.getGroup() == null :
-                    "Add implementation for " + selection.getGroup();
-        }
+        assert selection.getGroup() instanceof ObjectSelectionGroup; // Because of (1)
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        final List<FXOMObject> candidates = osg.getSortedItems();
 
         for (FXOMObject candidate : candidates) {
             final FXOMObject previousSlibing = candidate.getPreviousSlibing();
@@ -75,11 +81,12 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, previousSlibing, getEditorController());
                 if (subJob.isExecutable()) {
+                    subJob.execute();
                     result.add(subJob);
                 }
             }
         }
-        
+
         return result;
     }
 
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendToBackJob.java	Tue Sep 09 08:51:09 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendToBackJob.java	Tue Sep 09 08:58:09 2014 +0200
@@ -33,44 +33,51 @@
 
 import com.oracle.javafx.scenebuilder.kit.editor.job.atomic.ReIndexObjectJob;
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.selection.GridSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup;
 import com.oracle.javafx.scenebuilder.kit.editor.selection.Selection;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMPropertyC;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  *
  */
-public class SendToBackJob extends BatchDocumentJob {
+public class SendToBackJob extends InlineDocumentJob {
 
     public SendToBackJob(EditorController editorController) {
         super(editorController);
     }
 
     @Override
-    protected List<Job> makeSubJobs() {
+    public boolean isExecutable() {
+        final Selection selection = getEditorController().getSelection();
+        if (selection.getGroup() instanceof ObjectSelectionGroup == false) {
+            return false;
+        }
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        for (FXOMObject item : osg.getSortedItems()) {
+            final FXOMObject previousSlibing = item.getPreviousSlibing();
+            if (previousSlibing == null) {
+                return false;
+            }
+        }
+        return true;
+    }
 
+    @Override
+    protected List<Job> makeAndExecuteSubJobs() {
+
+        assert isExecutable(); // (1)
         final List<Job> result = new ArrayList<>();
 
-        final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
-        if (selection.getGroup() instanceof ObjectSelectionGroup) {
-            final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
-            candidates.addAll(osg.getFlattenItems());
-        } else if (selection.getGroup() instanceof GridSelectionGroup) {
-            // GridPane rows / columns are selected : SendToBackJob is meaningless
-            // Just do nothing
-        } else {
-            assert selection.getGroup() == null :
-                    "Add implementation for " + selection.getGroup();
-        }
+        assert selection.getGroup() instanceof ObjectSelectionGroup; // Because of (1)
+        final ObjectSelectionGroup osg = (ObjectSelectionGroup) selection.getGroup();
+        final List<FXOMObject> candidates = osg.getSortedItems();
 
-        for (FXOMObject candidate : candidates) {
+        for (int i = candidates.size() - 1; i >= 0; i--) {
+            final FXOMObject candidate = candidates.get(i);
             final FXOMObject previousSlibing = candidate.getPreviousSlibing();
             if (previousSlibing != null) {
                 final FXOMPropertyC parentProperty = candidate.getParentProperty();
@@ -78,11 +85,12 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, beforeChild, getEditorController());
                 if (subJob.isExecutable()) {
+                    subJob.execute();
                     result.add(subJob);
                 }
             }
         }
-        
+
         return result;
     }