# HG changeset patch # User Tom Rodriguez # Date 1450426230 28800 # Node ID 0b9cc0259f5aa6976cdade015c6ccd8495e77c79 # Parent 94a6bb5a58f2c17cdc1d0a885a412cea02606653 Make node searches look through all the graphs for a match diff -r 94a6bb5a58f2 -r 0b9cc0259f5a src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java Wed Dec 16 20:18:20 2015 -0800 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java Fri Dec 18 00:10:30 2015 -0800 @@ -37,4 +37,14 @@ InputGraph getGraph(); void setSelectedNodes(Set nodes); + + /** + * @return an iterator walking forward through the {@link InputGraph}s following the {@link #getGraph()} + */ + Iterable searchForward(); + + /** + * @return an iterator walking backward through the {@link InputGraph}s preceeding the {@link #getGraph()} + */ + Iterable searchBackward(); } diff -r 94a6bb5a58f2 -r 0b9cc0259f5a src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Wed Dec 16 20:18:20 2015 -0800 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Fri Dec 18 00:10:30 2015 -0800 @@ -445,5 +445,48 @@ void close() { filterChain.getChangedEvent().removeListener(filterChainChangedListener); sequenceFilterChain.getChangedEvent().removeListener(filterChainChangedListener); + } + + Iterable getGraphsForward() { + return new Iterable() { + + @Override + public Iterator iterator() { + return new Iterator() { + int index = getFirstPosition(); + + @Override + public boolean hasNext() { + return index + 1 < graphs.size(); + } + + @Override + public InputGraph next() { + return graphs.get(++index); + } + }; + } + }; + } + + Iterable getGraphsBackward() { + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + int index = getFirstPosition(); + + @Override + public boolean hasNext() { + return index - 1 > 0; + } + + @Override + public InputGraph next() { + return graphs.get(--index); + } + }; + } + }; + } } -} diff -r 94a6bb5a58f2 -r 0b9cc0259f5a src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java Wed Dec 16 20:18:20 2015 -0800 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java Fri Dec 18 00:10:30 2015 -0800 @@ -50,4 +50,14 @@ public void setSelectedNodes(Set nodes) { editor.setSelectedNodes(nodes); } + + @Override + public Iterable searchBackward() { + return editor.getDiagramModel().getGraphsBackward(); + } + + @Override + public Iterable searchForward() { + return editor.getDiagramModel().getGraphsForward(); + } } diff -r 94a6bb5a58f2 -r 0b9cc0259f5a src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java Wed Dec 16 20:18:20 2015 -0800 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java Fri Dec 18 00:10:30 2015 -0800 @@ -23,6 +23,7 @@ */ package com.sun.hotspot.igv.view; +import com.sun.hotspot.igv.data.InputGraph; import com.sun.hotspot.igv.data.InputNode; import com.sun.hotspot.igv.data.Properties; import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; @@ -81,57 +82,67 @@ final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class); if (p != null && p.getGraph() != null) { - List matches = null; - try { - RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); - Properties.PropertySelector selector = new Properties.PropertySelector<>(p.getGraph().getNodes()); - - matches = selector.selectMultiple(matcher); - } catch (Exception e) { - final String msg = e.getMessage(); - response.addResult(new Runnable() { - @Override - public void run() { - Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " - + "perhaps due to a malformed query string:\n" + msg, - NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(desc); - } - }, - "(Error during search)" - ); + InputGraph matchGraph = p.getGraph(); + // Search the current graph + List matches = findMatches(name, value, p.getGraph(), response); + if (matches == null) { + // See if the it hits in a later graph + for (InputGraph graph : p.searchForward()) { + matches = findMatches(name, value, graph, response); + if (matches != null) { + matchGraph = graph; + break; + } + } + } + if (matches == null) { + // See if it hits in a earlier graph + for (InputGraph graph : p.searchBackward()) { + matches = findMatches(name, value, graph, response); + if (matches != null) { + matchGraph = graph; + break; + } + } } if (matches != null) { final Set set = new HashSet<>(matches); + final InputGraph theGraph = p.getGraph() != matchGraph ? matchGraph : null; response.addResult(new Runnable() { @Override - public void run() { - final EditorTopComponent comp = EditorTopComponent.getActive(); - if (comp != null) { - comp.setSelectedNodes(set); - comp.requestActive(); + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + if (theGraph != null) { + comp.getDiagramModel().selectGraph(theGraph); } + comp.setSelectedNodes(set); + comp.requestActive(); } - }, - "All " + matches.size() + " matching nodes (" + name + "=" + value + ")" + } + }, + "All " + matches.size() + " matching nodes (" + name + "=" + value + ")" + (theGraph != null ? " in " + theGraph.getName() : "") ); // Single matches for (final InputNode n : matches) { response.addResult(new Runnable() { @Override - public void run() { - final EditorTopComponent comp = EditorTopComponent.getActive(); - if (comp != null) { - final Set tmpSet = new HashSet<>(); - tmpSet.add(n); - comp.setSelectedNodes(tmpSet); - comp.requestActive(); + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + final Set tmpSet = new HashSet<>(); + tmpSet.add(n); + if (theGraph != null) { + comp.getDiagramModel().selectGraph(theGraph); } + comp.setSelectedNodes(tmpSet); + comp.requestActive(); } - }, - n.getProperties().get(name) + " (" + n.getId() + " " + n.getProperties().get("name") + ")" + } + }, + n.getProperties().get(name) + " (" + n.getId() + " " + n.getProperties().get("name") + ")" + (theGraph != null ? " in " + theGraph.getName() : "") ); } } @@ -139,4 +150,27 @@ System.out.println("no input graph provider!"); } } + + private List findMatches(String name, String value, InputGraph inputGraph, SearchResponse response) { + try { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); + Properties.PropertySelector selector = new Properties.PropertySelector<>(inputGraph.getNodes()); + List matches = selector.selectMultiple(matcher); + return matches.size() == 0 ? null : matches; + } catch (Exception e) { + final String msg = e.getMessage(); + response.addResult(new Runnable() { + @Override + public void run() { + Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " + + "perhaps due to a malformed query string:\n" + msg, + NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(desc); + } + }, + "(Error during search)" + ); + } + return null; + } }