use of com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult in project binnavi by google.
the class CSearchExecuter method startNewSearch.
/**
* Cycles through an existing search operation.
*
* @param parent Parent window used for dialogs.
* @param editor Combobox editor whose color is changed depending on the search result.
* @param graph Graph to search through.
* @param searcher Executes the search over the graph.
* @param searchString The string to search for.
* @param zoomToResult True, to zoom to a result. False, to move without zooming.
*/
private static void startNewSearch(final Window parent, final ComboBoxEditor editor, final ZyGraph graph, final GraphSearcher searcher, final String searchString, final boolean zoomToResult) {
try {
// Search for all occurrences
searcher.search(GraphHelpers.getNodes(graph), GraphHelpers.getEdges(graph), searchString);
if (searcher.getResults().isEmpty()) {
editor.getEditorComponent().setBackground(BACKGROUND_COLOR_FAIL);
} else {
editor.getEditorComponent().setBackground(BACKGROUND_COLOR_SUCCESS);
}
// Immediately display all search occurrences
for (final SearchResult result : searcher.getResults()) {
if (result.getObject() instanceof NaviNode) {
final NaviNode node = (NaviNode) result.getObject();
node.setBackgroundColor(result.getLine(), result.getPosition(), result.getLength(), Color.YELLOW);
} else if (result.getObject() instanceof NaviEdge) {
final NaviEdge edge = (NaviEdge) result.getObject();
edge.getLabelContent().getLineContent(result.getLine()).setBackgroundColor(result.getPosition(), result.getLength(), Color.YELLOW);
}
}
final SearchResult result = searcher.getCursor().current();
if (result != null) {
if (result.getObject() instanceof NaviNode) {
ZyGraphHelpers.centerNode(graph, (NaviNode) result.getObject(), zoomToResult);
} else if (result.getObject() instanceof NaviEdge) {
ZyGraphHelpers.centerEdgeLabel(graph, (NaviEdge) result.getObject(), zoomToResult);
}
}
graph.updateGraphViews();
} catch (final PatternSyntaxException exception) {
// Do not bother to log this
CMessageBox.showInformation(parent, String.format("Invalid Regular Expression '%s'", searchString));
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult in project binnavi by google.
the class CSearchResultsDialog method setResults.
/**
* Fills the search results table model with search results data.
*
* @param results The search results data.
*/
private void setResults(final List<SearchResult> results) {
final Object[][] data = new Object[results.size()][1];
int counter = 0;
for (final SearchResult result : results) {
if (result.getObject() instanceof NaviNode) {
final NaviNode node = (NaviNode) result.getObject();
final ZyLabelContent labelContent = node.getRealizer().getNodeContent();
final String lineText = labelContent.getLineContent(result.getLine()).getText();
data[counter++][0] = lineText;
} else if (result.getObject() instanceof NaviEdge) {
final NaviEdge edge = (NaviEdge) result.getObject();
final ZyLabelContent labelContent = edge.getLabelContent();
final String lineText = labelContent.getLineContent(result.getLine()).getText();
data[counter++][0] = lineText;
}
}
m_table.setModel(new CResultsTableModel(data, new String[] { "Result" }));
m_resultsLabel.setText(String.format("%d search results", data.length));
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult in project binnavi by google.
the class CGraphFunctions method selectNodesWithString.
/**
* Selects all nodes of a graph that contain a given search string.
*
* @param graph The graph to search through and select.
* @param searchString The search string to search for.
*/
public static void selectNodesWithString(final ZyGraph graph, final String searchString) {
Preconditions.checkNotNull(graph, "IE02117: Graph argument can not be null");
Preconditions.checkNotNull(searchString, "IE02118: Search string argument can not be null");
final GraphSearcher searcher = new GraphSearcher();
searcher.search(GraphHelpers.getNodes(graph), new ArrayList<NaviEdge>(), searchString);
final List<SearchResult> results = searcher.getResults();
final List<NaviNode> resultNodes = new ArrayList<NaviNode>();
for (final SearchResult searchResult : results) {
resultNodes.add((NaviNode) searchResult.getObject());
}
graph.selectNodes(resultNodes, true);
searcher.dispose();
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult in project binnavi by google.
the class CGraphSearchField method jumpTo.
/**
* Jumps to a search result of the given index.
*
* @param index The index of the search result to jump to.
*/
public void jumpTo(final int index) {
m_searcher.getCursor().jumpTo(index);
final SearchResult result = m_searcher.getCursor().current();
if (result == null) {
return;
}
if (result.getObject() instanceof NaviNode) {
ZyGraphHelpers.centerNode(m_graph, (NaviNode) result.getObject(), false);
} else if (result.getObject() instanceof NaviEdge) {
ZyGraphHelpers.centerEdgeLabel(m_graph, (NaviEdge) result.getObject(), false);
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult in project binnavi by google.
the class GraphSearcher method clearResults.
/**
* Clears the results list.
*/
public void clearResults() {
for (final SearchResult result : m_results) {
if (result.getObject() instanceof NaviNode) {
((NaviNode) result.getObject()).setBackgroundColor(result.getLine(), result.getPosition(), result.getLength(), null);
} else if (result.getObject() instanceof NaviEdge) {
final NaviEdge edge = (NaviEdge) result.getObject();
final ZyLabelContent content = edge.getLabelContent();
content.getLineContent(result.getLine()).setBackgroundColor(result.getPosition(), result.getLength(), null);
}
}
m_results.clear();
m_cursor.clear();
m_changed = false;
}
Aggregations