Skip to content

Commit

Permalink
8263384: IGV: Outline should highlight the Graph that has focus
Browse files Browse the repository at this point in the history
Reviewed-by: xliu, chagedorn, thartmann
  • Loading branch information
robcasloz committed Jun 20, 2022
1 parent 7d4df6a commit 02da5f9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,8 @@
import com.sun.hotspot.igv.util.PropertiesSheet;
import java.awt.Image;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
Expand All @@ -44,6 +46,9 @@ public class FolderNode extends AbstractNode {

private InstanceContent content;
private FolderChildren children;
// NetBeans node corresponding to each opened graph. Used to highlight the
// focused graph in the Outline window.
private static Map<InputGraph, GraphNode> graphNode = new HashMap<>();

private static class FolderChildren extends Children.Keys<FolderElement> implements ChangedListener {

Expand All @@ -56,15 +61,26 @@ public FolderChildren(Folder folder) {

@Override
protected Node[] createNodes(FolderElement e) {
if (e instanceof InputGraph) {
return new Node[]{new GraphNode((InputGraph) e)};
if (e instanceof InputGraph) {
InputGraph g = (InputGraph) e;
GraphNode n = new GraphNode(g);
graphNode.put(g, n);
return new Node[]{n};
} else if (e instanceof Folder) {
return new Node[]{new FolderNode((Folder) e)};
} else {
return new Node[]{new FolderNode((Folder) e)};
} else {
return null;
}
}

@Override
protected void destroyNodes(Node[] nodes) {
for (Node n : nodes) {
// Each node is only present once in the graphNode map.
graphNode.values().remove(n);
}
}

@Override
public void addNotify() {
this.setKeys(folder.getElements());
Expand Down Expand Up @@ -105,6 +121,7 @@ private FolderNode(final Folder folder, FolderChildren children, InstanceContent
content.add(new RemoveCookie() {
@Override
public void remove() {
children.destroyNodes(children.getNodes());
folderElement.getParent().removeElement(folderElement);
}
});
Expand All @@ -124,4 +141,12 @@ public void init(String name, List<Group> groups) {
public Image getOpenedIcon(int i) {
return getIcon(i);
}

public static void clearGraphNodeMap() {
graphNode.clear();
}

public static GraphNode getGraphNode(InputGraph graph) {
return graphNode.get(graph);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,11 +28,14 @@
import com.sun.hotspot.igv.data.GraphDocument;
import com.sun.hotspot.igv.data.Group;
import com.sun.hotspot.igv.data.services.GroupCallback;
import com.sun.hotspot.igv.data.services.InputGraphProvider;
import com.sun.hotspot.igv.util.LookupHistory;
import java.awt.BorderLayout;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
import org.openide.ErrorManager;
Expand All @@ -42,9 +45,12 @@
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.explorer.view.BeanTreeView;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.util.actions.NodeAction;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
Expand All @@ -57,6 +63,7 @@ public final class OutlineTopComponent extends TopComponent implements ExplorerM

public static OutlineTopComponent instance;
public static final String PREFERRED_ID = "OutlineTopComponent";
private Lookup.Result result = null;
private ExplorerManager manager;
private GraphDocument document;
private FolderNode root;
Expand Down Expand Up @@ -123,8 +130,22 @@ public void started(Group g) {
binaryServer = new Server(getDocument(), callback, true);
}

// Fetch and select the latest active graph.
private void updateGraphSelection() {
final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
if (p == null) {
return;
}
try {
manager.setSelectedNodes(new GraphNode[]{FolderNode.getGraphNode(p.getGraph())});
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}

public void clear() {
document.clear();
FolderNode.clearGraphNodeMap();
root = new FolderNode(document);
manager.setRootContext(root);
}
Expand Down Expand Up @@ -173,11 +194,16 @@ public int getPersistenceType() {

@Override
public void componentOpened() {
Lookup.Template<InputGraphProvider> tpl = new Lookup.Template<InputGraphProvider>(InputGraphProvider.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
updateGraphSelection();
this.requestActive();
}

@Override
public void componentClosed() {
result.removeLookupListener(this);
}

@Override
Expand Down Expand Up @@ -205,6 +231,13 @@ protected boolean requestFocusInWindow(boolean temporary) {

@Override
public void resultChanged(LookupEvent lookupEvent) {
// Highlight the focused graph, if available, in the outline.
if (result.allItems().isEmpty()) {
return;
}
// Wait for LookupHistory to be updated with the last active graph
// before selecting it.
SwingUtilities.invokeLater(() -> updateGraphSelection());
}

@Override
Expand Down

1 comment on commit 02da5f9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.