Search in sources :

Example 1 with DefaultSelectableHistoryReferencesContainer

use of org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer in project zaproxy by zaproxy.

the class AlertPanel method getTreeAlert.

/**
	 * This method initializes treeAlert	
	 * 	
	 * @return javax.swing.JTree	
	 */
JTree getTreeAlert() {
    if (treeAlert == null) {
        treeAlert = new JTree() {

            private static final long serialVersionUID = 1L;

            @Override
            public Point getPopupLocation(final MouseEvent event) {
                if (event != null) {
                    // Select item on right click
                    TreePath tp = treeAlert.getPathForLocation(event.getX(), event.getY());
                    if (tp != null) {
                        // to be selected
                        if (!treeAlert.getSelectionModel().isPathSelected(tp)) {
                            treeAlert.getSelectionModel().setSelectionPath(tp);
                        }
                    }
                }
                return super.getPopupLocation(event);
            }
        };
        treeAlert.setName(ALERT_TREE_PANEL_NAME);
        treeAlert.setShowsRootHandles(true);
        treeAlert.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        treeAlert.setComponentPopupMenu(new JPopupMenu() {

            private static final long serialVersionUID = 1L;

            @Override
            public void show(Component invoker, int x, int y) {
                final int countSelectedNodes = treeAlert.getSelectionCount();
                final ArrayList<HistoryReference> uniqueHistoryReferences = new ArrayList<>(countSelectedNodes);
                if (countSelectedNodes > 0) {
                    SortedSet<Integer> historyReferenceIdsAdded = new TreeSet<>();
                    for (TreePath path : treeAlert.getSelectionPaths()) {
                        final AlertNode node = (AlertNode) path.getLastPathComponent();
                        final Object userObject = node.getUserObject();
                        if (userObject instanceof Alert) {
                            HistoryReference historyReference = ((Alert) userObject).getHistoryRef();
                            if (historyReference != null && !historyReferenceIdsAdded.contains(Integer.valueOf(historyReference.getHistoryId()))) {
                                historyReferenceIdsAdded.add(Integer.valueOf(historyReference.getHistoryId()));
                                uniqueHistoryReferences.add(historyReference);
                            }
                        }
                    }
                    uniqueHistoryReferences.trimToSize();
                }
                SelectableHistoryReferencesContainer messageContainer = new DefaultSelectableHistoryReferencesContainer(treeAlert.getName(), treeAlert, Collections.<HistoryReference>emptyList(), uniqueHistoryReferences);
                view.getPopupMenu().show(messageContainer, x, y);
            }
        });
        treeAlert.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
                    // Its a double click - edit the alert
                    editSelectedAlert();
                }
            }
        });
        treeAlert.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeAlert.getLastSelectedPathComponent();
                if (node != null && node.getUserObject() != null) {
                    Object obj = node.getUserObject();
                    if (obj instanceof Alert) {
                        Alert alert = (Alert) obj;
                        setMessage(alert.getMessage(), alert.getEvidence());
                        treeAlert.requestFocusInWindow();
                        getAlertViewPanel().displayAlert(alert);
                    } else {
                        getAlertViewPanel().clearAlert();
                    }
                } else {
                    getAlertViewPanel().clearAlert();
                }
            }
        });
        treeAlert.setCellRenderer(new AlertTreeCellRenderer());
        treeAlert.setExpandsSelectedPaths(true);
    }
    return treeAlert;
}
Also used : DefaultSelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) SortedSet(java.util.SortedSet) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) HistoryReference(org.parosproxy.paros.model.HistoryReference) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MouseEvent(java.awt.event.MouseEvent) JTree(javax.swing.JTree) DefaultSelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer) SelectableHistoryReferencesContainer(org.zaproxy.zap.view.messagecontainer.http.SelectableHistoryReferencesContainer) TreePath(javax.swing.tree.TreePath) Alert(org.parosproxy.paros.core.scanner.Alert)

Aggregations

Component (java.awt.Component)1 Point (java.awt.Point)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 SortedSet (java.util.SortedSet)1 JPopupMenu (javax.swing.JPopupMenu)1 JTree (javax.swing.JTree)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 Alert (org.parosproxy.paros.core.scanner.Alert)1 HistoryReference (org.parosproxy.paros.model.HistoryReference)1 DefaultSelectableHistoryReferencesContainer (org.zaproxy.zap.view.messagecontainer.http.DefaultSelectableHistoryReferencesContainer)1 SelectableHistoryReferencesContainer (org.zaproxy.zap.view.messagecontainer.http.SelectableHistoryReferencesContainer)1