Search in sources :

Example 26 with DefaultMutableTreeNode

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

the class AbstractParamContainerPanel method addParamPanel.

/**
     * Adds the given panel with the given name positioned under the given parents (or root node if none given).
     * <p>
     * If not sorted the panel is appended to existing panels.
     *
     * @param parentParams the name of the parent nodes of the panel, might be {@code null}.
     * @param name the name of the panel, must not be {@code null}.
     * @param panel the panel, must not be {@code null}.
     * @param sort {@code true} if the panel should be added in alphabetic order, {@code false} otherwise
     */
// ZAP: Added sort option
public void addParamPanel(String[] parentParams, String name, AbstractParamPanel panel, boolean sort) {
    if (parentParams != null) {
        addNewNode(addParamNode(parentParams, sort), new DefaultMutableTreeNode(name), sort);
    } else {
    // No need to create node.  This is the root panel.
    }
    panel.setName(name);
    getPanelParam().add(panel, name);
    tablePanel.put(name, panel);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 27 with DefaultMutableTreeNode

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

the class AbstractParamContainerPanel method renamePanel.

public void renamePanel(AbstractParamPanel panel, String newPanelName) {
    DefaultMutableTreeNode node = getTreeNodeFromPanelName(panel.getName(), true);
    DefaultMutableTreeNode newNode = getTreeNodeFromPanelName(newPanelName, true);
    if (node != null && newNode == null) {
        // TODO work out which of these lines are really necessary ;)
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        node.setUserObject(newPanelName);
        tablePanel.remove(panel.getName());
        int index = parent.getIndex(node);
        getTreeModel().removeNodeFromParent(node);
        getTreeModel().insertNodeInto(node, parent, index);
        if (panel == currentShownPanel) {
            this.nameLastSelectedPanel = newPanelName;
            this.currentShownPanel = null;
        }
        this.getPanelParam().remove(panel);
        panel.setName(newPanelName);
        tablePanel.put(newPanelName, panel);
        this.getPanelParam().add(newPanelName, panel);
        getTreeModel().nodeChanged(node);
        getTreeModel().nodeChanged(node.getParent());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 28 with DefaultMutableTreeNode

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

the class SiteMapPanel method getTreeSite.

/**
	 * This method initializes treeSite	
	 * 	
	 * @return javax.swing.JTree	
	 */
public JTree getTreeSite() {
    if (treeSite == null) {
        treeSite = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
        treeSite.setShowsRootHandles(true);
        treeSite.setName("treeSite");
        treeSite.setToggleClickCount(1);
        treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent();
                if (node == null) {
                    return;
                }
                if (!node.isRoot()) {
                    HttpMessage msg = null;
                    try {
                        msg = node.getHistoryReference().getHttpMessage();
                    } catch (Exception e1) {
                        // ZAP: Log exceptions
                        log.warn(e1.getMessage(), e1);
                        return;
                    }
                    getView().displayMessage(msg);
                    // ZAP: Call SiteMapListenners
                    for (SiteMapListener listener : listeners) {
                        listener.nodeSelected(node);
                    }
                } else {
                    // ZAP: clear the views when the root is selected
                    getView().displayMessage(null);
                }
            }
        });
        treeSite.setComponentPopupMenu(new SitesCustomPopupMenu());
        // ZAP: Add custom tree cell renderer.
        DefaultTreeCellRenderer renderer = new SiteMapTreeCellRenderer(listeners);
        treeSite.setCellRenderer(renderer);
    }
    return treeSite;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DatabaseException(org.parosproxy.paros.db.DatabaseException) JTree(javax.swing.JTree) SiteMapTreeCellRenderer(org.zaproxy.zap.view.SiteMapTreeCellRenderer) HttpMessage(org.parosproxy.paros.network.HttpMessage) SiteMapListener(org.zaproxy.zap.view.SiteMapListener) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 29 with DefaultMutableTreeNode

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

the class AbstractParamContainerPanel method showDialog.

// ZAP: Added option to specify panel - note this only supports one level at the moment
// ZAP: show the last selected panel
public void showDialog(boolean showRoot, String panel) {
    expandRoot();
    try {
        DefaultMutableTreeNode node = null;
        if (panel != null) {
            node = getTreeNodeFromPanelName(panel);
        }
        if (node == null) {
            if (nameLastSelectedPanel != null) {
                node = getTreeNodeFromPanelName(nameLastSelectedPanel);
            } else if (showRoot) {
                node = (DefaultMutableTreeNode) getTreeModel().getRoot();
            } else if (((DefaultMutableTreeNode) getTreeModel().getRoot()).getChildCount() > 0) {
                node = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) getTreeModel().getRoot()).getChildAt(0);
            }
        }
        if (node != null) {
            showParamPanel(node.toString());
            getTreeParam().setSelectionPath(new TreePath(node.getPath()));
        }
    } catch (Exception e) {
        // ZAP: log errors
        log.error(e.getMessage(), e);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 30 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode 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)

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