19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.EventQueue;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
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 javax.swing.JCheckBox;
34 import javax.swing.JTable;
35 import javax.swing.ListSelectionModel;
36 import javax.swing.event.ListSelectionEvent;
37 import javax.swing.event.ListSelectionListener;
38 import javax.swing.table.AbstractTableModel;
39 import javax.swing.table.TableCellRenderer;
40 import javax.swing.table.TableColumn;
41 import org.openide.util.NbBundle;
42 import org.openide.util.actions.SystemAction;
51 @SuppressWarnings(
"PMD.SingularField")
52 class DropdownListSearchPanel extends AdHocSearchPanel {
54 private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
55 private static DropdownListSearchPanel instance;
56 private XmlKeywordSearchList loader;
57 private final KeywordListsTableModel listsTableModel;
58 private final KeywordsTableModel keywordsTableModel;
59 private ActionListener searchAddListener;
60 private boolean ingestRunning;
65 private DropdownListSearchPanel() {
66 listsTableModel =
new KeywordListsTableModel();
67 keywordsTableModel =
new KeywordsTableModel();
69 customizeComponents();
70 dataSourceList.setModel(getDataSourceListModel());
72 dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
73 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
77 static synchronized DropdownListSearchPanel getDefault() {
78 if (instance == null) {
79 instance =
new DropdownListSearchPanel();
84 private void customizeComponents() {
85 listsTable.setTableHeader(null);
86 listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
88 final int leftWidth = leftPane.getPreferredSize().width;
90 for (
int i = 0; i < listsTable.getColumnCount(); i++) {
91 column = listsTable.getColumnModel().getColumn(i);
93 column.setPreferredWidth(((
int) (leftWidth * 0.10)));
94 column.setCellRenderer(
new LeftCheckBoxRenderer());
96 column.setPreferredWidth(((
int) (leftWidth * 0.89)));
97 column.setCellRenderer(
new SimpleTableCellRenderer());
100 final int rightWidth = rightPane.getPreferredSize().width;
101 for (
int i = 0; i < keywordsTable.getColumnCount(); i++) {
102 column = keywordsTable.getColumnModel().getColumn(i);
104 column.setPreferredWidth(((
int) (rightWidth * 0.60)));
106 column.setPreferredWidth(((
int) (rightWidth * 0.38)));
109 keywordsTable.setDefaultRenderer(String.class,
new SimpleTableCellRenderer());
111 loader = XmlKeywordSearchList.getCurrent();
112 listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
114 public void valueChanged(ListSelectionEvent e) {
115 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
116 if (!listSelectionModel.isSelectionEmpty()) {
117 int index = listSelectionModel.getMinSelectionIndex();
118 KeywordList list = listsTableModel.getListAt(index);
119 keywordsTableModel.resync(list);
121 keywordsTableModel.deleteAll();
126 ingestRunning = IngestManager.getInstance().isIngestRunning();
129 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
131 public void propertyChange(PropertyChangeEvent evt) {
132 Object source = evt.getSource();
133 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
134 EventQueue.invokeLater(() -> {
135 ingestRunning = IngestManager.getInstance().isIngestRunning();
142 searchAddListener =
new ActionListener() {
144 public void actionPerformed(ActionEvent e) {
145 if (!ingestRunning) {
151 searchAddButton.addActionListener(searchAddListener);
154 private void updateComponents() {
155 ingestRunning = IngestManager.getInstance().isIngestRunning();
157 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
158 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
161 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
162 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
164 listsTableModel.resync();
165 updateIngestIndexLabel();
167 jSaveSearchResults.setSelected(
true);
170 private void updateIngestIndexLabel() {
172 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
174 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
179 protected void postFilesIndexedChange() {
180 updateIngestIndexLabel();
187 listsTableModel.resync();
195 @SuppressWarnings(
"unchecked")
197 private
void initComponents() {
199 jSplitPane1 =
new javax.swing.JSplitPane();
200 leftPane =
new javax.swing.JScrollPane();
201 listsTable =
new javax.swing.JTable();
202 rightPane =
new javax.swing.JScrollPane();
203 keywordsTable =
new javax.swing.JTable();
204 manageListsButton =
new javax.swing.JButton();
205 searchAddButton =
new javax.swing.JButton();
206 ingestIndexLabel =
new javax.swing.JLabel();
207 dataSourceCheckBox =
new javax.swing.JCheckBox();
208 jScrollPane1 =
new javax.swing.JScrollPane();
209 dataSourceList =
new javax.swing.JList<>();
210 jSaveSearchResults =
new javax.swing.JCheckBox();
212 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
213 leftPane.setOpaque(
false);
215 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
216 listsTable.setModel(listsTableModel);
217 listsTable.setShowHorizontalLines(
false);
218 listsTable.setShowVerticalLines(
false);
219 listsTable.getTableHeader().setReorderingAllowed(
false);
220 leftPane.setViewportView(listsTable);
222 jSplitPane1.setLeftComponent(leftPane);
224 rightPane.setOpaque(
false);
226 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
227 keywordsTable.setModel(keywordsTableModel);
228 keywordsTable.setGridColor(
new java.awt.Color(153, 153, 153));
229 rightPane.setViewportView(keywordsTable);
231 jSplitPane1.setRightComponent(rightPane);
233 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
234 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
235 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 manageListsButtonActionPerformed(evt);
241 searchAddButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/search-icon.png")));
242 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
243 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
244 public void actionPerformed(java.awt.event.ActionEvent evt) {
245 searchAddButtonActionPerformed(evt);
249 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getSize()-1f));
250 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
252 dataSourceCheckBox.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"DropdownListSearchPanel.dataSourceCheckBox.text"));
253 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
254 public void actionPerformed(java.awt.event.ActionEvent evt) {
255 dataSourceCheckBoxActionPerformed(evt);
259 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
260 jScrollPane1.setViewportView(dataSourceList);
262 jSaveSearchResults.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"DropdownListSearchPanel.jSaveSearchResults.text"));
263 jSaveSearchResults.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"DropdownListSearchPanel.jSaveSearchResults.toolTipText"));
265 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
266 this.setLayout(layout);
267 layout.setHorizontalGroup(
268 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
270 .addComponent(jScrollPane1)
271 .addGroup(layout.createSequentialGroup()
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addComponent(dataSourceCheckBox)
274 .addComponent(jSaveSearchResults)
275 .addGroup(layout.createSequentialGroup()
276 .addComponent(searchAddButton)
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
278 .addComponent(manageListsButton)
279 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
280 .addComponent(ingestIndexLabel)))
281 .addGap(0, 120, Short.MAX_VALUE))
284 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {manageListsButton, searchAddButton});
286 layout.setVerticalGroup(
287 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addGroup(layout.createSequentialGroup()
289 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
290 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
291 .addComponent(dataSourceCheckBox)
292 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
294 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
295 .addComponent(jSaveSearchResults)
296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
297 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
298 .addComponent(manageListsButton)
299 .addComponent(searchAddButton)
300 .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
305 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
306 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
309 private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
310 updateDataSourceListModel();
313 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
318 private javax.swing.JCheckBox dataSourceCheckBox;
319 private javax.swing.JList<String> dataSourceList;
320 private javax.swing.JLabel ingestIndexLabel;
321 private javax.swing.JCheckBox jSaveSearchResults;
322 private javax.swing.JScrollPane jScrollPane1;
323 private javax.swing.JSplitPane jSplitPane1;
324 private javax.swing.JTable keywordsTable;
325 private javax.swing.JScrollPane leftPane;
326 private javax.swing.JTable listsTable;
327 private javax.swing.JButton manageListsButton;
328 private javax.swing.JScrollPane rightPane;
329 private javax.swing.JButton searchAddButton;
332 private void searchAction(ActionEvent e) {
333 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
336 search(jSaveSearchResults.isSelected());
343 List<KeywordList> getKeywordLists() {
344 return listsTableModel.getSelectedListsL();
347 void addSearchButtonActionListener(ActionListener al) {
348 searchAddButton.addActionListener(al);
356 Set<Long> getDataSourcesSelected() {
357 Set<Long> dataSourceObjIdSet =
new HashSet<>();
358 for (Long key : getDataSourceMap().keySet()) {
359 String value = getDataSourceMap().get(key);
360 for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
361 if (value.equals(dataSource)) {
362 dataSourceObjIdSet.add(key);
366 return dataSourceObjIdSet;
372 private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
373 private final List<ListTableEntry> listData =
new ArrayList<>();
382 return listData.size();
390 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
393 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
406 Iterator<ListTableEntry> it = listData.iterator();
407 for (
int i = 0; i <= rowIndex; ++i) {
411 switch (columnIndex) {
413 ret = (Object) entry.selected;
416 ret = (Object) entry.name;
427 return (columnIndex == 0 && !ingestRunning);
431 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
432 if (columnIndex == 0) {
434 Iterator<ListTableEntry> it = listData.iterator();
435 for (
int i = 0; i <= rowIndex; i++) {
439 entry.selected = (Boolean) aValue;
450 return getValueAt(0, c).getClass();
453 List<String> getAllLists() {
454 List<String> ret =
new ArrayList<>();
455 for (ListTableEntry e : listData) {
461 KeywordList getListAt(
int rowIndex) {
462 return listsHandle.getList((String) getValueAt(rowIndex, 1));
465 List<String> getSelectedLists() {
466 List<String> ret =
new ArrayList<>();
467 for (ListTableEntry e : listData) {
475 List<KeywordList> getSelectedListsL() {
476 List<KeywordList> ret =
new ArrayList<>();
477 for (String s : getSelectedLists()) {
478 ret.add(listsHandle.getList(s));
483 boolean listExists(String list) {
484 List<String> all = getAllLists();
485 return all.contains(list);
491 addLists(listsHandle.getListsL());
492 fireTableDataChanged();
498 if (!listExists(list.getName())) {
511 this.name = list.getName();
513 this.selected = list.getUseForIngest();
515 this.selected =
false;
521 return this.name.compareTo(e.name);
528 List<KeywordTableEntry> listData =
new ArrayList<>();
532 return listData.size();
545 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
548 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
561 Iterator<KeywordTableEntry> it = listData.iterator();
562 for (
int i = 0; i <= rowIndex; ++i) {
566 switch (columnIndex) {
568 ret = (Object) entry.name;
571 ret = (Object) entry.keywordType;
586 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
591 return getValueAt(0, c).getClass();
597 listData.add(
new KeywordTableEntry(k));
599 fireTableDataChanged();
604 fireTableDataChanged();
615 this.keywordType = keyword.getSearchTermType();
620 return this.name.compareTo(e.name);
629 JTable table, Object value,
630 boolean isSelected,
boolean hasFocus,
631 int row,
int column) {
633 this.setHorizontalAlignment(JCheckBox.CENTER);
634 this.setVerticalAlignment(JCheckBox.CENTER);
636 setEnabled(!ingestRunning);
638 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
639 setSelected(selected);
642 setBackground(listsTable.getSelectionBackground());
644 setBackground(listsTable.getBackground());
654 @NbBundle.Messages({
"DropdownListSearchPanel.selected=Ad Hoc Search data source filter is selected"})
655 void updateDataSourceListModel() {
656 getDataSourceListModel().removeAllElements();
657 for (String dsName : getDataSourceArray()) {
658 getDataSourceListModel().addElement(dsName);
660 setComponentsEnabled();
661 firePropertyChange(Bundle.DropdownListSearchPanel_selected(), null, null);
668 private void setComponentsEnabled() {
670 if (getDataSourceListModel().size() > 1) {
671 this.dataSourceCheckBox.setEnabled(
true);
673 boolean enabled = this.dataSourceCheckBox.isSelected();
674 this.dataSourceList.setEnabled(enabled);
676 this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
678 this.dataSourceList.setSelectedIndices(
new int[0]);
681 this.dataSourceCheckBox.setEnabled(
false);
682 this.dataSourceCheckBox.setSelected(
false);
683 this.dataSourceList.setEnabled(
false);
684 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)
List< Keyword > getKeywords()
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)