Search in sources :

Example 1 with CGroupNode

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;
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 2 with CGroupNode

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++;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 3 with CGroupNode

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());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Color(java.awt.Color) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 4 with CGroupNode

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);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 5 with CGroupNode

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);
}
Also used : ArrayList(java.util.ArrayList) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IViewNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IViewNode) CNaviViewNode(com.google.security.zynamics.binnavi.disassembly.CNaviViewNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Aggregations

CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)12 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)7 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)7 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)7 Test (org.junit.Test)5 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)4 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)4 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)4 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)4 ArrayList (java.util.ArrayList)4 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)3 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)3 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)2 CUserManager (com.google.security.zynamics.binnavi.Gui.Users.CUserManager)2 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)2 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)2 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)2 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)2