class ActionPopup extends MouseAdapter {

    private final JList<SearchResult> list;

    public ActionPopup(JList<SearchResult> list) {
        super();
        this.list = list;
    }

    @Override
    public void mousePressed(MouseEvent e) {
        maybePopup(e);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        maybePopup(e);
    }

    private void maybePopup(MouseEvent e) {<FILL_FUNCTION_BODY>}

    protected JPopupMenu createPopup(Point p) {
        SearchResult result = list.getSelectedValue();
        if (result != null) {
            if (result.getResult() instanceof Node) {
                return NodePopup.createPopup((Node) result.getResult());
            } else if (result.getResult() instanceof Edge) {
                return EdgePopup.createPopup((Edge) result.getResult());
            }
        }
        return null;
    }

    private void showPopup(int xpos, int ypos, final JPopupMenu popup) {
        if ((popup != null) && (popup.getSubElements().length > 0)) {
            popup.show(list, xpos, ypos);
        }
    }
}

        if (e.isPopupTrigger()) {
            SwingUtilities.invokeLater(() -> {
                final Point p = e.getPoint();
                int row = list.locationToIndex(e.getPoint());
                list.setSelectedIndex(row);
                final JPopupMenu pop = createPopup(p);
                if (pop != null) {
                    showPopup(p.x, p.y, pop);
                }
            });
        }
    
<methods>public void mouseClicked(java.awt.event.MouseEvent) ,public void mouseDragged(java.awt.event.MouseEvent) ,public void mouseEntered(java.awt.event.MouseEvent) ,public void mouseExited(java.awt.event.MouseEvent) ,public void mouseMoved(java.awt.event.MouseEvent) ,public void mousePressed(java.awt.event.MouseEvent) ,public void mouseReleased(java.awt.event.MouseEvent) ,public void mouseWheelMoved(java.awt.event.MouseWheelEvent) <variables>