use of com.google.security.zynamics.binnavi.disassembly.CGroupNode in project binnavi by google.
the class CViewContent method createGroupNode.
@Override
public CGroupNode createGroupNode(final Collection<INaviViewNode> nodes) {
Preconditions.checkNotNull(nodes, "IE00297: Nodes argument can not be null");
Preconditions.checkArgument(!nodes.isEmpty(), "IE00298: Nodes list can not be empty");
final CGroupNode groupNode = new CGroupNode(-1, 0, 0, 0, 0, TEXTNODE_COLOR, false, true, new HashSet<CTag>(), null, false, provider);
for (final INaviViewNode node : nodes) {
Preconditions.checkNotNull(node, "IE00299: Nodes list contains a null-argument");
groupNode.addElement(node);
}
addNode(groupNode);
// Do not bother to update the graph type because group nodes have no effect on graph types.
groupNode.addListener(m_internalNodeListener);
groupNode.addGroupListener(m_internalNodeListener);
return groupNode;
}
use of com.google.security.zynamics.binnavi.disassembly.CGroupNode in project binnavi by google.
the class PostgreSQLGroupNodeLoader method setupGroupNodes.
/**
* Sets up the elements of the group nodes of a view.
*
* @param connection The connection to the database.
* @param view The view whose group nodes are set up.
* @param nodes The nodes of the view.
*
* @throws SQLException Thrown if setting up the group nodes fails.
*/
public static void setupGroupNodes(final CConnection connection, final INaviView view, final List<INaviViewNode> nodes) throws SQLException {
final String query = "SELECT id, parent_id FROM " + CTableNames.NODES_TABLE + " WHERE view_id = " + view.getConfiguration().getId() + " ORDER BY id";
int counter = 0;
int firstId = -1;
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
if (firstId == -1) {
firstId = resultSet.getInt("id");
}
final int parentId = resultSet.getInt("parent_id");
if (!resultSet.wasNull()) {
final INaviViewNode node = nodes.get(counter);
final INaviViewNode parent = nodes.get(parentId - firstId);
((CGroupNode) parent).addElement(node);
}
counter++;
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.CGroupNode in project binnavi by google.
the class PostgreSQLGroupNodeLoader method load.
/**
* Loads the group nodes of a view.
*
* @param provider The connection to the database.
* @param view The view whose group nodes are loaded.
* @param nodes The loaded nodes are stored here.
*
* @throws SQLException Thrown of loading the nodes failed.
* @throws CouldntLoadDataException
*/
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws SQLException, CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02513: provider argument can not be null");
Preconditions.checkNotNull(view, "IE02514: view argument can not be null");
Preconditions.checkNotNull(nodes, "IE02515: nodes argument can not be null");
final Map<Integer, INaviGroupNode> commentIdToGroupNode = new HashMap<Integer, INaviGroupNode>();
final String query = "SELECT id, comment_id , collapsed, x, y, width, height, color, selected, visible " + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.GROUP_NODES_TABLE + " ON id = node_id WHERE view_id = " + view.getConfiguration().getId();
try (ResultSet resultSet = provider.getConnection().executeQuery(query, true)) {
while (resultSet.next()) {
final int nodeId = resultSet.getInt("id");
Integer commentId = resultSet.getInt("comment_id");
if (resultSet.wasNull()) {
commentId = null;
}
final boolean collapsed = resultSet.getBoolean("collapsed");
final double posX = resultSet.getDouble("x");
final double posY = resultSet.getDouble("y");
final double width = resultSet.getDouble("width");
final double height = resultSet.getDouble("height");
final Color color = new Color(resultSet.getInt("color"));
final boolean selected = resultSet.getBoolean("selected");
final boolean visible = resultSet.getBoolean("visible");
final INaviGroupNode groupNode = new CGroupNode(nodeId, posX, posY, width, height, color, selected, visible, new HashSet<CTag>(), null, collapsed, provider);
if (commentId != null) {
commentIdToGroupNode.put(commentId, groupNode);
}
nodes.add(groupNode);
}
if (!commentIdToGroupNode.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToGroupNode.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
commentIdToGroupNode.get(commentIdToComment.getKey()).initializeComment(commentIdToComment.getValue());
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.CGroupNode in project binnavi by google.
the class GroupNodeTest method testSetCollapsed.
@Test
public void testSetCollapsed() {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final MockView mockView = new MockView();
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
final MockGroupNodeListener listener = new MockGroupNodeListener();
node.addListener(listener);
node.setCollapsed(true);
assertEquals("changedState;", listener.events);
assertTrue(node.isCollapsed());
node.removeListener(listener);
}
use of com.google.security.zynamics.binnavi.disassembly.CGroupNode in project binnavi by google.
the class View method createGroupNode.
// ! Creates a new group node.
/**
* Creates a new group node in the view.
*
* @param text Text that is shown when the group node is collapsed.
* @param elements Nodes that belong to the group node.
*
* @return The created group node.
*/
public GroupNode createGroupNode(final String text, final List<ViewNode> elements) {
Preconditions.checkNotNull(text, "Error: Text argument can not be null");
Preconditions.checkNotNull(elements, "Error: Elements argument can not be null");
final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
for (final ViewNode element : elements) {
Preconditions.checkNotNull(element, "Error: Elements list contains a null-element");
nodes.add(element.getNative());
}
final CGroupNode newGroupNode = naviView.getContent().createGroupNode(nodes);
return (GroupNode) cachedNodes.get(newGroupNode);
}
Aggregations