changeset 7818:3abdf4d4ac34

[SCENEBUILDER] Going on fixing DTL-6783: Rationalize job implementation between Hierarchy and Content Panels => Adapt Bring To Front / Send To Back / Bring Forward / Send Backward jobs
author slions
date Fri, 22 Aug 2014 09:42:07 +0200
parents fb4402463363
children bf32ada7d417
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/ArrangeZOrderJob.java 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 5 files changed, 121 insertions(+), 182 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/ArrangeZOrderJob.java	Thu Aug 21 19:53:02 2014 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
- * All rights reserved. Use is subject to license terms.
- *
- * This file is available and licensed under the following license:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *  - Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  - Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the distribution.
- *  - Neither the name of Oracle Corporation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.oracle.javafx.scenebuilder.kit.editor.job;
-
-import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
-import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
-import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Used for the Arrange menu items : Bring To Front / Bring Forward / Send To
- * Back / Send Backward.
- */
-public abstract class ArrangeZOrderJob extends Job {
-
-    protected final List<ReIndexObjectJob> subJobs = new ArrayList<>();
-    protected String description; // final but initialized lazily
-    private AdjustAllToggleGroupJob adjustToggleGroups; // created by execute()
-
-    public ArrangeZOrderJob(EditorController editorController) {
-        super(editorController);
-    }
-
-    /*
-     * Job
-     */
-    @Override
-    public boolean isExecutable() {
-        return subJobs.isEmpty() == false;
-    }
-
-    @Override
-    public void execute() {
-        final FXOMDocument fxomDocument
-                = getEditorController().getFxomDocument();
-        fxomDocument.beginUpdate();
-        for (ReIndexObjectJob subJob : subJobs) {
-            subJob.execute();
-        }
-        adjustToggleGroups = new AdjustAllToggleGroupJob(getEditorController());
-        adjustToggleGroups.execute();
-        fxomDocument.endUpdate();
-    }
-
-    @Override
-    public void undo() {
-        final FXOMDocument fxomDocument
-                = getEditorController().getFxomDocument();
-        fxomDocument.beginUpdate();
-        assert adjustToggleGroups != null;
-        adjustToggleGroups.undo();
-        for (int i = subJobs.size() - 1; i >= 0; i--) {
-            subJobs.get(i).undo();
-        }
-        fxomDocument.endUpdate();
-    }
-
-    @Override
-    public void redo() {
-        final FXOMDocument fxomDocument
-                = getEditorController().getFxomDocument();
-        fxomDocument.beginUpdate();
-        for (ReIndexObjectJob subJob : subJobs) {
-            subJob.redo();
-        }
-        assert adjustToggleGroups != null;
-        adjustToggleGroups.redo();
-        fxomDocument.endUpdate();
-    }
-}
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringForwardJob.java	Thu Aug 21 19:53:02 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringForwardJob.java	Fri Aug 22 09:42:07 2014 +0200
@@ -32,35 +32,30 @@
 package com.oracle.javafx.scenebuilder.kit.editor.job;
 
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
+import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup;
 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 ArrangeZOrderJob {
+public class BringForwardJob extends BatchSelectionJob {
 
     public BringForwardJob(EditorController editorController) {
         super(editorController);
-        buildSubJobs();
     }
 
     @Override
-    public String getDescription() {
-        if (description == null) {
-            buildDescription();
-        }
-        return description;
-    }
+    protected List<Job> makeSubJobs() {
 
-    /*
-     * Private
-     */
-    private void buildSubJobs() {
+        final List<Job> result = new ArrayList<>();
 
         final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
@@ -82,30 +77,45 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, beforeChild, getEditorController());
                 if (subJob.isExecutable()) {
-                    subJobs.add(subJob);
+                    result.add(subJob);
                 }
             }
         }
+        
+        if (result.isEmpty() == false) {
+            // Finally we adjust toggle groups
+            result.add(new AdjustAllToggleGroupJob(getEditorController()));
+        }
+        return result;
     }
 
-    private void buildDescription() {
-        switch (subJobs.size()) {
+    @Override
+    protected String makeDescription() {
+        final String result;
+        switch (getSubJobs().size()) {
             case 0:
-                description = "Unexecutable Bring Forward"; // NO18N
+                result = "Unexecutable Bring Forward"; // NO18N
                 break;
-            case 1:
-                description = subJobs.get(0).getDescription();
+            case 2: // one arrange Z order + one AdjustAllToggleGroup
+                result = getSubJobs().get(0).getDescription();
                 break;
             default:
-                description = makeMultipleSelectionDescription();
+                result = makeMultipleSelectionDescription();
                 break;
         }
+        return result;
+    }
+
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        // Selection unchanged
+        return getOldSelectionGroup();
     }
 
     private String makeMultipleSelectionDescription() {
         final StringBuilder result = new StringBuilder();
         result.append("Bring Forward ");
-        result.append(subJobs.size());
+        result.append(getSubJobs().size() - 1);
         result.append(" Objects");
         return result.toString();
     }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringToFrontJob.java	Thu Aug 21 19:53:02 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/BringToFrontJob.java	Fri Aug 22 09:42:07 2014 +0200
@@ -32,35 +32,29 @@
 package com.oracle.javafx.scenebuilder.kit.editor.job;
 
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
+import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup;
 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 ArrangeZOrderJob {
+public class BringToFrontJob extends BatchSelectionJob {
 
     public BringToFrontJob(EditorController editorController) {
         super(editorController);
-        buildSubJobs();
     }
+    @Override
+    protected List<Job> makeSubJobs() {
 
-    @Override
-    public String getDescription() {
-        if (description == null) {
-            buildDescription();
-        }
-        return description;
-    }
-
-    /*
-     * Private
-     */
-    private void buildSubJobs() {
+        final List<Job> result = new ArrayList<>();
 
         final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
@@ -81,30 +75,45 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, null, getEditorController());
                 if (subJob.isExecutable()) {
-                    subJobs.add(subJob);
+                    result.add(subJob);
                 }
             }
         }
+        
+        if (result.isEmpty() == false) {
+            // Finally we adjust toggle groups
+            result.add(new AdjustAllToggleGroupJob(getEditorController()));
+        }
+        return result;
     }
 
-    private void buildDescription() {
-        switch (subJobs.size()) {
+    @Override
+    protected String makeDescription() {
+        final String result;
+        switch (getSubJobs().size()) {
             case 0:
-                description = "Unexecutable Bring To Front"; // NO18N
+                result = "Unexecutable Bring To Front"; // NO18N
                 break;
-            case 1:
-                description = subJobs.get(0).getDescription();
+            case 2: // one arrange Z order + one AdjustAllToggleGroup
+                result = getSubJobs().get(0).getDescription();
                 break;
             default:
-                description = makeMultipleSelectionDescription();
+                result = makeMultipleSelectionDescription();
                 break;
         }
+        return result;
+    }
+
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        // Selection unchanged
+        return getOldSelectionGroup();
     }
 
     private String makeMultipleSelectionDescription() {
         final StringBuilder result = new StringBuilder();
         result.append("Bring To Front ");
-        result.append(subJobs.size());
+        result.append(getSubJobs().size() - 1);
         result.append(" Objects");
         return result.toString();
     }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendBackwardJob.java	Thu Aug 21 19:53:02 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendBackwardJob.java	Fri Aug 22 09:42:07 2014 +0200
@@ -32,35 +32,30 @@
 package com.oracle.javafx.scenebuilder.kit.editor.job;
 
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
+import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup;
 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 ArrangeZOrderJob {
+public class SendBackwardJob extends BatchSelectionJob {
 
     public SendBackwardJob(EditorController editorController) {
         super(editorController);
-        buildSubJobs();
     }
 
     @Override
-    public String getDescription() {
-        if (description == null) {
-            buildDescription();
-        }
-        return description;
-    }
+    protected List<Job> makeSubJobs() {
 
-    /*
-     * Private
-     */
-    private void buildSubJobs() {
+        final List<Job> result = new ArrayList<>();
 
         final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
@@ -81,30 +76,45 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, previousSlibing, getEditorController());
                 if (subJob.isExecutable()) {
-                    subJobs.add(subJob);
+                    result.add(subJob);
                 }
             }
         }
+        
+        if (result.isEmpty() == false) {
+            // Finally we adjust toggle groups
+            result.add(new AdjustAllToggleGroupJob(getEditorController()));
+        }
+        return result;
     }
 
-    private void buildDescription() {
-        switch (subJobs.size()) {
+    @Override
+    protected String makeDescription() {
+        final String result;
+        switch (getSubJobs().size()) {
             case 0:
-                description = "Unexecutable Send Backward"; // NO18N
+                result = "Unexecutable Send Backward"; // NO18N
                 break;
-            case 1:
-                description = subJobs.get(0).getDescription();
+            case 2: // one arrange Z order + one AdjustAllToggleGroup
+                result = getSubJobs().get(0).getDescription();
                 break;
             default:
-                description = makeMultipleSelectionDescription();
+                result = makeMultipleSelectionDescription();
                 break;
         }
+        return result;
+    }
+
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        // Selection unchanged
+        return getOldSelectionGroup();
     }
 
     private String makeMultipleSelectionDescription() {
         final StringBuilder result = new StringBuilder();
         result.append("Send Backward ");
-        result.append(subJobs.size());
+        result.append(getSubJobs().size() - 1);
         result.append(" Objects");
         return result.toString();
     }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendToBackJob.java	Thu Aug 21 19:53:02 2014 -0600
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/SendToBackJob.java	Fri Aug 22 09:42:07 2014 +0200
@@ -32,36 +32,31 @@
 package com.oracle.javafx.scenebuilder.kit.editor.job;
 
 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.job.togglegroup.AdjustAllToggleGroupJob;
+import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup;
 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 ArrangeZOrderJob {
+public class SendToBackJob extends BatchSelectionJob {
 
     public SendToBackJob(EditorController editorController) {
         super(editorController);
-        buildSubJobs();
     }
 
     @Override
-    public String getDescription() {
-        if (description == null) {
-            buildDescription();
-        }
-        return description;
-    }
+    protected List<Job> makeSubJobs() {
 
-    /*
-     * Private
-     */
-    private void buildSubJobs() {
+        final List<Job> result = new ArrayList<>();
 
         final Set<FXOMObject> candidates = new HashSet<>();
         final Selection selection = getEditorController().getSelection();
@@ -84,30 +79,45 @@
                 final ReIndexObjectJob subJob = new ReIndexObjectJob(
                         candidate, beforeChild, getEditorController());
                 if (subJob.isExecutable()) {
-                    subJobs.add(subJob);
+                    result.add(subJob);
                 }
             }
         }
+        
+        if (result.isEmpty() == false) {
+            // Finally we adjust toggle groups
+            result.add(new AdjustAllToggleGroupJob(getEditorController()));
+        }
+        return result;
     }
 
-    private void buildDescription() {
-        switch (subJobs.size()) {
+    @Override
+    protected String makeDescription() {
+        final String result;
+        switch (getSubJobs().size()) {
             case 0:
-                description = "Unexecutable Send To Back"; // NO18N
+                result = "Unexecutable Send To Back"; // NO18N
                 break;
-            case 1:
-                description = subJobs.get(0).getDescription();
+            case 2: // one arrange Z order + one AdjustAllToggleGroup
+                result = getSubJobs().get(0).getDescription();
                 break;
             default:
-                description = makeMultipleSelectionDescription();
+                result = makeMultipleSelectionDescription();
                 break;
         }
+        return result;
+    }
+
+    @Override
+    protected AbstractSelectionGroup getNewSelectionGroup() {
+        // Selection unchanged
+        return getOldSelectionGroup();
     }
 
     private String makeMultipleSelectionDescription() {
         final StringBuilder result = new StringBuilder();
         result.append("Send To Back ");
-        result.append(subJobs.size());
+        result.append(getSubJobs().size() - 1);
         result.append(" Objects");
         return result.toString();
     }