Search in sources :

Example 31 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project zaproxy by zaproxy.

the class PopupMenuItemAlert method getNumberOfSelectedAlerts.

/**
     * Gets the number of selected alerts in the Alerts tree.
     * <p>
     * If multiple alert nodes are selected it returns the corresponding number of alerts. If just a middle alert node (that is,
     * the nodes that show the alert name) is selected it returns only one selected alert when {@link #isMultiSelect() multiple
     * selection} is not supported, otherwise it returns the number of child nodes (which is one alert per node).
     * 
     * @return the number of selected nodes
     */
private int getNumberOfSelectedAlerts() {
    JTree treeAlert = this.extAlert.getAlertPanel().getTreeAlert();
    int count = treeAlert.getSelectionCount();
    if (count == 0) {
        return 0;
    }
    if (count == 1) {
        DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) treeAlert.getSelectionPath().getLastPathComponent();
        if (alertNode.getChildCount() == 0 || !isMultiSelect()) {
            return 1;
        }
        return alertNode.getChildCount();
    }
    count = 0;
    TreePath[] paths = treeAlert.getSelectionPaths();
    for (int i = 0; i < paths.length; i++) {
        TreePath nodePath = paths[i];
        int childCount = ((DefaultMutableTreeNode) nodePath.getLastPathComponent()).getChildCount();
        count += childCount != 0 ? childCount : (treeAlert.isPathSelected(nodePath.getParentPath()) ? 0 : 1);
    }
    return count;
}
Also used : JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 32 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.

the class CDatabaseNodeTest method testUnloaded.

@Test
public void testUnloaded() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final CDatabaseNode node = new CDatabaseNode(m_tree, new DefaultMutableTreeNode(), m_database);
    m_database.load();
    node.dispose();
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")).isEmpty());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CDatabaseNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Database.CDatabaseNode) Test(org.junit.Test)

Example 33 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.

the class CDatabaseNodeTest method testListenersRemoved.

@Test
public void testListenersRemoved() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final CDatabaseNode node = new CDatabaseNode(m_tree, new DefaultMutableTreeNode(), m_database);
    node.dispose();
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")).isEmpty());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CDatabaseNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Database.CDatabaseNode) Test(org.junit.Test)

Example 34 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.

the class CDatabaseNodeTest method testConstructor.

@Test
public void testConstructor() {
    final CDatabaseNode node = new CDatabaseNode(m_tree, new DefaultMutableTreeNode(), m_database);
    assertEquals(m_database, node.getObject());
    assertNotNull(node.getComponent());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CDatabaseNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Database.CDatabaseNode) Test(org.junit.Test)

Example 35 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.

the class CDatabaseNodeTest method testLoaded.

@Test
public void testLoaded() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    m_database.load();
    final CDatabaseNode node = new CDatabaseNode(m_tree, new DefaultMutableTreeNode(), m_database);
    node.dispose();
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")).isEmpty());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CDatabaseNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Database.CDatabaseNode) Test(org.junit.Test)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)692 TreePath (javax.swing.tree.TreePath)185 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)98 ArrayList (java.util.ArrayList)51 Nullable (org.jetbrains.annotations.Nullable)50 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)38 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)23 TreeSelectionListener (javax.swing.event.TreeSelectionListener)23 Module (com.intellij.openapi.module.Module)20 File (java.io.File)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)19 MouseEvent (java.awt.event.MouseEvent)18 IOException (java.io.IOException)17 MProduct (org.compiere.model.MProduct)17