jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1827349 - /jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java
Date Tue, 20 Mar 2018 19:25:42 GMT
Author: pmouawad
Date: Tue Mar 20 19:25:41 2018
New Revision: 1827349

URL: http://svn.apache.org/viewvc?rev=1827349&view=rev
Log:
[Bug 62156] Search Feature : Distinguish between node that matches search and node that contains
a child that matches search
Fix regression on expand and factor out some common code
Bugzilla Id: 62156

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java?rev=1827349&r1=1827348&r2=1827349&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/SearchTreeDialog.java Tue Mar 20 19:25:41
2018
@@ -244,14 +244,7 @@ public class SearchTreeDialog extends JD
                     logger.error("Error occurred searching for word:"+ wordToSearch+ " in
node:"+jMeterTreeNode.getName(), ex);
                 }
             }
-            GuiPackage guiInstance = GuiPackage.getInstance();
-            JTree jTree = guiInstance.getMainFrame().getTree();
-            for (JMeterTreeNode jMeterTreeNode : nodes) {
-                jMeterTreeNode.setMarkedBySearch(true);
-                if (expand) {
-                    jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
-                }
-            }
+            markConcernedNodes(expand, nodes);
         } finally {
             guiPackage.endUndoTransaction();
         }
@@ -261,12 +254,32 @@ public class SearchTreeDialog extends JD
                 MessageFormat.format(
                         JMeterUtils.getResString("search_tree_matches"), numberOfMatches));
     }
+
+    /**
+     * @param expand true if we want to expand
+     * @param nodes Set of {@link JMeterTreeNode} to mark
+     */
+    private void markConcernedNodes(boolean expand, Set<JMeterTreeNode> nodes) {
+        GuiPackage guiInstance = GuiPackage.getInstance();
+        JTree jTree = guiInstance.getMainFrame().getTree();
+        for (JMeterTreeNode jMeterTreeNode : nodes) {
+            jMeterTreeNode.setMarkedBySearch(true);
+            if (expand) {
+                if(jMeterTreeNode.isLeaf()) {
+                    jTree.expandPath(new TreePath(((JMeterTreeNode)jMeterTreeNode.getParent()).getPath()));
+                } else {
+                    jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
+                }
+            }
+        }
+    }
     
     /**
      * Replace all occurrences in nodes that contain {@link Replaceable} Test Elements
      * @param e {@link ActionEvent}
      */
     private void doReplaceAll(ActionEvent e) {
+        boolean expand = e.getSource()==searchAndExpandButton;
         String wordToSearch = searchTF.getText();
         String wordToReplace = replaceTF.getText();
 
@@ -313,13 +326,7 @@ public class SearchTreeDialog extends JD
             }
         }
         statusLabel.setText(MessageFormat.format("Replaced {0} occurrences", totalReplaced));
-        GuiPackage guiInstance = GuiPackage.getInstance();
-        JTree jTree = guiInstance.getMainFrame().getTree();
-
-        for (JMeterTreeNode jMeterTreeNode : nodes) {
-            jMeterTreeNode.setMarkedBySearch(true);
-            jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
-        }
+        markConcernedNodes(expand, nodes);
         // Update GUI as current node may be concerned by changes
         if (totalReplaced > 0) {
             GuiPackage.getInstance().refreshCurrentGui();



Mime
View raw message