View | Details | Raw Unified | Return to bug 60961
Collapse All | Expand All

(-)src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java (-3 / +38 lines)
Lines 31-37 Link Here
31
import java.awt.event.ItemEvent;
31
import java.awt.event.ItemEvent;
32
import java.awt.event.ItemListener;
32
import java.awt.event.ItemListener;
33
import java.io.IOException;
33
import java.io.IOException;
34
import java.util.ArrayList;
35
import java.util.Arrays;
34
import java.util.Collections;
36
import java.util.Collections;
37
import java.util.Enumeration;
35
import java.util.HashMap;
38
import java.util.HashMap;
36
import java.util.List;
39
import java.util.List;
37
import java.util.Map;
40
import java.util.Map;
Lines 53-58 Link Here
53
import javax.swing.tree.DefaultMutableTreeNode;
56
import javax.swing.tree.DefaultMutableTreeNode;
54
import javax.swing.tree.DefaultTreeCellRenderer;
57
import javax.swing.tree.DefaultTreeCellRenderer;
55
import javax.swing.tree.DefaultTreeModel;
58
import javax.swing.tree.DefaultTreeModel;
59
import javax.swing.tree.TreeNode;
56
import javax.swing.tree.TreePath;
60
import javax.swing.tree.TreePath;
57
import javax.swing.tree.TreeSelectionModel;
61
import javax.swing.tree.TreeSelectionModel;
58
62
Lines 169-178 Link Here
169
     * Update the visualizer with new data.
173
     * Update the visualizer with new data.
170
     */
174
     */
171
    private void updateGui() {
175
    private void updateGui() {
176
        TreePath selectedPath = null;
172
        synchronized (buffer) {
177
        synchronized (buffer) {
173
            if (!dataChanged) {
178
            if (!dataChanged) {
174
                return;
179
                return;
175
            }
180
            }
181
            DefaultMutableTreeNode oldSelectedNode = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
182
            Object selectedSample = oldSelectedNode == null ? null : oldSelectedNode.getUserObject();
183
            final int selectedSampleHash = System.identityHashCode(selectedSample);
176
            root.removeAllChildren();
184
            root.removeAllChildren();
177
            for (Object sampler: buffer) {
185
            for (Object sampler: buffer) {
178
                SampleResult res = (SampleResult) sampler;
186
                SampleResult res = (SampleResult) sampler;
Lines 179-185 Link Here
179
                // Add sample
187
                // Add sample
180
                DefaultMutableTreeNode currNode = new SearchableTreeNode(res, treeModel);
188
                DefaultMutableTreeNode currNode = new SearchableTreeNode(res, treeModel);
181
                treeModel.insertNodeInto(currNode, root, root.getChildCount());
189
                treeModel.insertNodeInto(currNode, root, root.getChildCount());
182
                addSubResults(currNode, res);
190
                List<TreeNode> path = new ArrayList<>(Arrays.asList(root, currNode));
191
                if (selectedSample != null && System.identityHashCode(res) == selectedSampleHash) {
192
                    selectedPath = new TreePath(path.toArray(new TreeNode[path.size()]));
193
                }
194
                
195
                TreeNode[] potentialSelection = addSubResults(currNode, res, path, selectedSampleHash, selectedSample);
196
                if (potentialSelection != null) {
197
                    selectedPath = new TreePath(potentialSelection);
198
                }
183
                // Add any assertion that failed as children of the sample node
199
                // Add any assertion that failed as children of the sample node
184
                AssertionResult[] assertionResults = res.getAssertionResults();
200
                AssertionResult[] assertionResults = res.getAssertionResults();
185
                int assertionIndex = currNode.getChildCount();
201
                int assertionIndex = currNode.getChildCount();
Lines 187-192 Link Here
187
                    if (assertionResult.isFailure() || assertionResult.isError()) {
203
                    if (assertionResult.isFailure() || assertionResult.isError()) {
188
                        DefaultMutableTreeNode assertionNode = new SearchableTreeNode(assertionResult, treeModel);
204
                        DefaultMutableTreeNode assertionNode = new SearchableTreeNode(assertionResult, treeModel);
189
                        treeModel.insertNodeInto(assertionNode, currNode, assertionIndex++);
205
                        treeModel.insertNodeInto(assertionNode, currNode, assertionIndex++);
206
                        if (selectedSample != null && System.identityHashCode(assertionResult) == selectedSampleHash) {
207
                            TreeNode[] selected = path.toArray(new TreeNode[path.size() + 1]);
208
                            selected[selected.length - 1] = assertionNode; 
209
                            selectedPath = new TreePath(selected);
210
                        }
190
                    }
211
                    }
191
                }
212
                }
192
            }
213
            }
Lines 197-202 Link Here
197
        if (root.getChildCount() == 1) {
218
        if (root.getChildCount() == 1) {
198
            jTree.expandPath(new TreePath(root));
219
            jTree.expandPath(new TreePath(root));
199
        }
220
        }
221
        if (selectedPath != null) {
222
            jTree.setSelectionPath(selectedPath);
223
        }
200
        if (autoScrollCB.isSelected() && root.getChildCount() > 1) {
224
        if (autoScrollCB.isSelected() && root.getChildCount() > 1) {
201
            jTree.scrollPathToVisible(new TreePath(new Object[] { root,
225
            jTree.scrollPathToVisible(new TreePath(new Object[] { root,
202
                    treeModel.getChild(root, root.getChildCount() - 1) }));
226
                    treeModel.getChild(root, root.getChildCount() - 1) }));
Lines 203-212 Link Here
203
        }
227
        }
204
    }
228
    }
205
229
206
    private void addSubResults(DefaultMutableTreeNode currNode, SampleResult res) {
230
    private TreeNode[] addSubResults(DefaultMutableTreeNode currNode, SampleResult res, List<TreeNode> path, int selectedHash, Object selectedObject) {
207
        SampleResult[] subResults = res.getSubResults();
231
        SampleResult[] subResults = res.getSubResults();
208
232
209
        int leafIndex = 0;
233
        int leafIndex = 0;
234
        TreeNode[] result = null;
210
235
211
        for (SampleResult child : subResults) {
236
        for (SampleResult child : subResults) {
212
            log.debug("updateGui1 : child sample result - {}", child);
237
            log.debug("updateGui1 : child sample result - {}", child);
Lines 213-219 Link Here
213
            DefaultMutableTreeNode leafNode = new SearchableTreeNode(child, treeModel);
238
            DefaultMutableTreeNode leafNode = new SearchableTreeNode(child, treeModel);
214
239
215
            treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
240
            treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
216
            addSubResults(leafNode, child);
241
            List<TreeNode> newPath = new ArrayList<>(path);
242
            newPath.add(leafNode);
243
            if (selectedObject != null && System.identityHashCode(child) == selectedHash) {
244
                result = newPath.toArray(new TreeNode[newPath.size()]);
245
            }
246
            addSubResults(leafNode, child, newPath, selectedHash, selectedObject);
217
            // Add any assertion that failed as children of the sample node
247
            // Add any assertion that failed as children of the sample node
218
            AssertionResult[] assertionResults = child.getAssertionResults();
248
            AssertionResult[] assertionResults = child.getAssertionResults();
219
            int assertionIndex = leafNode.getChildCount();
249
            int assertionIndex = leafNode.getChildCount();
Lines 221-229 Link Here
221
                if (item.isFailure() || item.isError()) {
251
                if (item.isFailure() || item.isError()) {
222
                    DefaultMutableTreeNode assertionNode = new SearchableTreeNode(item, treeModel);
252
                    DefaultMutableTreeNode assertionNode = new SearchableTreeNode(item, treeModel);
223
                    treeModel.insertNodeInto(assertionNode, leafNode, assertionIndex++);
253
                    treeModel.insertNodeInto(assertionNode, leafNode, assertionIndex++);
254
                    if (selectedObject != null && System.identityHashCode(item) == selectedHash) {
255
                        result = path.toArray(new TreeNode[path.size() + 1]);
256
                        result[result.length - 1] = assertionNode; 
257
                    }
224
                }
258
                }
225
            }
259
            }
226
        }
260
        }
261
        return result;
227
    }
262
    }
228
263
229
    /** {@inheritDoc} */
264
    /** {@inheritDoc} */

Return to bug 60961