<commit_before>package nl.mpi.arbil.ui.menu;

import java.util.ArrayList;
import java.util.Hashtable;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import nl.mpi.arbil.data.ArbilComponentBuilder;
import nl.mpi.arbil.data.ArbilField;
import nl.mpi.arbil.data.ArbilDataNode;
import nl.mpi.arbil.data.ArbilTreeHelper;
import nl.mpi.arbil.ui.ArbilSplitPanel;
import nl.mpi.arbil.ui.ArbilTable;
import nl.mpi.arbil.ui.ArbilWindowManager;
import nl.mpi.arbil.ui.GuiHelper;

/**
 * Context menu for table UI components
 *
 * @author <NAME>
 */
public class TableContextMenu extends ArbilContextMenu {

    public TableContextMenu(ArbilTable table) {
	super();
	this.table = table;
	setInvoker(table);

	selectedTreeNodes = table.getSelectedRowsFromTable();
	leadSelectedTreeNode = table.getDataNodeForSelection();
    }

    @Override
    protected void setUpMenu() {
	setUpItems();
	setUpActions();
    }

    private void setUpItems() {
	if (table.getSelectedRow() != -1) {
	    copySelectedRowsMenuItem.setVisible(true);
	    pasteIntoSelectedRowsMenuItem.setVisible(true);
	    openInLongFieldEditorMenuItem.setVisible(true);
	    if (table.arbilTableModel.isHorizontalView()) {
		viewSelectedRowsMenuItem.setVisible(true);
		matchingRowsMenuItem.setVisible(true);
		removeSelectedRowsMenuItem.setVisible(true);
		showChildNodesMenuItem.setVisible(true);
	    }
	    boolean canDeleteSelectedFields = true;
	    ArbilField[] currentSelection = table.getSelectedFields();
	    for (ArbilField currentField : currentSelection) {
		if (!currentField.getParentDataNode().getNodeTemplate().pathIsDeleteableField(currentField.getGenericFullXmlPath())) {
		    canDeleteSelectedFields = false;
		    break;
		}
	    }
	    if (canDeleteSelectedFields && currentSelection.length > 0) {
		String menuText = "Delete " + currentSelection[0].getTranslateFieldName();
		if (currentSelection.length > 1) {
		    menuText = menuText + " X " + currentSelection.length;
		}
		deleteFieldMenuItem.setText(menuText);
		deleteFieldMenuItem.setVisible(true);
	    }

	    // set up the revert field menu
	    for (ArbilField currentField : currentSelection) {
		if (currentField.fieldNeedsSaveToDisk()) {
		    revertFieldMenuItem.setVisible(true);
		    break;
		}
	    }
	}
	if (table.getSelectedRow() != -1 && table.getSelectedColumn() != -1) {
	    // add a divider for the cell functions
	    //cellMenuDivider.setVisible(true);
	    if (table.arbilTableModel.isHorizontalView() && table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
		copyCellToColumnMenuItem.setVisible(true);
		hideSelectedColumnsMenuItem.setVisible(true);
	    }
	    //if (!table.arbilTableModel.isHorizontalView() || table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
	    // show the cell only menu items
	    if (!table.getArbilTableModel().isHorizontalView() || table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
		// show the cell only menu items
		matchingCellsMenuItem.setVisible(true);
	    }
	    jumpToNodeInTreeMenuItem.setVisible(true);
	    clearCellColoursMenuItem.setVisible(true);
	}
	if (table.getParent().getParent().getParent().getParent() instanceof ArbilSplitPanel) {
	    // test the LinorgSplitPanel exists before showing this
	    searchReplaceMenuItem.setVisible(true);
	}
    }

    private void setUpActions() {
	copySelectedRowsMenuItem.setText("Copy");
	copySelectedRowsMenuItem.addActionListener(new java.awt.event.ActionListener() {

	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		try {
		    table.copySelectedTableRowsToClipBoard();
		} catch (Exception ex) {
		    GuiHelper.linorgBugCatcher.logError(ex);
		}
	    }
	});
	addItem(CATEGORY_EDIT, PRIORITY_BOTTOM + 5, copySelectedRowsMenuItem);

	pasteIntoSelectedRowsMenuItem.setText("Paste");
	pasteIntoSelectedRowsMenuItem.addActionListener(new java.awt.event.ActionListener() {

	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		try {
		    table.pasteIntoSelectedTableRowsFromClipBoard();
		} catch (Exception ex) {<commit_msg>Made 'Jump to in tree' table context menu option invisible<commit_after>package nl.mpi.arbil.ui.menu;

import java.util.ArrayList;
import java.util.Hashtable;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import nl.mpi.arbil.data.ArbilComponentBuilder;
import nl.mpi.arbil.data.ArbilField;
import nl.mpi.arbil.data.ArbilDataNode;
import nl.mpi.arbil.data.ArbilTreeHelper;
import nl.mpi.arbil.ui.ArbilSplitPanel;
import nl.mpi.arbil.ui.ArbilTable;
import nl.mpi.arbil.ui.ArbilWindowManager;
import nl.mpi.arbil.ui.GuiHelper;

/**
 * Context menu for table UI components
 *
 * @author <NAME>
 */
public class TableContextMenu extends ArbilContextMenu {

    public TableContextMenu(ArbilTable table) {
	super();
	this.table = table;
	setInvoker(table);

	selectedTreeNodes = table.getSelectedRowsFromTable();
	leadSelectedTreeNode = table.getDataNodeForSelection();
    }

    @Override
    protected void setUpMenu() {
	setUpItems();
	setUpActions();
    }

    private void setUpItems() {
	if (table.getSelectedRow() != -1) {
	    copySelectedRowsMenuItem.setVisible(true);
	    pasteIntoSelectedRowsMenuItem.setVisible(true);
	    openInLongFieldEditorMenuItem.setVisible(true);
	    if (table.arbilTableModel.isHorizontalView()) {
		viewSelectedRowsMenuItem.setVisible(true);
		matchingRowsMenuItem.setVisible(true);
		removeSelectedRowsMenuItem.setVisible(true);
		showChildNodesMenuItem.setVisible(true);
	    }
	    boolean canDeleteSelectedFields = true;
	    ArbilField[] currentSelection = table.getSelectedFields();
	    for (ArbilField currentField : currentSelection) {
		if (!currentField.getParentDataNode().getNodeTemplate().pathIsDeleteableField(currentField.getGenericFullXmlPath())) {
		    canDeleteSelectedFields = false;
		    break;
		}
	    }
	    if (canDeleteSelectedFields && currentSelection.length > 0) {
		String menuText = "Delete " + currentSelection[0].getTranslateFieldName();
		if (currentSelection.length > 1) {
		    menuText = menuText + " X " + currentSelection.length;
		}
		deleteFieldMenuItem.setText(menuText);
		deleteFieldMenuItem.setVisible(true);
	    }

	    // set up the revert field menu
	    for (ArbilField currentField : currentSelection) {
		if (currentField.fieldNeedsSaveToDisk()) {
		    revertFieldMenuItem.setVisible(true);
		    break;
		}
	    }
	}
	if (table.getSelectedRow() != -1 && table.getSelectedColumn() != -1) {
	    // add a divider for the cell functions
	    //cellMenuDivider.setVisible(true);
	    if (table.arbilTableModel.isHorizontalView() && table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
		copyCellToColumnMenuItem.setVisible(true);
		hideSelectedColumnsMenuItem.setVisible(true);
	    }
	    //if (!table.arbilTableModel.isHorizontalView() || table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
	    // show the cell only menu items
	    if (!table.getArbilTableModel().isHorizontalView() || table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
		// show the cell only menu items
		matchingCellsMenuItem.setVisible(true);
	    }
	    jumpToNodeInTreeMenuItem.setVisible(false); // TODO: if functional, set to true here!
	    clearCellColoursMenuItem.setVisible(true);
	}
	if (table.getParent().getParent().getParent().getParent() instanceof ArbilSplitPanel) {
	    // test the LinorgSplitPanel exists before showing this
	    searchReplaceMenuItem.setVisible(true);
	}
    }

    private void setUpActions() {
	copySelectedRowsMenuItem.setText("Copy");
	copySelectedRowsMenuItem.addActionListener(new java.awt.event.ActionListener() {

	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		try {
		    table.copySelectedTableRowsToClipBoard();
		} catch (Exception ex) {
		    GuiHelper.linorgBugCatcher.logError(ex);
		}
	    }
	});
	addItem(CATEGORY_EDIT, PRIORITY_BOTTOM + 5, copySelectedRowsMenuItem);

	pasteIntoSelectedRowsMenuItem.setText("Paste");
	pasteIntoSelectedRowsMenuItem.addActionListener(new java.awt.event.ActionListener() {

	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		try {
		    table.pasteIntoSelectedTableRowsFromClipBoard();
		} catch (Exception ex) {
{'fraction_non_alphanumeric': 0.10973597359735973, 'fraction_numerical': 0.0016501650165016502, 'mean_word_length': 4.717654986522911, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '827252', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2519, 'n_words': 426}