Skip to content

Commit

Permalink
8290063: IGV: Give the graphs a unique number in the outline
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, chagedorn
  • Loading branch information
tobiasholenstein committed Nov 2, 2022
1 parent b807470 commit a1c349f
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
import com.sun.hotspot.igv.util.StringUtils;
import java.awt.Image;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet;
import javax.swing.Action;
import org.openide.actions.PropertiesAction;
import org.openide.actions.RenameAction;
import org.openide.nodes.*;
import org.openide.util.ImageUtilities;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
Expand All @@ -49,7 +48,7 @@ public class FolderNode extends AbstractNode {
private final FolderChildren children;
// NetBeans node corresponding to each opened graph. Used to highlight the
// focused graph in the Outline window.
private static final Map<InputGraph, GraphNode> graphNode = new HashMap<>();
private static final Map<InputGraph, GraphNode> graphNodeMap = new HashMap<>();
private boolean selected = false;

private static class FolderChildren extends Children.Keys<FolderElement> implements ChangedListener {
Expand All @@ -66,14 +65,14 @@ public Folder getFolder() {
}

@Override
protected Node[] createNodes(FolderElement 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)};
protected Node[] createNodes(FolderElement folderElement) {
if (folderElement instanceof InputGraph) {
InputGraph inputGraph = (InputGraph) folderElement;
GraphNode graphNode = new GraphNode(inputGraph);
graphNodeMap.put(inputGraph, graphNode);
return new Node[]{graphNode};
} else if (folderElement instanceof Group) {
return new Node[]{new FolderNode((Group) folderElement)};
} else {
return null;
}
Expand All @@ -83,19 +82,23 @@ protected Node[] createNodes(FolderElement e) {
protected void destroyNodes(Node[] nodes) {
for (Node n : nodes) {
// Each node is only present once in the graphNode map.
graphNode.values().remove(n);
graphNodeMap.values().remove(n);
}
for (Node node : getNodes()) {
node.setDisplayName(node.getDisplayName());
}
}

@Override
public void addNotify() {
this.setKeys(folder.getElements());
super.addNotify();
setKeys(folder.getElements());
}

@Override
public void changed(Object source) {
addNotify();
}
}
}

@Override
Expand Down Expand Up @@ -128,7 +131,7 @@ private FolderNode(final Folder folder, FolderChildren children, InstanceContent
if (folder instanceof FolderElement) {
final FolderElement folderElement = (FolderElement) folder;
this.setDisplayName(folderElement.getName());
content.add((RemoveCookie) () -> {
this.content.add((RemoveCookie) () -> {
children.destroyNodes(children.getNodes());
folderElement.getParent().removeElement(folderElement);
});
Expand All @@ -141,6 +144,28 @@ public void setSelected(boolean selected) {
fireIconChange();
}

@Override
public boolean canRename() {
return true;
}

@Override
public void setName(String name) {
children.getFolder().setName(name);
fireDisplayNameChange(null, null);
}

@Override
public String getName() {
return children.getFolder().getName();
}

@Override
public String getDisplayName() {
return children.getFolder().getDisplayName();
}

@Override
public String getHtmlDisplayName() {
String htmlDisplayName = StringUtils.escapeHTML(getDisplayName());
if (selected) {
Expand All @@ -149,15 +174,6 @@ public String getHtmlDisplayName() {
return htmlDisplayName;
}

public void init(String name, List<Group> groups) {
this.setDisplayName(name);
children.addNotify();

for (Group g : groups) {
content.add(g);
}
}

public boolean isRootNode() {
Folder folder = getFolder();
return (folder instanceof GraphDocument);
Expand All @@ -168,12 +184,20 @@ public Image getOpenedIcon(int i) {
return getIcon(i);
}

@Override
public Action[] getActions(boolean b) {
return new Action[]{
RenameAction.findObject(RenameAction.class, true),
PropertiesAction.findObject(PropertiesAction.class, true),
};
}

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

public static GraphNode getGraphNode(InputGraph graph) {
return graphNode.get(graph);
return graphNodeMap.get(graph);
}

public Folder getFolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.awt.Image;
import javax.swing.Action;
import org.openide.actions.OpenAction;
import org.openide.actions.RenameAction;
import org.openide.nodes.*;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
Expand All @@ -44,27 +45,50 @@
*/
public class GraphNode extends AbstractNode {

private InputGraph graph;
private final InputGraph graph;
private boolean selected = false;

/** Creates a new instance of GraphNode */
public GraphNode(InputGraph graph) {
this(graph, new InstanceContent());
}

@Override
public boolean canRename() {
return true;
}

@Override
public void setName(String name) {
graph.setName(name);
fireDisplayNameChange(null, null);
}

@Override
public String getName() {
return graph.getName();
}

public void setSelected(boolean selected) {
this.selected = selected;
fireDisplayNameChange(null, null);
fireIconChange();
}

@Override
public String getHtmlDisplayName() {
String htmlDisplayName = StringUtils.escapeHTML(getDisplayName());
if (selected) {
htmlDisplayName = "<b>" + htmlDisplayName + "</b>";
}
return htmlDisplayName;
}

@Override
public String getDisplayName() {
return graph.getDisplayName();
}

private GraphNode(InputGraph graph, InstanceContent content) {
super(Children.LEAF, new AbstractLookup(content));
this.graph = graph;
Expand All @@ -86,13 +110,6 @@ private GraphNode(InputGraph graph, InstanceContent content) {

// Action for cloning to the current graph
content.add(new GraphCloneCookie(viewer, graph));

this.addNodeListener(new NodeAdapter() {
@Override
public void childrenRemoved(NodeMemberEvent ev) {
GraphNode.this.graph = null;
}
});
}

@Override
Expand Down Expand Up @@ -122,7 +139,12 @@ public Image getOpenedIcon(int i) {

@Override
public Action[] getActions(boolean b) {
return new Action[]{DiffGraphAction.findObject(DiffGraphAction.class, true), CloneGraphAction.findObject(CloneGraphAction.class, true), OpenAction.findObject(OpenAction.class, true)};
return new Action[]{
RenameAction.findObject(RenameAction.class, true),
DiffGraphAction.findObject(DiffGraphAction.class, true),
CloneGraphAction.findObject(CloneGraphAction.class, true),
OpenAction.findObject(OpenAction.class, true)
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<file name="DS-W.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.instance"/>
</file>
<file name="AD-R.shadow">
<attr name="originalFile" stringvalue="Actions/System/org-openide-actions-RenameAction.instance"/>
</file>
</folder>
<folder name="Actions">
<folder name="File">
Expand Down Expand Up @@ -58,27 +61,35 @@
</file>
<file name="SeparatorSave.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="150"/>
<attr name="position" intvalue="200"/>
</file>
<file name="org-openide-actions-RenameAction.shadow">
<attr name="originalFile" stringvalue="Actions/System/org-openide-actions-RenameAction.instance"/>
<attr name="position" intvalue="300"/>
</file>
<file name="SeparatorRename.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="400"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAsAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAsAction.instance"/>
<attr name="position" intvalue="200"/>
<attr name="position" intvalue="500"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAllAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAllAction.instance"/>
<attr name="position" intvalue="300"/>
<attr name="position" intvalue="600"/>
</file>
<file name="SeparatorRemove.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="350"/>
<attr name="position" intvalue="700"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-RemoveAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-RemoveAction.instance"/>
<attr name="position" intvalue="400"/>
<attr name="position" intvalue="800"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.instance"/>
<attr name="position" intvalue="500"/>
<attr name="position" intvalue="900"/>
</file>
<!-- Hidden menu entries from other modules -->
<file name="org-netbeans-modules-editor-ExportHtmlAction.shadow_hidden"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.util.List;

public interface Folder {
void setName(String name);
String getName();
String getDisplayName();
List<? extends FolderElement> getElements();
void removeElement(FolderElement element);
void addElement(FolderElement group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
package com.sun.hotspot.igv.data;

public interface FolderElement {

Folder getParent();
ChangedEvent<? extends FolderElement> getDisplayNameChangedEvent();
void setName(String name);
String getName();
String getDisplayName();
void setParent(Folder parent);
Folder getParent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public class GraphDocument extends Properties.Entity implements ChangedEventProv

private final List<FolderElement> elements;
private final ChangedEvent<GraphDocument> changedEvent;
private String name;

public GraphDocument() {
elements = new ArrayList<>();
changedEvent = new ChangedEvent<>(this);
setName("GraphDocument");
}

public void clear() {
Expand All @@ -61,10 +63,23 @@ public void addGraphDocument(GraphDocument document) {
getChangedEvent().fire();
}

@Override
public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

@Override
public String getDisplayName() {
return getName();
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();

sb.append("GraphDocument: ").append(getProperties().toString()).append(" \n\n");
for (FolderElement g : getElements()) {
sb.append(g.toString());
Expand All @@ -84,6 +99,9 @@ public void removeElement(FolderElement element) {
if (elements.remove(element)) {
getChangedEvent().fire();
}
for (FolderElement folderElement : elements) {
folderElement.getDisplayNameChangedEvent().fire();
}
}

@Override
Expand Down
Loading

1 comment on commit a1c349f

@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.