19 package org.sleuthkit.autopsy.keywordsearch;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.JCheckBox;
31 import javax.swing.JTable;
32 import javax.swing.ListSelectionModel;
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
35 import javax.swing.table.AbstractTableModel;
36 import javax.swing.table.TableCellRenderer;
37 import javax.swing.table.TableColumn;
38 import org.openide.util.NbBundle;
39 import org.openide.util.actions.SystemAction;
47 class DropdownListSearchPanel
extends KeywordSearchPanel {
49 private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
50 private static DropdownListSearchPanel instance;
51 private XmlKeywordSearchList loader;
52 private final KeywordListsTableModel listsTableModel;
53 private final KeywordsTableModel keywordsTableModel;
54 private ActionListener searchAddListener;
55 private boolean ingestRunning;
60 private DropdownListSearchPanel() {
61 listsTableModel =
new KeywordListsTableModel();
62 keywordsTableModel =
new KeywordsTableModel();
64 customizeComponents();
67 static synchronized DropdownListSearchPanel getDefault() {
68 if (instance == null) {
69 instance =
new DropdownListSearchPanel();
74 private void customizeComponents() {
75 listsTable.setTableHeader(null);
76 listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
78 final int leftWidth = leftPane.getPreferredSize().width;
80 for (
int i = 0; i < listsTable.getColumnCount(); i++) {
81 column = listsTable.getColumnModel().getColumn(i);
83 column.setPreferredWidth(((
int) (leftWidth * 0.10)));
84 column.setCellRenderer(
new LeftCheckBoxRenderer());
86 column.setPreferredWidth(((
int) (leftWidth * 0.89)));
89 final int rightWidth = rightPane.getPreferredSize().width;
90 for (
int i = 0; i < keywordsTable.getColumnCount(); i++) {
91 column = keywordsTable.getColumnModel().getColumn(i);
93 column.setPreferredWidth(((
int) (rightWidth * 0.78)));
95 column.setPreferredWidth(((
int) (rightWidth * 0.20)));
96 column.setCellRenderer(
new RightCheckBoxRenderer());
100 loader = XmlKeywordSearchList.getCurrent();
101 listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
103 public void valueChanged(ListSelectionEvent e) {
104 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
105 if (!listSelectionModel.isSelectionEmpty()) {
106 int index = listSelectionModel.getMinSelectionIndex();
107 KeywordList list = listsTableModel.getListAt(index);
108 keywordsTableModel.resync(list);
110 keywordsTableModel.deleteAll();
115 ingestRunning = IngestManager.getInstance().isIngestRunning();
118 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
120 public void propertyChange(PropertyChangeEvent evt) {
121 Object source = evt.getSource();
122 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
123 EventQueue.invokeLater(
new Runnable() {
126 ingestRunning = IngestManager.getInstance().isIngestRunning();
134 searchAddListener =
new ActionListener() {
136 public void actionPerformed(ActionEvent e) {
138 SearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
139 logger.log(Level.INFO,
"Submitted enqueued lists to ingest");
146 searchAddButton.addActionListener(searchAddListener);
149 private void updateComponents() {
150 ingestRunning = IngestManager.getInstance().isIngestRunning();
152 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
153 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
156 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
157 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
159 listsTableModel.resync();
160 updateIngestIndexLabel();
163 private void updateIngestIndexLabel() {
165 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
167 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
172 protected void postFilesIndexedChange() {
173 updateIngestIndexLabel();
180 listsTableModel.resync();
188 @SuppressWarnings(
"unchecked")
190 private
void initComponents() {
192 jSplitPane1 =
new javax.swing.JSplitPane();
193 leftPane =
new javax.swing.JScrollPane();
194 listsTable =
new javax.swing.JTable();
195 rightPane =
new javax.swing.JScrollPane();
196 keywordsTable =
new javax.swing.JTable();
197 manageListsButton =
new javax.swing.JButton();
198 searchAddButton =
new javax.swing.JButton();
199 ingestIndexLabel =
new javax.swing.JLabel();
201 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
203 jSplitPane1.setFont(leftPane.getFont());
205 leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
206 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
208 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
209 listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
210 listsTable.setModel(listsTableModel);
211 listsTable.setShowHorizontalLines(
false);
212 listsTable.setShowVerticalLines(
false);
213 listsTable.getTableHeader().setReorderingAllowed(
false);
214 leftPane.setViewportView(listsTable);
216 jSplitPane1.setLeftComponent(leftPane);
218 rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
220 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
221 keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
222 keywordsTable.setModel(keywordsTableModel);
223 keywordsTable.setShowHorizontalLines(
false);
224 keywordsTable.setShowVerticalLines(
false);
225 rightPane.setViewportView(keywordsTable);
227 jSplitPane1.setRightComponent(rightPane);
229 manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
230 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
231 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
232 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 manageListsButtonActionPerformed(evt);
238 searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
239 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
240 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
241 public void actionPerformed(java.awt.event.ActionEvent evt) {
242 searchAddButtonActionPerformed(evt);
246 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
247 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
249 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
250 this.setLayout(layout);
251 layout.setHorizontalGroup(
252 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
254 .addGroup(layout.createSequentialGroup()
256 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
258 .addComponent(searchAddButton)
259 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 220, Short.MAX_VALUE)
260 .addComponent(manageListsButton))
261 .addGroup(layout.createSequentialGroup()
262 .addComponent(ingestIndexLabel)
263 .addGap(0, 317, Short.MAX_VALUE)))
266 layout.setVerticalGroup(
267 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addGroup(layout.createSequentialGroup()
269 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
270 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
271 .addComponent(ingestIndexLabel)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
273 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
274 .addComponent(manageListsButton)
275 .addComponent(searchAddButton))
280 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
281 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
284 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
289 private javax.swing.JLabel ingestIndexLabel;
290 private javax.swing.JSplitPane jSplitPane1;
291 private javax.swing.JTable keywordsTable;
292 private javax.swing.JScrollPane leftPane;
293 private javax.swing.JTable listsTable;
294 private javax.swing.JButton manageListsButton;
295 private javax.swing.JScrollPane rightPane;
296 private javax.swing.JButton searchAddButton;
299 private void searchAction(ActionEvent e) {
300 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
310 List<KeywordList> getKeywordLists() {
311 return listsTableModel.getSelectedListsL();
314 void addSearchButtonActionListener(ActionListener al) {
315 searchAddButton.addActionListener(al);
321 private XmlKeywordSearchList
listsHandle = XmlKeywordSearchList.getCurrent();
322 private List<ListTableEntry>
listData =
new ArrayList<>();
331 return listData.size();
339 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
342 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
355 Iterator<ListTableEntry> it = listData.iterator();
356 for (
int i = 0; i <= rowIndex; ++i) {
360 switch (columnIndex) {
362 ret = (Object) entry.selected;
365 ret = (Object) entry.name;
376 return (columnIndex == 0 && !ingestRunning);
380 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
381 if (columnIndex == 0) {
383 Iterator<ListTableEntry> it = listData.iterator();
384 for (
int i = 0; i <= rowIndex; i++) {
388 entry.selected = (Boolean) aValue;
402 List<String> getAllLists() {
403 List<String> ret =
new ArrayList<>();
404 for (ListTableEntry e : listData) {
410 KeywordList getListAt(
int rowIndex) {
411 return listsHandle.getList((String)
getValueAt(rowIndex, 1));
414 List<String> getSelectedLists() {
415 List<String> ret =
new ArrayList<>();
416 for (ListTableEntry e : listData) {
424 List<KeywordList> getSelectedListsL() {
425 List<KeywordList> ret =
new ArrayList<>();
426 for (String s : getSelectedLists()) {
427 ret.add(listsHandle.getList(s));
432 boolean listExists(String list) {
433 List<String> all = getAllLists();
434 return all.contains(list);
441 fireTableDataChanged();
447 if (!listExists(list.getName())) {
460 this.name = list.getName();
462 this.selected = list.getUseForIngest();
464 this.selected =
false;
470 return this.name.compareTo(e.name);
477 List<KeywordTableEntry> listData =
new ArrayList<>();
481 return listData.size();
494 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
497 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.regExColLbl");
510 Iterator<KeywordTableEntry> it = listData.iterator();
511 for (
int i = 0; i <= rowIndex; ++i) {
515 switch (columnIndex) {
517 ret = (Object) entry.name;
520 ret = (Object) entry.regex;
535 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
545 for (Keyword k : list.getKeywords()) {
546 listData.add(
new KeywordTableEntry(k));
548 fireTableDataChanged();
553 fireTableDataChanged();
563 this.name = keyword.getQuery();
564 this.regex = !keyword.isLiteral();
569 return this.name.compareTo(e.name);
578 JTable table, Object value,
579 boolean isSelected,
boolean hasFocus,
580 int row,
int column) {
582 this.setHorizontalAlignment(JCheckBox.CENTER);
583 this.setVerticalAlignment(JCheckBox.CENTER);
585 setEnabled(!ingestRunning);
587 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
588 setSelected(selected);
591 setBackground(listsTable.getSelectionBackground());
593 setBackground(listsTable.getBackground());
604 JTable table, Object value,
605 boolean isSelected,
boolean hasFocus,
606 int row,
int column) {
608 this.setHorizontalAlignment(JCheckBox.CENTER);
609 this.setVerticalAlignment(JCheckBox.CENTER);
611 Boolean selected = (Boolean) table.getModel().getValueAt(row, 1);
612 setSelected(selected);
614 setBackground(keywordsTable.getSelectionBackground());
616 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