class AbstractPopupAdapter<T extends Element> extends MouseUtils.PopupMouseAdapter {

    protected final AbstractElementsDataTable<T> elementsDataTable;
    protected final JXTable table;

    public AbstractPopupAdapter(AbstractElementsDataTable<T> elementsDataTable) {
        super();
        this.elementsDataTable = elementsDataTable;
        this.table = elementsDataTable.getTable();
    }

    @Override
    protected void showPopup(final MouseEvent e) {<FILL_FUNCTION_BODY>}

    private void showPopup(int xpos, int ypos, final JPopupMenu popup) {
        if ((popup != null) && (popup.getSubElements().length > 0)) {
            final PopupMenuListener p = new PopupMenuListener() {

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                }

                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    popup.removePopupMenuListener(this);
                    table.requestFocus();
                }

                @Override
                public void popupMenuCanceled(PopupMenuEvent e) {
                }
            };
            popup.addPopupMenuListener(p);
            popup.show(table, xpos, ypos);
        }
    }

    protected abstract JPopupMenu createPopup(Point p);
}

        int selRow = table.rowAtPoint(e.getPoint());

        if (selRow != -1) {
            if (!table.getSelectionModel().isSelectedIndex(selRow)) {
                table.getSelectionModel().clearSelection();
                table.getSelectionModel().setSelectionInterval(selRow, selRow);
            }
            final Point p = e.getPoint();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final JPopupMenu pop = createPopup(p);
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            showPopup(p.x, p.y, pop);
                        }
                    });
                }
            }).start();
        } else {
            table.getSelectionModel().clearSelection();
        }
        e.consume();

    
<no_super_class>