[hg] main-silver: #226818: Remember the nodes we invoke actions ...

  • From:
  • To:
  • Subject: [hg] main-silver: #226818: Remember the nodes we invoke actions ...
  • Date: Thu, 07 Mar 2013 13:00:40 -0800

changeset 6f08bef5b72d in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/6f08bef5b72d
description:
        #226818: Remember the nodes we invoke actions on and use them in 
isEnabled() test.

diffstat:

 spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java |  32 
++++++++-
 spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java            |  35 
+++++++++-
 2 files changed, 61 insertions(+), 6 deletions(-)

diffs (138 lines):

diff --git 
a/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java 
b/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java
--- a/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java
+++ b/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java
@@ -398,13 +398,24 @@
     
     @Override
     public Action[] getActions (boolean context) {
+        Action[] actions;
         if (context) 
-            return treeModelRoot.getRootNode ().getActions (false);
+            actions = treeModelRoot.getRootNode ().getActions (false);
         try {
-            return filterActionsWhenSorted(model.getActions (object));
+            actions = filterActionsWhenSorted(model.getActions (object));
         } catch (UnknownTypeException e) {
             // NodeActionsProvider is voluntary
-            return new Action [0];
+            actions = new Action [0];
+        }
+        presetActionNodes(actions);
+        return actions;
+    }
+    
+    private void presetActionNodes(Action[] actions) {
+        for (Action a : actions) {
+            if (a instanceof ActionOnPresetNodes) {
+                ((ActionOnPresetNodes) a).addNode(this);
+            }
         }
     }
 
@@ -1217,6 +1228,21 @@
         
     }
 
+    /**
+     * An action, that can act on a pre-set set of nodes.
+     */
+    public static interface ActionOnPresetNodes extends Action {
+        
+        /**
+         * Add a node to act on.
+         * The set of nodes is cleared in the next cycle of event dispatch 
loop.
+         * When no nodes are provided, the TopComponent.getRegistry 
().getActivatedNodes () are used.
+         * @param n a node to act on
+         */
+        void addNode(Node n);
+        
+    }
+
     private class DisabledWhenSortedAction implements Action {
 
         private Action a;
diff --git a/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java 
b/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java
--- a/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java
+++ b/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java
@@ -77,6 +77,7 @@
 import org.netbeans.modules.viewmodel.DefaultTreeExpansionManager;
 import org.netbeans.modules.viewmodel.HyperCompoundModel;
 import org.netbeans.modules.viewmodel.OutlineTable;
+import org.netbeans.modules.viewmodel.TreeModelNode.ActionOnPresetNodes;
 import org.netbeans.modules.viewmodel.TreeModelNode.DisableableAction;
 import org.netbeans.modules.viewmodel.TreeModelRoot;
 
@@ -633,12 +634,14 @@
     /**
      * @author   Jan Jancura
      */
-    private static class ActionSupport extends AbstractAction implements 
DisableableAction {
+    private static class ActionSupport extends AbstractAction implements 
DisableableAction,
+                                                                         
ActionOnPresetNodes {
 
         private ActionPerformer     performer;
         private int                 multiselectionType;
         private String              displayName;
         private PrivilegedAction    enabledTest;
+        private List<Node>          presetNodes;
 
  
         ActionSupport (
@@ -653,6 +656,23 @@
         }
         
         @Override
+        public void addNode(Node n) {
+            if (presetNodes == null) {
+                presetNodes = new LinkedList<Node>();
+                SwingUtilities.invokeLater(new PresetNodesCleaner());
+            }
+            presetNodes.add(n);
+        }
+        
+        private Node[] getActiveNodes() {
+            if (presetNodes != null) {
+                return presetNodes.toArray(new Node[] {});
+            } else {
+                return TopComponent.getRegistry().getActivatedNodes();
+            }
+        }
+        
+        @Override
         public boolean isEnabled () {
             if (enabledTest != null) {
                 if (Boolean.FALSE.equals(enabledTest.run())) {
@@ -660,7 +680,7 @@
                 }
             }
             boolean any = multiselectionType == MULTISELECTION_TYPE_ANY;
-            Node[] ns = TopComponent.getRegistry ().getActivatedNodes ();
+            Node[] ns = getActiveNodes();
             if (multiselectionType == MULTISELECTION_TYPE_EXACTLY_ONE) {
                 if (ns.length != 1) return false;
                 return performer.isEnabled (
@@ -688,7 +708,7 @@
 
         public void actionPerformed (ActionEvent e) {
             
//System.err.println("Models.ActionSupport.actionPerformed("+e+")");
-            Node[] ns = TopComponent.getRegistry ().getActivatedNodes ();
+            Node[] ns = getActiveNodes();
             int i, k = ns.length;
             IdentityHashMap<Action, ArrayList<Object>> h = new 
IdentityHashMap<Action, ArrayList<Object>>();
             for (i = 0; i < k; i++) {
@@ -746,6 +766,15 @@
             }
             return a;
         }
+        
+        private class PresetNodesCleaner implements Runnable {
+
+            @Override
+            public void run() {
+                presetNodes = null;
+            }
+            
+        }
     }
 
     /**

[hg] main-silver: #226818: Remember the nodes we invoke actions ...

mentlicher 03/07/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close