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;
42 import javax.swing.ImageIcon;
43 import static javax.swing.SwingConstants.CENTER;
44 import javax.swing.table.DefaultTableCellRenderer;
50 class DropdownListSearchPanel
extends KeywordSearchPanel {
52 private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
53 private static DropdownListSearchPanel instance;
54 private XmlKeywordSearchList loader;
55 private final KeywordListsTableModel listsTableModel;
56 private final KeywordsTableModel keywordsTableModel;
57 private ActionListener searchAddListener;
58 private boolean ingestRunning;
63 private DropdownListSearchPanel() {
64 listsTableModel =
new KeywordListsTableModel();
65 keywordsTableModel =
new KeywordsTableModel();
67 customizeComponents();
70 static synchronized DropdownListSearchPanel getDefault() {
71 if (instance == null) {
72 instance =
new DropdownListSearchPanel();
77 private void customizeComponents() {
78 listsTable.setTableHeader(null);
79 listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
81 final int leftWidth = leftPane.getPreferredSize().width;
83 for (
int i = 0; i < listsTable.getColumnCount(); i++) {
84 column = listsTable.getColumnModel().getColumn(i);
86 column.setPreferredWidth(((
int) (leftWidth * 0.10)));
87 column.setCellRenderer(
new LeftCheckBoxRenderer());
89 column.setPreferredWidth(((
int) (leftWidth * 0.89)));
92 final int rightWidth = rightPane.getPreferredSize().width;
93 for (
int i = 0; i < keywordsTable.getColumnCount(); i++) {
94 column = keywordsTable.getColumnModel().getColumn(i);
96 column.setPreferredWidth(((
int) (rightWidth * 0.78)));
98 column.setPreferredWidth(((
int) (rightWidth * 0.20)));
99 column.setCellRenderer(
new CheckBoxRenderer());
103 loader = XmlKeywordSearchList.getCurrent();
104 listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
106 public void valueChanged(ListSelectionEvent e) {
107 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
108 if (!listSelectionModel.isSelectionEmpty()) {
109 int index = listSelectionModel.getMinSelectionIndex();
110 KeywordList list = listsTableModel.getListAt(index);
111 keywordsTableModel.resync(list);
113 keywordsTableModel.deleteAll();
118 ingestRunning = IngestManager.getInstance().isIngestRunning();
121 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
123 public void propertyChange(PropertyChangeEvent evt) {
124 Object source = evt.getSource();
125 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
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));
170 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
175 protected void postFilesIndexedChange() {
176 updateIngestIndexLabel();
183 listsTableModel.resync();
191 @SuppressWarnings(
"unchecked")
193 private
void initComponents() {
195 jSplitPane1 =
new javax.swing.JSplitPane();
196 leftPane =
new javax.swing.JScrollPane();
197 listsTable =
new javax.swing.JTable();
198 rightPane =
new javax.swing.JScrollPane();
199 keywordsTable =
new javax.swing.JTable();
200 manageListsButton =
new javax.swing.JButton();
201 searchAddButton =
new javax.swing.JButton();
202 ingestIndexLabel =
new javax.swing.JLabel();
204 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
206 jSplitPane1.setFont(leftPane.getFont());
208 leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
209 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
211 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
212 listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
213 listsTable.setModel(listsTableModel);
214 listsTable.setShowHorizontalLines(
false);
215 listsTable.setShowVerticalLines(
false);
216 listsTable.getTableHeader().setReorderingAllowed(
false);
217 leftPane.setViewportView(listsTable);
219 jSplitPane1.setLeftComponent(leftPane);
221 rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
223 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
224 keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
225 keywordsTable.setModel(keywordsTableModel);
226 keywordsTable.setGridColor(
new java.awt.Color(153, 153, 153));
227 rightPane.setViewportView(keywordsTable);
229 jSplitPane1.setRightComponent(rightPane);
231 manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
232 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
233 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
234 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
235 public void actionPerformed(java.awt.event.ActionEvent evt) {
236 manageListsButtonActionPerformed(evt);
240 searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
241 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
242 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
243 public void actionPerformed(java.awt.event.ActionEvent evt) {
244 searchAddButtonActionPerformed(evt);
248 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
249 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
251 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
252 this.setLayout(layout);
253 layout.setHorizontalGroup(
254 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
256 .addGroup(layout.createSequentialGroup()
258 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
260 .addComponent(searchAddButton)
261 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 220, Short.MAX_VALUE)
262 .addComponent(manageListsButton))
263 .addGroup(layout.createSequentialGroup()
264 .addComponent(ingestIndexLabel)
265 .addGap(0, 317, Short.MAX_VALUE)))
268 layout.setVerticalGroup(
269 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270 .addGroup(layout.createSequentialGroup()
271 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
273 .addComponent(ingestIndexLabel)
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
276 .addComponent(manageListsButton)
277 .addComponent(searchAddButton))
282 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
283 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
286 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
291 private javax.swing.JLabel ingestIndexLabel;
292 private javax.swing.JSplitPane jSplitPane1;
293 private javax.swing.JTable keywordsTable;
294 private javax.swing.JScrollPane leftPane;
295 private javax.swing.JTable listsTable;
296 private javax.swing.JButton manageListsButton;
297 private javax.swing.JScrollPane rightPane;
298 private javax.swing.JButton searchAddButton;
301 private void searchAction(ActionEvent e) {
302 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
312 List<KeywordList> getKeywordLists() {
313 return listsTableModel.getSelectedListsL();
316 void addSearchButtonActionListener(ActionListener al) {
317 searchAddButton.addActionListener(al);
323 private XmlKeywordSearchList
listsHandle = XmlKeywordSearchList.getCurrent();
324 private List<ListTableEntry>
listData =
new ArrayList<>();
333 return listData.size();
341 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
344 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
357 Iterator<ListTableEntry> it = listData.iterator();
358 for (
int i = 0; i <= rowIndex; ++i) {
362 switch (columnIndex) {
364 ret = (Object) entry.selected;
367 ret = (Object) entry.name;
378 return (columnIndex == 0 && !ingestRunning);
382 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
383 if (columnIndex == 0) {
385 Iterator<ListTableEntry> it = listData.iterator();
386 for (
int i = 0; i <= rowIndex; i++) {
390 entry.selected = (Boolean) aValue;
404 List<String> getAllLists() {
405 List<String> ret =
new ArrayList<>();
406 for (ListTableEntry e : listData) {
412 KeywordList getListAt(
int rowIndex) {
413 return listsHandle.getList((String)
getValueAt(rowIndex, 1));
416 List<String> getSelectedLists() {
417 List<String> ret =
new ArrayList<>();
418 for (ListTableEntry e : listData) {
426 List<KeywordList> getSelectedListsL() {
427 List<KeywordList> ret =
new ArrayList<>();
428 for (String s : getSelectedLists()) {
429 ret.add(listsHandle.getList(s));
434 boolean listExists(String list) {
435 List<String> all = getAllLists();
436 return all.contains(list);
443 fireTableDataChanged();
449 if (!listExists(list.getName())) {
462 this.name = list.getName();
464 this.selected = list.getUseForIngest();
466 this.selected =
false;
472 return this.name.compareTo(e.name);
479 List<KeywordTableEntry> listData =
new ArrayList<>();
483 return listData.size();
496 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
499 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.regExColLbl");
512 Iterator<KeywordTableEntry> it = listData.iterator();
513 for (
int i = 0; i <= rowIndex; ++i) {
517 switch (columnIndex) {
519 ret = (Object) entry.name;
522 ret = (Object) entry.regex;
537 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
547 for (Keyword k : list.getKeywords()) {
548 listData.add(
new KeywordTableEntry(k));
550 fireTableDataChanged();
555 fireTableDataChanged();
565 this.name = keyword.getSearchTerm();
566 this.regex = !keyword.searchTermIsLiteral();
571 return this.name.compareTo(e.name);
580 JTable table, Object value,
581 boolean isSelected,
boolean hasFocus,
582 int row,
int column) {
584 this.setHorizontalAlignment(JCheckBox.CENTER);
585 this.setVerticalAlignment(JCheckBox.CENTER);
587 setEnabled(!ingestRunning);
589 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
590 setSelected(selected);
593 setBackground(listsTable.getSelectionBackground());
595 setBackground(listsTable.getBackground());
609 final ImageIcon theCheck =
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/checkmark.png"));
612 setHorizontalAlignment(CENTER);
618 if ((value instanceof Boolean)) {
619 if ((Boolean) value) {
621 setToolTipText(Bundle.IsRegularExpression());
624 setToolTipText(null);
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)
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
static final long serialVersionUID
Object getValueAt(int rowIndex, int columnIndex)
List< ListTableEntry > listData