<commit_before>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011-2013 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.corecomponents;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.datatransfer.StringSelection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.swing.JMenuItem;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.apache.commons.lang.StringUtils;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskException;
import org.netbeans.swing.etable.ETable;

/**
 * Instances of this class display the BlackboardArtifacts associated with the
 * Content represented by a Node. Each BlackboardArtifact is rendered as an HTML
 * representation of its BlackboardAttributes.
 */
@ServiceProvider(service = DataContentViewer.class, position = 3)
public class DataContentViewerArtifact extends javax.swing.JPanel implements DataContentViewer {

    @NbBundle.Messages({
        "DataContentViewerArtifact.attrsTableHeader.type=Type",
        "DataContentViewerArtifact.attrsTableHeader.value=Value",
        "DataContentViewerArtifact.attrsTableHeader.sources=Source(s)",
        "DataContentViewerArtifact.failedToGetSourcePath.message=Failed to get source file path from case database",
        "DataContentViewerArtifact.failedToGetAttributes.message=Failed to get some or all attributes from case database"
    })
    private final static Logger logger = Logger.getLogger(DataContentViewerArtifact.class.getName());
    private final static String WAIT_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.waitText");
    private final static String ERROR_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.errorText");
    private Node currentNode; // @@@ Remove this when the redundant setNode() calls problem is fixed. 
    private int currentPage = 1;
    private final Object lock = new Object();
    private List<ResultsTableArtifact> artifactTableContents; // Accessed by multiple threads, use getArtifactContents() and setArtifactContents()
    SwingWorker<ViewUpdate, Void> currentTask; // Accessed by multiple threads, use startNewTask()
    private static final String[] COLUMN_HEADERS = {
        Bundle.DataContentViewerArtifact_attrsTableHeader_type(),
        Bundle.DataContentViewerArtifact_attrsTableHeader_value(),
        Bundle.DataContentViewerArtifact_attrsTableHeader_sources()};
    private static final int[] COLUMN_WIDTHS = {100, 800, 100};

    public DataContentViewerArtifact() {
        initResultsTable();
        initComponents();
        resultsTableScrollPane.setViewportView(resultsTable);
        customizeComponents();
        resetComponents();
    }

    private void initResultsTable() {
        resultsTable = new ETable();
        resultsTable.setModel(new javax.swing.table.DefaultTableModel() {
            private static final long serialVersionUID = 1L;

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        resultsTable.setCellSelectionEnabled(true);
        resultsTable.getTableHeader().setReorderingAllowed(false);
        resultsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        updateColumnSizes();
    }

    private void updateColumnSizes() {
        resultsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN);
        Enumeration<TableColumn> columns = resultsTable.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn col = columns.nextElement();
            if (col.getHeaderValue().equals(COLUMN_HEADERS[0])) {
                col.setPreferredWidth(COLUMN_WIDTHS[0]);<commit_msg>2745 disable column hiding leaving sorting enabled for content viewer ETable<commit_after>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011-2013 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.corecomponents;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.datatransfer.StringSelection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.swing.JMenuItem;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.apache.commons.lang.StringUtils;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskException;
import org.netbeans.swing.etable.ETable;

/**
 * Instances of this class display the BlackboardArtifacts associated with the
 * Content represented by a Node. Each BlackboardArtifact is rendered as an HTML
 * representation of its BlackboardAttributes.
 */
@ServiceProvider(service = DataContentViewer.class, position = 3)
public class DataContentViewerArtifact extends javax.swing.JPanel implements DataContentViewer {

    @NbBundle.Messages({
        "DataContentViewerArtifact.attrsTableHeader.type=Type",
        "DataContentViewerArtifact.attrsTableHeader.value=Value",
        "DataContentViewerArtifact.attrsTableHeader.sources=Source(s)",
        "DataContentViewerArtifact.failedToGetSourcePath.message=Failed to get source file path from case database",
        "DataContentViewerArtifact.failedToGetAttributes.message=Failed to get some or all attributes from case database"
    })
    private final static Logger logger = Logger.getLogger(DataContentViewerArtifact.class.getName());
    private final static String WAIT_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.waitText");
    private final static String ERROR_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.errorText");
    private Node currentNode; // @@@ Remove this when the redundant setNode() calls problem is fixed. 
    private int currentPage = 1;
    private final Object lock = new Object();
    private List<ResultsTableArtifact> artifactTableContents; // Accessed by multiple threads, use getArtifactContents() and setArtifactContents()
    SwingWorker<ViewUpdate, Void> currentTask; // Accessed by multiple threads, use startNewTask()
    private static final String[] COLUMN_HEADERS = {
        Bundle.DataContentViewerArtifact_attrsTableHeader_type(),
        Bundle.DataContentViewerArtifact_attrsTableHeader_value(),
        Bundle.DataContentViewerArtifact_attrsTableHeader_sources()};
    private static final int[] COLUMN_WIDTHS = {100, 800, 100};

    public DataContentViewerArtifact() {
        initResultsTable();
        initComponents();
        resultsTableScrollPane.setViewportView(resultsTable);
        customizeComponents();
        resetComponents();
    }

    private void initResultsTable() {
        resultsTable = new ETable();
        resultsTable.setModel(new javax.swing.table.DefaultTableModel() {
            private static final long serialVersionUID = 1L;

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        resultsTable.setCellSelectionEnabled(true);
        resultsTable.getTableHeader().setReorderingAllowed(false);
        resultsTable.setColumnHidingAllowed(false);
        resultsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        updateColumnSizes();
    }

    private void updateColumnSizes() {
        resultsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN);
        Enumeration<TableColumn> columns = resultsTable.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn col = columns.nextElement();
            if (col.getHeaderValue().equals(COLUMN_HEADERS[0])) {
                col.setPreferredWidth(COLUMN_WIDTHS[0]);
{'fraction_non_alphanumeric': 0.0844381758345087, 'fraction_numerical': 0.005265632346027269, 'mean_word_length': 4.56567242281528, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6002370', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2874, 'n_words': 698}