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.60)));
95 column.setPreferredWidth(((
int) (rightWidth * 0.38)));
99 loader = XmlKeywordSearchList.getCurrent();
100 listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
102 public void valueChanged(ListSelectionEvent e) {
103 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
104 if (!listSelectionModel.isSelectionEmpty()) {
105 int index = listSelectionModel.getMinSelectionIndex();
106 KeywordList list = listsTableModel.getListAt(index);
107 keywordsTableModel.resync(list);
109 keywordsTableModel.deleteAll();
114 ingestRunning = IngestManager.getInstance().isIngestRunning();
117 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
119 public void propertyChange(PropertyChangeEvent evt) {
120 Object source = evt.getSource();
121 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
122 EventQueue.invokeLater(() -> {
123 ingestRunning = IngestManager.getInstance().isIngestRunning();
130 searchAddListener =
new ActionListener() {
132 public void actionPerformed(ActionEvent e) {
134 SearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
135 logger.log(Level.INFO,
"Submitted enqueued lists to ingest");
142 searchAddButton.addActionListener(searchAddListener);
145 private void updateComponents() {
146 ingestRunning = IngestManager.getInstance().isIngestRunning();
148 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
149 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
152 searchAddButton.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
153 searchAddButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
155 listsTableModel.resync();
156 updateIngestIndexLabel();
159 private void updateIngestIndexLabel() {
161 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
163 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
168 protected void postFilesIndexedChange() {
169 updateIngestIndexLabel();
176 listsTableModel.resync();
184 @SuppressWarnings(
"unchecked")
186 private
void initComponents() {
188 jSplitPane1 =
new javax.swing.JSplitPane();
189 leftPane =
new javax.swing.JScrollPane();
190 listsTable =
new javax.swing.JTable();
191 rightPane =
new javax.swing.JScrollPane();
192 keywordsTable =
new javax.swing.JTable();
193 manageListsButton =
new javax.swing.JButton();
194 searchAddButton =
new javax.swing.JButton();
195 ingestIndexLabel =
new javax.swing.JLabel();
197 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
199 jSplitPane1.setFont(leftPane.getFont());
201 leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
202 leftPane.setMinimumSize(
new java.awt.Dimension(150, 23));
204 listsTable.setBackground(
new java.awt.Color(240, 240, 240));
205 listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
206 listsTable.setModel(listsTableModel);
207 listsTable.setShowHorizontalLines(
false);
208 listsTable.setShowVerticalLines(
false);
209 listsTable.getTableHeader().setReorderingAllowed(
false);
210 leftPane.setViewportView(listsTable);
212 jSplitPane1.setLeftComponent(leftPane);
214 rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
216 keywordsTable.setBackground(
new java.awt.Color(240, 240, 240));
217 keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
218 keywordsTable.setModel(keywordsTableModel);
219 keywordsTable.setGridColor(
new java.awt.Color(153, 153, 153));
220 rightPane.setViewportView(keywordsTable);
222 jSplitPane1.setRightComponent(rightPane);
224 manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
225 manageListsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.text"));
226 manageListsButton.setToolTipText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.manageListsButton.toolTipText"));
227 manageListsButton.addActionListener(
new java.awt.event.ActionListener() {
228 public void actionPerformed(java.awt.event.ActionEvent evt) {
229 manageListsButtonActionPerformed(evt);
233 searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
234 searchAddButton.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.searchAddButton.text"));
235 searchAddButton.addActionListener(
new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 searchAddButtonActionPerformed(evt);
241 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
242 ingestIndexLabel.setText(
org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class,
"KeywordSearchListsViewerPanel.ingestIndexLabel.text"));
244 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
245 this.setLayout(layout);
246 layout.setHorizontalGroup(
247 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
249 .addGroup(layout.createSequentialGroup()
251 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
253 .addComponent(searchAddButton)
254 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 220, Short.MAX_VALUE)
255 .addComponent(manageListsButton))
256 .addGroup(layout.createSequentialGroup()
257 .addComponent(ingestIndexLabel)
258 .addGap(0, 317, Short.MAX_VALUE)))
261 layout.setVerticalGroup(
262 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addGroup(layout.createSequentialGroup()
264 .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
265 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
266 .addComponent(ingestIndexLabel)
267 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
268 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
269 .addComponent(manageListsButton)
270 .addComponent(searchAddButton))
275 private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {
276 SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
279 private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {
284 private javax.swing.JLabel ingestIndexLabel;
285 private javax.swing.JSplitPane jSplitPane1;
286 private javax.swing.JTable keywordsTable;
287 private javax.swing.JScrollPane leftPane;
288 private javax.swing.JTable listsTable;
289 private javax.swing.JButton manageListsButton;
290 private javax.swing.JScrollPane rightPane;
291 private javax.swing.JButton searchAddButton;
294 private void searchAction(ActionEvent e) {
295 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
305 List<KeywordList> getKeywordLists() {
306 return listsTableModel.getSelectedListsL();
309 void addSearchButtonActionListener(ActionListener al) {
310 searchAddButton.addActionListener(al);
316 private final XmlKeywordSearchList
listsHandle = XmlKeywordSearchList.getCurrent();
317 private final List<ListTableEntry>
listData =
new ArrayList<>();
326 return listData.size();
334 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.selectedColLbl");
337 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
350 Iterator<ListTableEntry> it = listData.iterator();
351 for (
int i = 0; i <= rowIndex; ++i) {
355 switch (columnIndex) {
357 ret = (Object) entry.selected;
360 ret = (Object) entry.name;
371 return (columnIndex == 0 && !ingestRunning);
375 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
376 if (columnIndex == 0) {
378 Iterator<ListTableEntry> it = listData.iterator();
379 for (
int i = 0; i <= rowIndex; i++) {
383 entry.selected = (Boolean) aValue;
397 List<String> getAllLists() {
398 List<String> ret =
new ArrayList<>();
399 for (ListTableEntry e : listData) {
405 KeywordList getListAt(
int rowIndex) {
406 return listsHandle.getList((String)
getValueAt(rowIndex, 1));
409 List<String> getSelectedLists() {
410 List<String> ret =
new ArrayList<>();
411 for (ListTableEntry e : listData) {
419 List<KeywordList> getSelectedListsL() {
420 List<KeywordList> ret =
new ArrayList<>();
421 for (String s : getSelectedLists()) {
422 ret.add(listsHandle.getList(s));
427 boolean listExists(String list) {
428 List<String> all = getAllLists();
429 return all.contains(list);
436 fireTableDataChanged();
442 if (!listExists(list.getName())) {
455 this.name = list.getName();
457 this.selected = list.getUseForIngest();
459 this.selected =
false;
465 return this.name.compareTo(e.name);
472 List<KeywordTableEntry> listData =
new ArrayList<>();
476 return listData.size();
489 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.nameColLbl");
492 ret = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
505 Iterator<KeywordTableEntry> it = listData.iterator();
506 for (
int i = 0; i <= rowIndex; ++i) {
510 switch (columnIndex) {
512 ret = (Object) entry.name;
515 ret = (Object) entry.keywordType;
530 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
540 for (Keyword k : list.getKeywords()) {
541 listData.add(
new KeywordTableEntry(k));
543 fireTableDataChanged();
548 fireTableDataChanged();
558 this.name = keyword.getSearchTerm();
559 this.keywordType = keyword.getSearchTermType();
564 return this.name.compareTo(e.name);
573 JTable table, Object value,
574 boolean isSelected,
boolean hasFocus,
575 int row,
int column) {
577 this.setHorizontalAlignment(JCheckBox.CENTER);
578 this.setVerticalAlignment(JCheckBox.CENTER);
580 setEnabled(!ingestRunning);
582 boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
583 setSelected(selected);
586 setBackground(listsTable.getSelectionBackground());
588 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)
final XmlKeywordSearchList listsHandle
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)
final List< ListTableEntry > listData