20 package org.sleuthkit.autopsy.keywordsearch;
 
   23 import java.awt.event.ActionEvent;
 
   24 import java.awt.event.ActionListener;
 
   25 import java.beans.PropertyChangeEvent;
 
   26 import java.beans.PropertyChangeListener;
 
   27 import java.util.ArrayList;
 
   28 import java.util.Iterator;
 
   29 import java.util.List;
 
   30 import java.util.logging.Level;
 
   31 import javax.swing.JCheckBox;
 
   32 import javax.swing.JTable;
 
   33 import javax.swing.ListSelectionModel;
 
   34 import javax.swing.event.ListSelectionEvent;
 
   35 import javax.swing.event.ListSelectionListener;
 
   36 import javax.swing.table.AbstractTableModel;
 
   37 import javax.swing.table.TableCellRenderer;
 
   38 import javax.swing.table.TableColumn;
 
   39 import org.openide.util.NbBundle;
 
   40 import org.openide.util.actions.SystemAction;
 
   48 class DropdownListSearchPanel 
extends KeywordSearchPanel {
 
   50     private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
 
   51     private static DropdownListSearchPanel instance;
 
   52     private XmlKeywordSearchList loader;
 
   53     private KeywordListsTableModel listsTableModel;
 
   54     private KeywordsTableModel keywordsTableModel;
 
   55     private ActionListener searchAddListener;
 
   56     private boolean ingestRunning;
 
   61     private DropdownListSearchPanel() {
 
   62         listsTableModel = 
new KeywordListsTableModel();
 
   63         keywordsTableModel = 
new KeywordsTableModel();
 
   65         customizeComponents();
 
   68     static synchronized DropdownListSearchPanel getDefault() {
 
   69         if (instance == null) {
 
   70             instance = 
new DropdownListSearchPanel();
 
   75     private void customizeComponents() {
 
   76         listsTable.setTableHeader(null);
 
   77         listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
   79         final int leftWidth = leftPane.getPreferredSize().width;
 
   81         for (
int i = 0; i < listsTable.getColumnCount(); i++) {
 
   82             column = listsTable.getColumnModel().getColumn(i);
 
   84                 column.setPreferredWidth(((
int) (leftWidth * 0.10)));
 
   85                 column.setCellRenderer(
new LeftCheckBoxRenderer());
 
   87                 column.setPreferredWidth(((
int) (leftWidth * 0.89)));
 
   90         final int rightWidth = rightPane.getPreferredSize().width;
 
   91         for (
int i = 0; i < keywordsTable.getColumnCount(); i++) {
 
   92             column = keywordsTable.getColumnModel().getColumn(i);
 
   94                 column.setPreferredWidth(((
int) (rightWidth * 0.78)));
 
   96                 column.setPreferredWidth(((
int) (rightWidth * 0.20)));
 
   97                 column.setCellRenderer(
new RightCheckBoxRenderer());
 
  101         loader = XmlKeywordSearchList.getCurrent();
 
  102         listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
 
  104             public void valueChanged(ListSelectionEvent e) {
 
  105                 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
 
  106                 if (!listSelectionModel.isSelectionEmpty()) {
 
  107                     int index = listSelectionModel.getMinSelectionIndex();
 
  108                     KeywordList list = listsTableModel.getListAt(index);
 
  109                     keywordsTableModel.resync(list);
 
  111                     keywordsTableModel.deleteAll();
 
  116         ingestRunning = IngestManager.getInstance().isIngestRunning();
 
  119         IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
 
  121             public void propertyChange(PropertyChangeEvent evt) {
 
  122                 String changed = evt.getPropertyName();
 
  123                 if (changed.equals(IngestJobEvent.STARTED.toString())
 
  124                         || changed.equals(IngestJobEvent.COMPLETED.toString())
 
  125                         || changed.equals(IngestJobEvent.CANCELLED.toString())) {
 
  126                     EventQueue.invokeLater(
new Runnable() {
 
  129                             ingestRunning = IngestManager.getInstance().isIngestRunning();
 
  137         searchAddListener = 
new ActionListener() {
 
  139             public void actionPerformed(ActionEvent e) {
 
  141                     SearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
 
  142                     logger.log(Level.INFO, 
"Submitted enqueued lists to ingest"); 
 
  149         searchAddButton.addActionListener(searchAddListener);
 
  152     private void updateComponents() {
 
  153         ingestRunning = IngestManager.getInstance().isIngestRunning();
 
  155             searchAddButton.setText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
 
  156             searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg" ));
 
  159             searchAddButton.setText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
 
  160             searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
 
  162         listsTableModel.resync();
 
  163         updateIngestIndexLabel();
 
  166     private void updateIngestIndexLabel() {
 
  168             ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
 
  171             ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
 
  176     protected void postFilesIndexedChange() {
 
  177          updateIngestIndexLabel();
 
  184         listsTableModel.resync();
 
  192     @SuppressWarnings(
"unchecked")
 
  194     private 
void initComponents() {
 
  196         jSplitPane1 = 
new javax.swing.JSplitPane();
 
  197         leftPane = 
new javax.swing.JScrollPane();
 
  198         listsTable = 
new javax.swing.JTable();
 
  199         rightPane = 
new javax.swing.JScrollPane();
 
  200         keywordsTable = 
new javax.swing.JTable();
 
  201         manageListsButton = 
new javax.swing.JButton();
 
  202         searchAddButton = 
new javax.swing.JButton();
 
  203         ingestIndexLabel = 
new javax.swing.JLabel();
 
  205         leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
 
  207         listsTable.setBackground(
new java.awt.Color(240, 240, 240));
 
  208         listsTable.setModel(listsTableModel);
 
  209         listsTable.setShowHorizontalLines(
false);
 
  210         listsTable.setShowVerticalLines(
false);
 
  211         listsTable.getTableHeader().setReorderingAllowed(
false);
 
  212         leftPane.setViewportView(listsTable);
 
  214         jSplitPane1.setLeftComponent(leftPane);
 
  216         keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
 
  217         keywordsTable.setModel(keywordsTableModel);
 
  218         keywordsTable.setShowHorizontalLines(
false);
 
  219         keywordsTable.setShowVerticalLines(
false);
 
  220         rightPane.setViewportView(keywordsTable);
 
  222         jSplitPane1.setRightComponent(rightPane);
 
  224         manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, 
"KeywordSearchListsViewerPanel.manageListsButton.text")); 
 
  225         manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, 
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText")); 
 
  226         manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
 
  227             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  228                 manageListsButtonActionPerformed(evt);
 
  232         searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, 
"KeywordSearchListsViewerPanel.searchAddButton.text")); 
 
  233         searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
 
  234             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  235                 searchAddButtonActionPerformed(evt);
 
  239         ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(Font.PLAIN, 10));
 
  240         ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, 
"KeywordSearchListsViewerPanel.ingestIndexLabel.text")); 
 
  242         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  243         this.setLayout(layout);
 
  244         layout.setHorizontalGroup(
 
  245             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  246             .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
 
  247             .addGroup(layout.createSequentialGroup()
 
  249                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  250                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  251                         .addComponent(searchAddButton)
 
  252                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 220, Short.MAX_VALUE)
 
  253                         .addComponent(manageListsButton))
 
  254                     .addGroup(layout.createSequentialGroup()
 
  255                         .addComponent(ingestIndexLabel)
 
  256                         .addGap(0, 317, Short.MAX_VALUE)))
 
  259         layout.setVerticalGroup(
 
  260             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  261             .addGroup(layout.createSequentialGroup()
 
  262                 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  263                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
 
  264                 .addComponent(ingestIndexLabel)
 
  265                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  266                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  267                     .addComponent(manageListsButton)
 
  268                     .addComponent(searchAddButton))
 
  273     private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  274         SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
 
  277     private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  282     private javax.swing.JLabel ingestIndexLabel;
 
  283     private javax.swing.JSplitPane jSplitPane1;
 
  284     private javax.swing.JTable keywordsTable;
 
  285     private javax.swing.JScrollPane leftPane;
 
  286     private javax.swing.JTable listsTable;
 
  287     private javax.swing.JButton manageListsButton;
 
  288     private javax.swing.JScrollPane rightPane;
 
  289     private javax.swing.JButton searchAddButton;
 
  292     private void searchAction(ActionEvent e) {
 
  293         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  303     List<KeywordList> getKeywordLists() {
 
  304         return listsTableModel.getSelectedListsL();
 
  308     void addSearchButtonActionListener(ActionListener al) {
 
  309         searchAddButton.addActionListener(al);
 
  315         private XmlKeywordSearchList 
listsHandle = XmlKeywordSearchList.getCurrent();
 
  316         private List<ListTableEntry> 
listData = 
new ArrayList<>();
 
  325             return listData.size();
 
  333                     ret = NbBundle.getMessage(this.getClass(), 
"KeywordSearch.selectedColLbl");
 
  336                     ret = NbBundle.getMessage(this.getClass(), 
"KeywordSearch.nameColLbl");
 
  349             Iterator<ListTableEntry> it = listData.iterator();
 
  350             for (
int i = 0; i <= rowIndex; ++i) {
 
  354                 switch (columnIndex) {
 
  356                         ret = (Object) entry.selected;
 
  359                         ret = (Object) entry.name;
 
  370             return (columnIndex == 0 && !ingestRunning);
 
  374         public void setValueAt(Object aValue, 
int rowIndex, 
int columnIndex) {
 
  375             if (columnIndex == 0) {
 
  377                 Iterator<ListTableEntry> it = listData.iterator();
 
  378                 for (
int i = 0; i <= rowIndex; i++) {
 
  382                     entry.selected = (Boolean) aValue;
 
  396         List<String> getAllLists() {
 
  397             List<String> ret = 
new ArrayList<>();
 
  398             for (ListTableEntry e : listData) {
 
  404         KeywordList getListAt(
int rowIndex) {
 
  405             return listsHandle.getList((String) 
getValueAt(rowIndex, 1));
 
  408         List<String> getSelectedLists() {
 
  409             List<String> ret = 
new ArrayList<>();
 
  410             for (ListTableEntry e : listData) {
 
  418         List<KeywordList> getSelectedListsL() {
 
  419             List<KeywordList> ret = 
new ArrayList<>();
 
  420             for (String s : getSelectedLists()) {
 
  421                 ret.add(listsHandle.getList(s));
 
  426         boolean listExists(String list) {
 
  427             List<String> all = getAllLists();
 
  428             return all.contains(list);
 
  435             fireTableDataChanged();
 
  441                 if (!listExists(list.getName())) {
 
  454                 this.name = list.getName();
 
  456                     this.selected = list.getUseForIngest();
 
  458                     this.selected = 
false;
 
  464                 return this.name.compareTo(e.name);
 
  471         List<KeywordTableEntry> listData = 
new ArrayList<>();
 
  475             return listData.size();
 
  488                     ret = NbBundle.getMessage(this.getClass(), 
"KeywordSearch.nameColLbl");
 
  491                     ret = NbBundle.getMessage(this.getClass(), 
"KeywordSearch.regExColLbl");
 
  504             Iterator<KeywordTableEntry> it = listData.iterator();
 
  505             for (
int i = 0; i <= rowIndex; ++i) {
 
  509                 switch (columnIndex) {
 
  511                         ret = (Object) entry.name;
 
  514                         ret = (Object) entry.regex;
 
  529         public void setValueAt(Object aValue, 
int rowIndex, 
int columnIndex) {
 
  539             for (Keyword k : list.getKeywords()) {
 
  540                 listData.add(
new KeywordTableEntry(k));
 
  542             fireTableDataChanged();
 
  547             fireTableDataChanged();
 
  557                 this.name = keyword.getQuery();
 
  558                 this.regex = !keyword.isLiteral();
 
  563                 return this.name.compareTo(e.name);
 
  572                 JTable table, Object value,
 
  573                 boolean isSelected, 
boolean hasFocus,
 
  574                 int row, 
int column) {
 
  576             this.setHorizontalAlignment(JCheckBox.CENTER);
 
  577             this.setVerticalAlignment(JCheckBox.CENTER);
 
  579             setEnabled(!ingestRunning);
 
  581             boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
 
  582             setSelected(selected);
 
  585                 setBackground(listsTable.getSelectionBackground());
 
  587                 setBackground(listsTable.getBackground());
 
  598                 JTable table, Object value,
 
  599                 boolean isSelected, 
boolean hasFocus,
 
  600                 int row, 
int column) {
 
  602             this.setHorizontalAlignment(JCheckBox.CENTER);
 
  603             this.setVerticalAlignment(JCheckBox.CENTER);
 
  605             Boolean selected = (Boolean) table.getModel().getValueAt(row, 1);
 
  606             setSelected(selected);
 
  608                 setBackground(keywordsTable.getSelectionBackground());
 
  610                 setBackground(keywordsTable.getBackground());
 
XmlKeywordSearchList listsHandle
 
void setValueAt(Object aValue, int rowIndex, int columnIndex)
 
String getColumnName(int column)
 
int compareTo(ListTableEntry e)
 
boolean isCellEditable(int rowIndex, int columnIndex)
 
Class<?> getColumnClass(int c)
 
void addLists(List< KeywordList > lists)
 
boolean isCellEditable(int rowIndex, int columnIndex)
 
Class<?> getColumnClass(int c)
 
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
 
int compareTo(KeywordTableEntry e)
 
String getColumnName(int column)
 
Object getValueAt(int rowIndex, int columnIndex)
 
void setValueAt(Object aValue, int rowIndex, int columnIndex)
 
Object getValueAt(int rowIndex, int columnIndex)
 
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
 
List< ListTableEntry > listData