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 @SuppressWarnings(
"PMD.SingularField")
48 class DropdownListSearchPanel extends AdHocSearchPanel {
50 private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
51 private static DropdownListSearchPanel instance;
52 private XmlKeywordSearchList loader;
53 private final KeywordListsTableModel listsTableModel;
54 private final 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.60)));
96 column.setPreferredWidth(((
int) (rightWidth * 0.38)));
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(() -> {
124 ingestRunning = IngestManager.getInstance().isIngestRunning();
131 searchAddListener =
new ActionListener() {
133 public void actionPerformed(ActionEvent e) {
135 IngestSearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
136 logger.log(Level.INFO,
"Submitted enqueued lists to ingest");
143 searchAddButton.addActionListener(searchAddListener);
146 private void updateComponents() {
147 ingestRunning = IngestManager.getInstance().isIngestRunning();
149 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
150 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
153 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
154 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
156 listsTableModel.resync();
157 updateIngestIndexLabel();
160 private void updateIngestIndexLabel() {
162 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
164 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
169 protected void postFilesIndexedChange() {
170 updateIngestIndexLabel();
177 listsTableModel.resync();
185 @SuppressWarnings(
"unchecked")
187 private
void initComponents() {
189 jSplitPane1 =
new javax.swing.JSplitPane();
190 leftPane =
new javax.swing.JScrollPane();
191 listsTable =
new javax.swing.JTable();
192 rightPane =
new javax.swing.JScrollPane();
193 keywordsTable =
new javax.swing.JTable();
194 manageListsButton =
new javax.swing.JButton();
195 searchAddButton =
new javax.swing.JButton();
196 ingestIndexLabel =
new javax.swing.JLabel();
198 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
200 jSplitPane1.setFont(leftPane.getFont());
202 leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
203 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
205 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
206 listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
207 listsTable.setModel(listsTableModel);
208 listsTable.setShowHorizontalLines(
false);
209 listsTable.setShowVerticalLines(
false);
210 listsTable.getTableHeader().setReorderingAllowed(
false);
211 leftPane.setViewportView(listsTable);
213 jSplitPane1.setLeftComponent(leftPane);
215 rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
217 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
218 keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
219 keywordsTable.setModel(keywordsTableModel);
220 keywordsTable.setGridColor(
new java.awt.Color(153, 153, 153));
221 rightPane.setViewportView(keywordsTable);
223 jSplitPane1.setRightComponent(rightPane);
225 manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
226 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
227 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
228 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 manageListsButtonActionPerformed(evt);
234 searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
235 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
236 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
237 public void actionPerformed(java.awt.event.ActionEvent evt) {
238 searchAddButtonActionPerformed(evt);
242 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
243 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
245 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
246 this.setLayout(layout);
247 layout.setHorizontalGroup(
248 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
250 .addGroup(layout.createSequentialGroup()
252 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
254 .addComponent(searchAddButton)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 220, Short.MAX_VALUE)
256 .addComponent(manageListsButton))
257 .addGroup(layout.createSequentialGroup()
258 .addComponent(ingestIndexLabel)
259 .addGap(0, 317, Short.MAX_VALUE)))
262 layout.setVerticalGroup(
263 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addGroup(layout.createSequentialGroup()
265 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
266 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
267 .addComponent(ingestIndexLabel)
268 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
269 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
270 .addComponent(manageListsButton)
271 .addComponent(searchAddButton))
276 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
277 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
280 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
285 private javax.swing.JLabel ingestIndexLabel;
286 private javax.swing.JSplitPane jSplitPane1;
287 private javax.swing.JTable keywordsTable;
288 private javax.swing.JScrollPane leftPane;
289 private javax.swing.JTable listsTable;
290 private javax.swing.JButton manageListsButton;
291 private javax.swing.JScrollPane rightPane;
292 private javax.swing.JButton searchAddButton;
295 private void searchAction(ActionEvent e) {
296 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
306 List<KeywordList> getKeywordLists() {
307 return listsTableModel.getSelectedListsL();
310 void addSearchButtonActionListener(ActionListener al) {
311 searchAddButton.addActionListener(al);
317 private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
318 private final List<ListTableEntry> listData =
new ArrayList<>();
327 return listData.size();
335 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
338 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
351 Iterator<ListTableEntry> it = listData.iterator();
352 for (
int i = 0; i <= rowIndex; ++i) {
356 switch (columnIndex) {
358 ret = (Object) entry.selected;
361 ret = (Object) entry.name;
372 return (columnIndex == 0 && !ingestRunning);
376 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
377 if (columnIndex == 0) {
379 Iterator<ListTableEntry> it = listData.iterator();
380 for (
int i = 0; i <= rowIndex; i++) {
384 entry.selected = (Boolean) aValue;
395 return getValueAt(0, c).getClass();
398 List<String> getAllLists() {
399 List<String> ret =
new ArrayList<>();
400 for (ListTableEntry e : listData) {
406 KeywordList getListAt(
int rowIndex) {
407 return listsHandle.getList((String) getValueAt(rowIndex, 1));
410 List<String> getSelectedLists() {
411 List<String> ret =
new ArrayList<>();
412 for (ListTableEntry e : listData) {
420 List<KeywordList> getSelectedListsL() {
421 List<KeywordList> ret =
new ArrayList<>();
422 for (String s : getSelectedLists()) {
423 ret.add(listsHandle.getList(s));
428 boolean listExists(String list) {
429 List<String> all = getAllLists();
430 return all.contains(list);
436 addLists(listsHandle.getListsL());
437 fireTableDataChanged();
443 if (!listExists(list.getName())) {
456 this.name = list.getName();
458 this.selected = list.getUseForIngest();
460 this.selected =
false;
466 return this.name.compareTo(e.name);
473 List<KeywordTableEntry> listData =
new ArrayList<>();
477 return listData.size();
490 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
493 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
506 Iterator<KeywordTableEntry> it = listData.iterator();
507 for (
int i = 0; i <= rowIndex; ++i) {
511 switch (columnIndex) {
513 ret = (Object) entry.name;
516 ret = (Object) entry.keywordType;
531 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
536 return getValueAt(0, c).getClass();
541 for (Keyword k : list.getKeywords()) {
542 listData.add(
new KeywordTableEntry(k));
544 fireTableDataChanged();
549 fireTableDataChanged();
559 this.name = keyword.getSearchTerm();
560 this.keywordType = keyword.getSearchTermType();
565 return this.name.compareTo(e.name);
574 JTable table, Object value,
575 boolean isSelected,
boolean hasFocus,
576 int row,
int column) {
578 this.setHorizontalAlignment(JCheckBox.CENTER);
579 this.setVerticalAlignment(JCheckBox.CENTER);
581 setEnabled(!ingestRunning);
583 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
584 setSelected(selected);
587 setBackground(listsTable.getSelectionBackground());
589 setBackground(listsTable.getBackground());
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)