<commit_before>package net.argius.stew.ui.window;

import static java.awt.EventQueue.invokeLater;
import static java.awt.event.InputEvent.ALT_DOWN_MASK;
import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
import static java.awt.event.KeyEvent.VK_C;
import static java.util.Collections.emptyList;
import static java.util.Collections.nCopies;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.text.TextUtilities.join;
import static net.argius.stew.ui.window.AnyActionKey.copy;
import static net.argius.stew.ui.window.AnyActionKey.refresh;
import static net.argius.stew.ui.window.DatabaseInfoTree.ActionKey.*;
import static net.argius.stew.ui.window.WindowOutputProcessor.showInformationMessageDialog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import net.argius.stew.*;

/**
 * The Database Information Tree is a tree pane that provides to
 * display database object information from DatabaseMetaData.
 */
final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSearch {

    enum ActionKey {
        copySimpleName,
        copyFullName,
        generateWherePhrase,
        generateSelectPhrase,
        generateUpdateStatement,
        generateInsertStatement,
        jumpToColumnByName,
        toggleShowColumnNumber
    }

    private static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
    private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class);

    static volatile boolean showColumnNumber;

    private Connector currentConnector;
    private DatabaseMetaData dbmeta;
    private AnyActionListener anyActionListener;

    DatabaseInfoTree(AnyActionListener anyActionListener) {
        this.anyActionListener = anyActionListener;
        setRootVisible(false);
        setShowsRootHandles(false);
        setScrollsOnExpand(true);
        setCellRenderer(new Renderer());
        setModel(new DefaultTreeModel(null));
        // [Events]
        int sckm = Utilities.getMenuShortcutKeyMask();
        AnyAction aa = new AnyAction(this);
        aa.bindKeyStroke(false, copy, KeyStroke.getKeyStroke(VK_C, sckm));
        aa.bindSelf(copySimpleName, getKeyStroke(VK_C, sckm | ALT_DOWN_MASK));
        aa.bindSelf(copyFullName, getKeyStroke(VK_C, sckm | SHIFT_DOWN_MASK));
    }

    @Override
    protected void processMouseEvent(MouseEvent e) {
        super.processMouseEvent(e);
        if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() % 2 == 0) {
            anyActionPerformed(new AnyActionEvent(this, jumpToColumnByName));
        }
    }

    @Override
    public void anyActionPerformed(AnyActionEvent ev) {
        log.atEnter("anyActionPerformed", ev);
        if (ev.isAnyOf(copy)) {
            Object src = ev.getSource();
            if (src != null && src instanceof JMenuItem) {
                KeyStroke k = ((JMenuItem)src).getAccelerator();
                if (k != null) {
                    ActionListener action = getActionForKeyStroke(k);
                    if (action != null) {
                        action.actionPerformed(new ActionEvent(this, 1001, ""));
                    }
                }
            }
        } else if (ev.isAnyOf(copySimpleName)) {
            copySimpleName();
        } else if (ev.isAnyOf(copyFullName)) {
            copyFullName();
        } else if (ev.isAnyOf(refresh)) {
            for (TreePath path : getSelectionPaths()) {
                refresh((InfoNode)path.getLastPathComponent());
            }
        } else if (ev.isAnyOf(generateWherePhrase)) {
            List<ColumnNode> columnNodes = new ArrayList<ColumnNode>();
            for (TreeNode node : getSelectionNodes()) {
                if (node instanceof ColumnNode) {
                    columnNodes.add((ColumnNode)node);
                }
            }
            final String phrase = generateEquivalentJoinClause(columnNodes);
            if (phrase.length() > 0) {
                insertTextIntoTextArea(addCommas(phrase));
            }
        } else if (ev.isAnyOf(generateSelectPhrase)) {
            final String phrase = generateSelectPhrase(getSelectionNodes());
            if (phrase.length() > 0) {<commit_msg>Fix #32187: anyActionPerformed -> getActionMap().get(cmd).actionPerformed...<commit_after>package net.argius.stew.ui.window;

import static java.awt.EventQueue.invokeLater;
import static java.awt.event.InputEvent.ALT_DOWN_MASK;
import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
import static java.awt.event.KeyEvent.VK_C;
import static java.util.Collections.emptyList;
import static java.util.Collections.nCopies;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.text.TextUtilities.join;
import static net.argius.stew.ui.window.AnyActionKey.copy;
import static net.argius.stew.ui.window.AnyActionKey.refresh;
import static net.argius.stew.ui.window.DatabaseInfoTree.ActionKey.*;
import static net.argius.stew.ui.window.WindowOutputProcessor.showInformationMessageDialog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import net.argius.stew.*;

/**
 * The Database Information Tree is a tree pane that provides to
 * display database object information from DatabaseMetaData.
 */
final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSearch {

    enum ActionKey {
        copySimpleName,
        copyFullName,
        generateWherePhrase,
        generateSelectPhrase,
        generateUpdateStatement,
        generateInsertStatement,
        jumpToColumnByName,
        toggleShowColumnNumber
    }

    private static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
    private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class);

    static volatile boolean showColumnNumber;

    private Connector currentConnector;
    private DatabaseMetaData dbmeta;
    private AnyActionListener anyActionListener;

    DatabaseInfoTree(AnyActionListener anyActionListener) {
        this.anyActionListener = anyActionListener;
        setRootVisible(false);
        setShowsRootHandles(false);
        setScrollsOnExpand(true);
        setCellRenderer(new Renderer());
        setModel(new DefaultTreeModel(null));
        // [Events]
        int sckm = Utilities.getMenuShortcutKeyMask();
        AnyAction aa = new AnyAction(this);
        aa.bindKeyStroke(false, copy, KeyStroke.getKeyStroke(VK_C, sckm));
        aa.bindSelf(copySimpleName, getKeyStroke(VK_C, sckm | ALT_DOWN_MASK));
        aa.bindSelf(copyFullName, getKeyStroke(VK_C, sckm | SHIFT_DOWN_MASK));
    }

    @Override
    protected void processMouseEvent(MouseEvent e) {
        super.processMouseEvent(e);
        if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() % 2 == 0) {
            anyActionPerformed(new AnyActionEvent(this, jumpToColumnByName));
        }
    }

    @Override
    public void anyActionPerformed(AnyActionEvent ev) {
        log.atEnter("anyActionPerformed", ev);
        if (ev.isAnyOf(copy)) {
            final String cmd = ev.getActionCommand();
            Action action = getActionMap().get(cmd);
            if (action != null) {
                action.actionPerformed(new ActionEvent(this, 1001, cmd));
            }
        } else if (ev.isAnyOf(copySimpleName)) {
            copySimpleName();
        } else if (ev.isAnyOf(copyFullName)) {
            copyFullName();
        } else if (ev.isAnyOf(refresh)) {
            for (TreePath path : getSelectionPaths()) {
                refresh((InfoNode)path.getLastPathComponent());
            }
        } else if (ev.isAnyOf(generateWherePhrase)) {
            List<ColumnNode> columnNodes = new ArrayList<ColumnNode>();
            for (TreeNode node : getSelectionNodes()) {
                if (node instanceof ColumnNode) {
                    columnNodes.add((ColumnNode)node);
                }
            }
            final String phrase = generateEquivalentJoinClause(columnNodes);
            if (phrase.length() > 0) {
                insertTextIntoTextArea(addCommas(phrase));
            }
        } else if (ev.isAnyOf(generateSelectPhrase)) {
            final String phrase = generateSelectPhrase(getSelectionNodes());
            if (phrase.length() > 0) {
{'fraction_non_alphanumeric': 0.09959325973271353, 'fraction_numerical': 0.0024404416037187683, 'mean_word_length': 2.9225159525979945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390431', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2370, 'n_words': 491}