Search in sources :

Example 31 with TreePath

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

the class PopupMenuItemAlert method getAlertNodes.

private Set<Alert> getAlertNodes() {
    TreePath[] paths = this.extAlert.getAlertPanel().getTreeAlert().getSelectionPaths();
    if (paths == null || paths.length == 0) {
        return Collections.emptySet();
    }
    HashSet<Alert> alertNodes = new HashSet<Alert>();
    if (!isMultiSelect()) {
        DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) paths[0].getLastPathComponent();
        alertNodes.add((Alert) alertNode.getUserObject());
        return alertNodes;
    }
    for (int i = 0; i < paths.length; i++) {
        DefaultMutableTreeNode alertNode = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
        if (alertNode.getChildCount() == 0) {
            alertNodes.add((Alert) alertNode.getUserObject());
            continue;
        }
        for (int j = 0; j < alertNode.getChildCount(); j++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) alertNode.getChildAt(j);
            alertNodes.add((Alert) node.getUserObject());
        }
    }
    return alertNodes;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Alert(org.parosproxy.paros.core.scanner.Alert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) HashSet(java.util.HashSet)

Example 32 with TreePath

use of javax.swing.tree.TreePath 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 33 with TreePath

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

the class ExtensionBreak method getMenuAddHttpBreakpoint.

private ZapMenuItem getMenuAddHttpBreakpoint() {
    if (menuHttpBreakpoint == null) {
        menuHttpBreakpoint = new ZapMenuItem("menu.tools.brk.custom", KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
        menuHttpBreakpoint.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                // Check to see if anything is selected in the main tabs
                String url = "";
                Component c = View.getSingleton().getMainFrame().getFocusOwner();
                if (c != null) {
                    if (c instanceof JList) {
                        // Handles the history list and similar
                        @SuppressWarnings("rawtypes") Object sel = ((JList) c).getSelectedValue();
                        try {
                            if (sel != null && sel instanceof HistoryReference && ((HistoryReference) sel).getURI() != null) {
                                url = ((HistoryReference) sel).getURI().toString();
                            }
                        } catch (Exception e1) {
                        // Ignore
                        }
                    } else if (c instanceof JTree) {
                        // Handles the Sites tree
                        TreePath path = ((JTree) c).getSelectionPath();
                        try {
                            if (path != null && path.getLastPathComponent() instanceof SiteNode) {
                                url = ((SiteNode) path.getLastPathComponent()).getHistoryReference().getURI().toString();
                            }
                        } catch (Exception e1) {
                        // Ignore
                        }
                    }
                }
                httpBreakpoints.handleAddBreakpoint(url);
            }
        });
    }
    return menuHttpBreakpoint;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) HistoryReference(org.parosproxy.paros.model.HistoryReference) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) ZapMenuItem(org.zaproxy.zap.view.ZapMenuItem) Component(java.awt.Component) JList(javax.swing.JList) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 34 with TreePath

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

the class SiteMapPanel method showInSites.

public void showInSites(SiteNode node) {
    TreeNode[] path = node.getPath();
    TreePath tp = new TreePath(path);
    treeSite.setExpandsSelectedPaths(true);
    treeSite.setSelectionPath(tp);
    treeSite.scrollPathToVisible(tp);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 35 with TreePath

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

the class AbstractParamContainerPanel method getTreeParam.

/**
     * This method initializes treeParam
     *
     * @return javax.swing.JTree
     */
private JTree getTreeParam() {
    if (treeParam == null) {
        treeParam = new JTree();
        treeParam.setModel(getTreeModel());
        treeParam.setShowsRootHandles(true);
        treeParam.setRootVisible(true);
        treeParam.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) getTreeParam().getLastSelectedPathComponent();
                if (node == null) {
                    return;
                }
                String name = (String) node.getUserObject();
                showParamPanel(name);
            }
        });
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setLeafIcon(null);
        renderer.setOpenIcon(null);
        renderer.setClosedIcon(null);
        treeParam.setCellRenderer(renderer);
        treeParam.setRowHeight(DisplayUtils.getScaledSize(18));
        treeParam.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                TreePath path = treeParam.getClosestPathForLocation(e.getX(), e.getY());
                if (path != null && !treeParam.isPathSelected(path)) {
                    treeParam.setSelectionPath(path);
                }
            }
        });
    }
    return treeParam;
}
Also used : JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11