<commit_before>package edu.wustl.cab2b.client.ui.viewresults;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.JXTitledPanel;
import org.jdesktop.swingx.painter.gradient.BasicGradientPainter;

import edu.common.dynamicextensions.domain.Association;
import edu.common.dynamicextensions.domaininterface.AssociationInterface;
import edu.common.dynamicextensions.domaininterface.AttributeInterface;
import edu.common.dynamicextensions.domaininterface.EntityInterface;
import edu.wustl.cab2b.client.ui.MainSearchPanel;
import edu.wustl.cab2b.client.ui.RiverLayout;
import edu.wustl.cab2b.client.ui.controls.Cab2bButton;
import edu.wustl.cab2b.client.ui.controls.Cab2bHyperlink;
import edu.wustl.cab2b.client.ui.controls.Cab2bLabel;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;
import edu.wustl.cab2b.client.ui.controls.Cab2bTitledPanel;
import edu.wustl.cab2b.client.ui.controls.CustomizableBorder;
import edu.wustl.cab2b.client.ui.util.CommonUtils;
import edu.wustl.cab2b.common.datalist.DataRow;
import edu.wustl.cab2b.common.ejb.path.PathFinderBusinessInterface;
import edu.wustl.cab2b.common.ejb.path.PathFinderHomeInterface;
import edu.wustl.common.querysuite.factory.QueryObjectFactory;
import edu.wustl.common.querysuite.metadata.associations.IAssociation;
import edu.wustl.common.querysuite.metadata.associations.IInterModelAssociation;
import edu.wustl.common.querysuite.metadata.associations.IIntraModelAssociation;
import edu.wustl.common.util.logger.Logger;

/**
 * A Panel to show any entity's details.
 * @author chetan_bh
 */
public class ResultObjectDetailsPanel extends Cab2bPanel {
    Object[] objectDetails;

    List<AttributeInterface> attributes; // List<IAttribute> attributes;

    JXTable objDetailsTable;

    Vector<Vector<Object>> tableData;

    Vector<String> tableHeader;

    JXTitledPanel relatedDataTitledPanel;

    JXPanel relatedDataPanel;

    JButton addToDataListButton;

    ActionListener associatedDataActionListener;

    ActionListener breadCrumbActionListener;

    JXPanel breadCrumbPanel;

    EntityInterface parentEntityInterface = null;

    ViewSearchResultsPanel viewPanel;

    Object id = null;

    DataRow dataRow;

    private Cab2bButton m_applyAllButton;

    private Cab2bPanel m_sidePanel;
    
    Collection<AssociationInterface> incomingIntraModelAssociationCollection;
	Collection<IInterModelAssociation> interModelAssociationCollection;
    
    public ResultObjectDetailsPanel(
            DataRow dataRow,
            List<AttributeInterface> attributes,
            ActionListener bcAL,
            ActionListener assoDataAL,
            ViewSearchResultsPanel viewPanel,
            Vector interIntraAssoClass
            ) {
        /* Set the parent entity interface. Note : This can never be null. */
        this.dataRow = dataRow;
        this.parentEntityInterface = dataRow.getEntityInterface();
        this.id = dataRow.getId();
        this.viewPanel = viewPanel;
        this.objectDetails = dataRow.getRow();
        this.attributes = attributes;
        
        this.interModelAssociationCollection = (Collection<IInterModelAssociation>) interIntraAssoClass.get(0);
        this.incomingIntraModelAssociationCollection = (Collection<AssociationInterface>) interIntraAssoClass.get(1); 
        
        breadCrumbActionListener = bcAL;
        associatedDataActionListener = assoDataAL;
        initData();
        initRelatedDataPanel();
        initGUI();
    }

    public void addDataSummaryPanel() {
        m_sidePanel.add(ViewSearchResultsSimplePanel.myDataListTitledPanel,
                        BorderLayout.CENTER);
    }

    private void initData() {
        tableData = new Vector<Vector<Object>>();
        Vector<Object> row = new Vector<Object>();
        for (int i = 0; i < objectDetails.length; i++) {
            AttributeInterface attribute = attributes.get(i);
            String formattedString = CommonUtils.getFormattedString(attribute.getName());
            row.add(formattedString);
            row.add(objectDetails[i]);
            tableData.add(row);
            row = new Vector<Object>();
        }

        tableHeader = new Vector<String>();
        // TODO remove this hard coding, or externalize this strings.
        tableHeader.add("Attribute");
        tableHeader.add("Value");
    }

    private void initGUI() {
        this.setLayout(new BorderLayout());

        final JXPanel detailsTablePanel = new Cab2bPanel(new RiverLayout());

        objDetailsTable = new JXTable(tableData, tableHeader);
        objDetailsTable.setEditable(false);

        JScrollPane tableSP = new JScrollPane(objDetailsTable);
        // tableSP.setPreferredSize(new Dimension(700,600));

        detailsTablePanel.add("br hfill vfill", tableSP);

        addToDataListButton = new Cab2bButton("Add To Data List");
        addToDataListButton.setPreferredSize(new Dimension(140, 22));
        addToDataListButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Logger.out.info("add to data list action");
                Vector<Object> selectedUserObjects = new Vector<Object>();
                selectedUserObjects.add(dataRow);
                MainSearchPanel.getDataList().addDataRows(selectedUserObjects);

                ViewSearchResultsSimplePanel.updateMyDataListPanel();
                updateUI();
            }
        });

        // Add Apply All button to apply currently added datalist options
        // to the currently selected objects.
        m_applyAllButton = new Cab2bButton("Apply Data List");
        m_applyAllButton.setPreferredSize(new Dimension(130, 22));<commit_msg>*** empty log message ***<commit_after>package edu.wustl.cab2b.client.ui.viewresults;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.JXTitledPanel;
import org.jdesktop.swingx.painter.gradient.BasicGradientPainter;

import edu.common.dynamicextensions.domain.Association;
import edu.common.dynamicextensions.domaininterface.AssociationInterface;
import edu.common.dynamicextensions.domaininterface.AttributeInterface;
import edu.common.dynamicextensions.domaininterface.EntityInterface;
import edu.wustl.cab2b.client.ui.MainSearchPanel;
import edu.wustl.cab2b.client.ui.RiverLayout;
import edu.wustl.cab2b.client.ui.SaveDatalistPanel;
import edu.wustl.cab2b.client.ui.controls.Cab2bButton;
import edu.wustl.cab2b.client.ui.controls.Cab2bHyperlink;
import edu.wustl.cab2b.client.ui.controls.Cab2bLabel;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;
import edu.wustl.cab2b.client.ui.controls.Cab2bTitledPanel;
import edu.wustl.cab2b.client.ui.controls.CustomizableBorder;
import edu.wustl.cab2b.client.ui.util.CommonUtils;
import edu.wustl.cab2b.common.datalist.DataRow;
import edu.wustl.cab2b.common.ejb.path.PathFinderBusinessInterface;
import edu.wustl.cab2b.common.ejb.path.PathFinderHomeInterface;
import edu.wustl.common.querysuite.factory.QueryObjectFactory;
import edu.wustl.common.querysuite.metadata.associations.IAssociation;
import edu.wustl.common.querysuite.metadata.associations.IInterModelAssociation;
import edu.wustl.common.querysuite.metadata.associations.IIntraModelAssociation;
import edu.wustl.common.util.logger.Logger;

/**
 * A Panel to show any entity's details.
 * @author chetan_bh
 */
public class ResultObjectDetailsPanel extends Cab2bPanel {
    Object[] objectDetails;

    List<AttributeInterface> attributes; // List<IAttribute> attributes;

    JXTable objDetailsTable;

    Vector<Vector<Object>> tableData;

    Vector<String> tableHeader;

    JXTitledPanel relatedDataTitledPanel;

    JXPanel relatedDataPanel;

    JButton addToDataListButton;

    ActionListener associatedDataActionListener;

    ActionListener breadCrumbActionListener;

    JXPanel breadCrumbPanel;

    EntityInterface parentEntityInterface = null;

    ViewSearchResultsPanel viewPanel;

    Object id = null;

    DataRow dataRow;

    private Cab2bButton m_applyAllButton;

    private Cab2bPanel m_sidePanel;
    
    Collection<AssociationInterface> incomingIntraModelAssociationCollection;
	Collection<IInterModelAssociation> interModelAssociationCollection;
    
    public ResultObjectDetailsPanel(
            DataRow dataRow,
            List<AttributeInterface> attributes,
            ActionListener bcAL,
            ActionListener assoDataAL,
            ViewSearchResultsPanel viewPanel,
            Vector interIntraAssoClass
            ) {
        /* Set the parent entity interface. Note : This can never be null. */
        this.dataRow = dataRow;
        this.parentEntityInterface = dataRow.getEntityInterface();
        this.id = dataRow.getId();
        this.viewPanel = viewPanel;
        this.objectDetails = dataRow.getRow();
        this.attributes = attributes;
        
        this.interModelAssociationCollection = (Collection<IInterModelAssociation>) interIntraAssoClass.get(0);
        this.incomingIntraModelAssociationCollection = (Collection<AssociationInterface>) interIntraAssoClass.get(1); 
        
        breadCrumbActionListener = bcAL;
        associatedDataActionListener = assoDataAL;
        initData();
        initRelatedDataPanel();
        initGUI();
    }

    public void addDataSummaryPanel() {
        m_sidePanel.add(ViewSearchResultsSimplePanel.myDataListTitledPanel,
                        BorderLayout.CENTER);
    }

    private void initData() {
        tableData = new Vector<Vector<Object>>();
        Vector<Object> row = new Vector<Object>();
        for (int i = 0; i < objectDetails.length; i++) {
            AttributeInterface attribute = attributes.get(i);
            String formattedString = CommonUtils.getFormattedString(attribute.getName());
            row.add(formattedString);
            row.add(objectDetails[i]);
            tableData.add(row);
            row = new Vector<Object>();
        }

        tableHeader = new Vector<String>();
        // TODO remove this hard coding, or externalize this strings.
        tableHeader.add("Attribute");
        tableHeader.add("Value");
    }

    private void initGUI() {
        this.setLayout(new BorderLayout());

        final JXPanel detailsTablePanel = new Cab2bPanel(new RiverLayout());

        objDetailsTable = new JXTable(tableData, tableHeader);
        objDetailsTable.setEditable(false);

        JScrollPane tableSP = new JScrollPane(objDetailsTable);
        // tableSP.setPreferredSize(new Dimension(700,600));

        detailsTablePanel.add("br hfill vfill", tableSP);

        addToDataListButton = new Cab2bButton("Add To Data List");
        addToDataListButton.setPreferredSize(new Dimension(140, 22));
        addToDataListButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Logger.out.info("add to data list action");
                Vector<Object> selectedUserObjects = new Vector<Object>();
                selectedUserObjects.add(dataRow);
                MainSearchPanel.getDataList().addDataRows(selectedUserObjects);

                ViewSearchResultsSimplePanel.updateMyDataListPanel();
                SaveDatalistPanel.isDataListSaved =  false;
                updateUI();
            }
        });

        // Add Apply All button to apply currently added datalist options
        // to the currently selected objects.
        m_applyAllButton = new Cab2bButton("Apply Data List");
        m_applyAllButton.setPreferredSize(new Dimension(130, 22));
{'fraction_non_alphanumeric': 0.09053989488772098, 'fraction_numerical': 0.007087115782767957, 'mean_word_length': 3.542133815551537, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, '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': '834437', 'n_tokens_mistral': 3763, 'n_tokens_neox': 3621, 'n_words': 645}