Skip to content

Commit

Permalink
6923: Retain treeview stack trace while switching between JFRs
Browse files Browse the repository at this point in the history
Reviewed-by: aptmac
  • Loading branch information
Guru Hb committed Jun 10, 2021
1 parent f2e80e7 commit df466e7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.WeakHashMap;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -208,6 +210,7 @@ public void run() {
private IAction[] layoutActions;
private ViewerAction[] viewerActions;
private int[] columnWidths;
private Map<IItemCollection, Object[]> treeViewerExpandedItems = new WeakHashMap<>();

private static class StacktraceViewToolTipSupport extends ColumnViewerToolTipSupport {

Expand Down Expand Up @@ -703,6 +706,13 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
}

private void setItems(IItemCollection items) {
if (viewer.getInput() != null && viewer instanceof TreeViewer && itemsToShow.hasItems()) {
// persist the older items expandedElements
Object[] expandedElements = ((TreeViewer) viewer).getExpandedElements();
if (expandedElements.length > 0) {
treeViewerExpandedItems.put(itemsToShow, expandedElements);
}
}
itemsToShow = items;
rebuildModel();
}
Expand Down Expand Up @@ -747,7 +757,13 @@ private void setModel(StacktraceModel model) {

private void setViewerInput(Fork rootFork) {
// NOTE: will be slow for TreeViewer if number of roots or children of a node are more than ~1000
viewer.setInput(rootFork);
if (rootFork != null && viewer instanceof TreeViewer && treeViewerExpandedItems.containsKey(itemsToShow)) {
Object[] expandedElements = treeViewerExpandedItems.get(itemsToShow);
viewer.setInput(rootFork);
((TreeViewer) viewer).setExpandedElements(expandedElements);
} else {
viewer.setInput(rootFork);
}
}

private ITreeContentProvider createTreeContentProvider() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -100,4 +100,42 @@ public int getItemCount() {
return items.size();
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((frame == null) ? 0 : frame.hashCode());
result = prime * result + indexInBranch;
result = prime * result + ((items == null) ? 0 : items.size());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StacktraceFrame other = (StacktraceFrame) obj;

if (branch == null) {
if (other.branch != null)
return false;
}
if (frame == null) {
if (other.frame != null) {
return false;
}
}
if (indexInBranch != other.indexInBranch)
return false;
if (items == null || other.items == null) {
return false;
} else if (items.size() != other.items.size())
return false;
return true;
}

}

0 comments on commit df466e7

Please sign in to comment.