Search in sources :

Example 1 with DeleteContextAction

use of org.zaproxy.zap.view.DeleteContextAction in project zaproxy by zaproxy.

the class ExtensionStdMenus method getPopupContextTreeMenuDelete.

private PopupContextTreeMenu getPopupContextTreeMenuDelete() {
    if (popupContextTreeMenuDelete == null) {
        popupContextTreeMenuDelete = new PopupContextTreeMenu();
        popupContextTreeMenuDelete.setAction(new DeleteContextAction() {

            private static final long serialVersionUID = 1L;

            @Override
            protected List<Context> getContexts() {
                List<Context> contexts = new ArrayList<>();
                for (Integer id : popupContextTreeMenuDelete.getContextIds()) {
                    contexts.add(Model.getSingleton().getSession().getContext(id));
                }
                return contexts;
            }

            @Override
            protected Context getContext() {
                return Model.getSingleton().getSession().getContext(popupContextTreeMenuDelete.getContextId());
            }
        });
        popupContextTreeMenuDelete.setText(Constant.messages.getString("context.delete.popup"));
    }
    return popupContextTreeMenuDelete;
}
Also used : Context(org.zaproxy.zap.model.Context) ArrayList(java.util.ArrayList) List(java.util.List) DeleteContextAction(org.zaproxy.zap.view.DeleteContextAction)

Example 2 with DeleteContextAction

use of org.zaproxy.zap.view.DeleteContextAction in project zaproxy by zaproxy.

the class SiteMapPanel method getTreeContext.

private JTree getTreeContext() {
    if (treeContext == null) {
        reloadContextTree();
        treeContext = new JTree(this.contextTree);
        treeContext.setShowsRootHandles(true);
        treeContext.setName(CONTEXT_TREE_COMPONENT_NAME);
        treeContext.setToggleClickCount(1);
        treeContext.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
        treeContext.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                mouseClicked(e);
            }

            @Override
            public void mouseClicked(java.awt.event.MouseEvent e) {
                TreePath path = treeContext.getClosestPathForLocation(e.getX(), e.getY());
                if (treeSite.getLastSelectedPathComponent() != null) {
                    getTreeSite().clearSelection();
                }
                if (path != null) {
                    if (((SiteNode) path.getLastPathComponent()).isRoot()) {
                        treeContext.removeSelectionPath(path);
                    }
                }
                if (e.getClickCount() > 1) {
                    // Its a double click - show the relevant context dialog
                    SiteNode node = (SiteNode) treeContext.getLastSelectedPathComponent();
                    if (node != null && node.getUserObject() != null) {
                        Target target = (Target) node.getUserObject();
                        String panelName = ContextGeneralPanel.getPanelName(target.getContext());
                        getView().getSessionDialog().expandParamPanelNode(panelName);
                        if (getView().getSessionDialog().isParamPanelOrChildSelected(panelName)) {
                            panelName = null;
                        }
                        getView().showSessionDialog(Model.getSingleton().getSession(), panelName);
                    }
                }
            }
        });
        treeContext.setComponentPopupMenu(new ContextsCustomPopupMenu());
        treeContext.setCellRenderer(new ContextsTreeCellRenderer());
        DeleteContextAction delContextAction = new DeleteContextAction() {

            private static final long serialVersionUID = 1L;

            @Override
            protected List<Context> getContexts() {
                return getSelectedContexts();
            }

            @Override
            protected Context getContext() {
                return getSelectedContext();
            }
        };
        treeContext.getInputMap().put((KeyStroke) delContextAction.getValue(DeleteContextAction.ACCELERATOR_KEY), DeleteContextAction.ACTION_NAME);
        treeContext.getActionMap().put(DeleteContextAction.ACTION_NAME, delContextAction);
    }
    return treeContext;
}
Also used : Context(org.zaproxy.zap.model.Context) ContextsTreeCellRenderer(org.zaproxy.zap.view.ContextsTreeCellRenderer) JTree(javax.swing.JTree) Target(org.zaproxy.zap.model.Target) TreePath(javax.swing.tree.TreePath) DeleteContextAction(org.zaproxy.zap.view.DeleteContextAction) SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

Context (org.zaproxy.zap.model.Context)2 DeleteContextAction (org.zaproxy.zap.view.DeleteContextAction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 SiteNode (org.parosproxy.paros.model.SiteNode)1 Target (org.zaproxy.zap.model.Target)1 ContextsTreeCellRenderer (org.zaproxy.zap.view.ContextsTreeCellRenderer)1