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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations