19 package org.sleuthkit.autopsy.keywordsearch;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.MouseMotionListener;
26 import java.beans.PropertyChangeEvent;
27 import java.beans.PropertyChangeListener;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.Iterator;
31 import java.util.List;
33 import java.util.logging.Level;
34 import javax.swing.JCheckBox;
35 import javax.swing.JList;
36 import javax.swing.JTable;
37 import javax.swing.ListSelectionModel;
38 import javax.swing.event.ListSelectionEvent;
39 import javax.swing.event.ListSelectionListener;
40 import javax.swing.table.AbstractTableModel;
41 import javax.swing.table.TableCellRenderer;
42 import javax.swing.table.TableColumn;
43 import org.openide.util.NbBundle;
44 import org.openide.util.actions.SystemAction;
52 @SuppressWarnings(
"PMD.SingularField")
53 class DropdownListSearchPanel extends AdHocSearchPanel {
55 private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
56 private static DropdownListSearchPanel instance;
57 private XmlKeywordSearchList loader;
58 private final KeywordListsTableModel listsTableModel;
59 private final KeywordsTableModel keywordsTableModel;
60 private ActionListener searchAddListener;
61 private boolean ingestRunning;
66 private DropdownListSearchPanel() {
67 listsTableModel =
new KeywordListsTableModel();
68 keywordsTableModel =
new KeywordsTableModel();
70 customizeComponents();
71 dataSourceList.setModel(getDataSourceListModel());
73 dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
74 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
76 dataSourceList.addMouseMotionListener(
new MouseMotionListener() {
79 public void mouseDragged(MouseEvent evt) {
84 public void mouseMoved(MouseEvent evt) {
85 JList<String> dsList = (JList<String>) evt.getSource();
86 int index = dsList.locationToIndex(evt.getPoint());
88 dsList.setToolTipText(getDataSourceToolTipList().
get(index));
94 static synchronized DropdownListSearchPanel getDefault() {
95 if (instance == null) {
96 instance =
new DropdownListSearchPanel();
101 private void customizeComponents() {
102 listsTable.setTableHeader(null);
103 listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
105 final int leftWidth = leftPane.getPreferredSize().width;
107 for (
int i = 0; i < listsTable.getColumnCount(); i++) {
108 column = listsTable.getColumnModel().getColumn(i);
110 column.setPreferredWidth(((
int) (leftWidth * 0.10)));
111 column.setCellRenderer(
new LeftCheckBoxRenderer());
113 column.setPreferredWidth(((
int) (leftWidth * 0.89)));
116 final int rightWidth = rightPane.getPreferredSize().width;
117 for (
int i = 0; i < keywordsTable.getColumnCount(); i++) {
118 column = keywordsTable.getColumnModel().getColumn(i);
120 column.setPreferredWidth(((
int) (rightWidth * 0.60)));
122 column.setPreferredWidth(((
int) (rightWidth * 0.38)));
126 loader = XmlKeywordSearchList.getCurrent();
127 listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
129 public void valueChanged(ListSelectionEvent e) {
130 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
131 if (!listSelectionModel.isSelectionEmpty()) {
132 int index = listSelectionModel.getMinSelectionIndex();
133 KeywordList list = listsTableModel.getListAt(index);
134 keywordsTableModel.resync(list);
136 keywordsTableModel.deleteAll();
141 ingestRunning = IngestManager.getInstance().isIngestRunning();
144 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
146 public void propertyChange(PropertyChangeEvent evt) {
147 Object source = evt.getSource();
148 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
149 EventQueue.invokeLater(() -> {
150 ingestRunning = IngestManager.getInstance().isIngestRunning();
157 searchAddListener =
new ActionListener() {
159 public void actionPerformed(ActionEvent e) {
161 IngestSearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
162 logger.log(Level.INFO,
"Submitted enqueued lists to ingest");
169 searchAddButton.addActionListener(searchAddListener);
172 private void updateComponents() {
173 ingestRunning = IngestManager.getInstance().isIngestRunning();
175 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
176 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
179 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
180 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
182 listsTableModel.resync();
183 updateIngestIndexLabel();
186 private void updateIngestIndexLabel() {
188 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
190 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
195 protected void postFilesIndexedChange() {
196 updateIngestIndexLabel();
203 listsTableModel.resync();
211 @SuppressWarnings(
"unchecked")
213 private
void initComponents() {
215 jSplitPane1 =
new javax.swing.JSplitPane();
216 leftPane =
new javax.swing.JScrollPane();
217 listsTable =
new javax.swing.JTable();
218 rightPane =
new javax.swing.JScrollPane();
219 keywordsTable =
new javax.swing.JTable();
220 manageListsButton =
new javax.swing.JButton();
221 searchAddButton =
new javax.swing.JButton();
222 ingestIndexLabel =
new javax.swing.JLabel();
223 dataSourceCheckBox =
new javax.swing.JCheckBox();
224 jScrollPane1 =
new javax.swing.JScrollPane();
225 dataSourceList =
new javax.swing.JList<>();
227 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
229 jSplitPane1.setFont(leftPane.getFont());
231 leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
232 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
234 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
235 listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
236 listsTable.setModel(listsTableModel);
237 listsTable.setShowHorizontalLines(
false);
238 listsTable.setShowVerticalLines(
false);
239 listsTable.getTableHeader().setReorderingAllowed(
false);
240 leftPane.setViewportView(listsTable);
242 jSplitPane1.setLeftComponent(leftPane);
244 rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
246 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
247 keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
248 keywordsTable.setModel(keywordsTableModel);
249 keywordsTable.setGridColor(
new java.awt.Color(153, 153, 153));
250 rightPane.setViewportView(keywordsTable);
252 jSplitPane1.setRightComponent(rightPane);
254 manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
255 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
256 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
257 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
258 public void actionPerformed(java.awt.event.ActionEvent evt) {
259 manageListsButtonActionPerformed(evt);
263 searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
264 searchAddButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/search-icon.png")));
265 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
266 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
267 public void actionPerformed(java.awt.event.ActionEvent evt) {
268 searchAddButtonActionPerformed(evt);
272 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
273 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
275 dataSourceCheckBox.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"DropdownListSearchPanel.dataSourceCheckBox.text"));
276 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
277 public void actionPerformed(java.awt.event.ActionEvent evt) {
278 dataSourceCheckBoxActionPerformed(evt);
282 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
283 jScrollPane1.setViewportView(dataSourceList);
285 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
286 this.setLayout(layout);
287 layout.setHorizontalGroup(
288 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
290 .addGroup(layout.createSequentialGroup()
292 .addComponent(searchAddButton)
293 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
294 .addComponent(manageListsButton)
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296 .addComponent(ingestIndexLabel)
297 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
298 .addGroup(layout.createSequentialGroup()
299 .addComponent(dataSourceCheckBox)
300 .addGap(0, 0, Short.MAX_VALUE))
301 .addComponent(jScrollPane1)
304 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {manageListsButton, searchAddButton});
306 layout.setVerticalGroup(
307 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308 .addGroup(layout.createSequentialGroup()
309 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
310 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
311 .addComponent(dataSourceCheckBox)
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
313 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
314 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
316 .addComponent(manageListsButton)
317 .addComponent(searchAddButton)
318 .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
323 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
324 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
327 private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
328 updateDataSourceListModel();
331 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
336 private javax.swing.JCheckBox dataSourceCheckBox;
337 private javax.swing.JList<String> dataSourceList;
338 private javax.swing.JLabel ingestIndexLabel;
339 private javax.swing.JScrollPane jScrollPane1;
340 private javax.swing.JSplitPane jSplitPane1;
341 private javax.swing.JTable keywordsTable;
342 private javax.swing.JScrollPane leftPane;
343 private javax.swing.JTable listsTable;
344 private javax.swing.JButton manageListsButton;
345 private javax.swing.JScrollPane rightPane;
346 private javax.swing.JButton searchAddButton;
349 private void searchAction(ActionEvent e) {
350 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
360 List<KeywordList> getKeywordLists() {
361 return listsTableModel.getSelectedListsL();
364 void addSearchButtonActionListener(ActionListener al) {
365 searchAddButton.addActionListener(al);
373 Set<Long> getDataSourcesSelected() {
374 Set<Long> dataSourceObjIdSet =
new HashSet<>();
375 for (Long key : getDataSourceMap().keySet()) {
376 String value = getDataSourceMap().get(key);
377 for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
378 if (value.equals(dataSource)) {
379 dataSourceObjIdSet.add(key);
383 return dataSourceObjIdSet;
389 private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
390 private final List<ListTableEntry> listData =
new ArrayList<>();
399 return listData.size();
407 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
410 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
423 Iterator<ListTableEntry> it = listData.iterator();
424 for (
int i = 0; i <= rowIndex; ++i) {
428 switch (columnIndex) {
430 ret = (Object) entry.selected;
433 ret = (Object) entry.name;
444 return (columnIndex == 0 && !ingestRunning);
448 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
449 if (columnIndex == 0) {
451 Iterator<ListTableEntry> it = listData.iterator();
452 for (
int i = 0; i <= rowIndex; i++) {
456 entry.selected = (Boolean) aValue;
467 return getValueAt(0, c).getClass();
470 List<String> getAllLists() {
471 List<String> ret =
new ArrayList<>();
472 for (ListTableEntry e : listData) {
478 KeywordList getListAt(
int rowIndex) {
479 return listsHandle.getList((String) getValueAt(rowIndex, 1));
482 List<String> getSelectedLists() {
483 List<String> ret =
new ArrayList<>();
484 for (ListTableEntry e : listData) {
492 List<KeywordList> getSelectedListsL() {
493 List<KeywordList> ret =
new ArrayList<>();
494 for (String s : getSelectedLists()) {
495 ret.add(listsHandle.getList(s));
500 boolean listExists(String list) {
501 List<String> all = getAllLists();
502 return all.contains(list);
508 addLists(listsHandle.getListsL());
509 fireTableDataChanged();
515 if (!listExists(list.getName())) {
528 this.name = list.getName();
530 this.selected = list.getUseForIngest();
532 this.selected =
false;
538 return this.name.compareTo(e.name);
545 List<KeywordTableEntry> listData =
new ArrayList<>();
549 return listData.size();
562 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
565 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
578 Iterator<KeywordTableEntry> it = listData.iterator();
579 for (
int i = 0; i <= rowIndex; ++i) {
583 switch (columnIndex) {
585 ret = (Object) entry.name;
588 ret = (Object) entry.keywordType;
603 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
608 return getValueAt(0, c).getClass();
613 for (Keyword k : list.getKeywords()) {
614 listData.add(
new KeywordTableEntry(k));
616 fireTableDataChanged();
621 fireTableDataChanged();
631 this.name = keyword.getSearchTerm();
632 this.keywordType = keyword.getSearchTermType();
637 return this.name.compareTo(e.name);
646 JTable table, Object value,
647 boolean isSelected,
boolean hasFocus,
648 int row,
int column) {
650 this.setHorizontalAlignment(JCheckBox.CENTER);
651 this.setVerticalAlignment(JCheckBox.CENTER);
653 setEnabled(!ingestRunning);
655 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
656 setSelected(selected);
659 setBackground(listsTable.getSelectionBackground());
661 setBackground(listsTable.getBackground());
671 @NbBundle.Messages({
"DropdownListSearchPanel.selected=Ad Hoc Search data source filter is selected"})
672 void updateDataSourceListModel() {
673 getDataSourceListModel().removeAllElements();
674 for (String dsName : getDataSourceArray()) {
675 getDataSourceListModel().addElement(dsName);
677 setComponentsEnabled();
678 firePropertyChange(Bundle.DropdownListSearchPanel_selected(), null, null);
685 private void setComponentsEnabled() {
686 boolean enabled = this.dataSourceCheckBox.isSelected();
687 this.dataSourceList.setEnabled(enabled);
689 this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
691 this.dataSourceList.setSelectedIndices(
new int[0]);
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)