19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.EventQueue;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.logging.Level;
27 import java.util.regex.Pattern;
28 import java.util.regex.PatternSyntaxException;
29 import javax.swing.JTable;
30 import javax.swing.ListSelectionModel;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
33 import javax.swing.table.AbstractTableModel;
34 import javax.swing.table.TableColumn;
35 import org.netbeans.spi.options.OptionsPanelController;
36 import org.openide.util.NbBundle;
44 @SuppressWarnings(
"PMD.SingularField")
45 class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionListener, OptionsPanel {
47 private static final Logger logger = Logger.getLogger(GlobalEditListPanel.class.getName());
48 private static final long serialVersionUID = 1L;
49 private final KeywordTableModel tableModel;
50 private KeywordList currentKeywordList;
55 GlobalEditListPanel() {
56 tableModel =
new KeywordTableModel();
58 customizeComponents();
61 private void customizeComponents() {
62 newKeywordsButton.setToolTipText((NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.customizeComponents.addWordToolTip")));
63 deleteWordButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.customizeComponents.removeSelectedMsg"));
65 keywordTable.getParent().setBackground(keywordTable.getBackground());
66 final int width = jScrollPane1.getPreferredSize().width;
67 keywordTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
69 for (
int i = 0; i < keywordTable.getColumnCount(); i++) {
70 column = keywordTable.getColumnModel().getColumn(i);
72 column.setPreferredWidth(((
int) (width * 0.90)));
74 column.setPreferredWidth(((
int) (width * 0.10)));
77 keywordTable.setCellSelectionEnabled(
false);
78 keywordTable.setRowSelectionAllowed(
true);
80 final ListSelectionModel lsm = keywordTable.getSelectionModel();
81 lsm.addListSelectionListener(
new ListSelectionListener() {
83 public void valueChanged(ListSelectionEvent e) {
84 boolean canDelete = !(lsm.isSelectionEmpty() || currentKeywordList.isEditable() || IngestManager.getInstance().isIngestRunning());
85 boolean canEdit = canDelete && (lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex());
86 deleteWordButton.setEnabled(canDelete);
87 editWordButton.setEnabled(canEdit);
93 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
95 public void propertyChange(PropertyChangeEvent evt) {
96 Object source = evt.getSource();
97 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
98 EventQueue.invokeLater(() -> {
109 void setButtonStates() {
110 boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
111 boolean isListSelected = currentKeywordList != null;
114 boolean canEditList = isListSelected && !isIngestRunning;
115 ingestMessagesCheckbox.setEnabled(canEditList);
116 ingestMessagesCheckbox.setSelected(currentKeywordList != null && currentKeywordList.getIngestMessages());
119 boolean canAddWord = canEditList && !currentKeywordList.isEditable();
120 newKeywordsButton.setEnabled(canAddWord);
123 if ((currentKeywordList == null) || (currentKeywordList.getKeywords().isEmpty())) {
124 deleteWordButton.setEnabled(
false);
125 editWordButton.setEnabled(
false);
129 @NbBundle.Messages({
"GlobalEditListPanel.editKeyword.title=Edit Keyword",
130 "GlobalEditListPanel.warning.title=Warning",
131 "GlobalEditListPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
139 private boolean addKeywordsAction(String existingKeywords,
boolean isLiteral,
boolean isWholeWord) {
140 String keywordsToRedisplay = existingKeywords;
141 AddKeywordsDialog dialog =
new AddKeywordsDialog();
147 if (!existingKeywords.isEmpty()) {
148 dialog.setTitle(NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editKeyword.title"));
150 while (badCount > 0) {
151 dialog.setInitialKeywordList(keywordsToRedisplay, isLiteral, isWholeWord);
157 keywordsToRedisplay =
"";
158 boolean displayedBoundaryWarning =
false;
160 if (!dialog.getKeywords().isEmpty()) {
162 for (String newWord : dialog.getKeywords()) {
163 if (newWord.isEmpty()) {
167 final Keyword keyword =
new Keyword(newWord, !dialog.isKeywordRegex(), dialog.isKeywordExact(), currentKeywordList.getName(), newWord);
168 if (currentKeywordList.hasKeyword(keyword)) {
174 if (( ! displayedBoundaryWarning) && dialog.isKeywordRegex()) {
175 if(newWord.startsWith(
"^") ||
176 (newWord.endsWith(
"$") && ! newWord.endsWith(
"\\$"))) {
178 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.title"),
179 NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.text"),
180 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
182 displayedBoundaryWarning =
true;
187 boolean valid =
true;
189 Pattern.compile(newWord);
190 }
catch (PatternSyntaxException ex1) {
192 }
catch (IllegalArgumentException ex2) {
198 keywordsToRedisplay += newWord +
"\n";
204 tableModel.addKeyword(keyword);
207 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
208 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
210 if ((badCount > 0) || (dupeCount > 0)) {
216 KeywordSearchUtil.DIALOG_MESSAGE_TYPE level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO;
219 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAddedPlural.text", goodCount) +
"\n";
221 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAdded.text", goodCount) +
"\n";
226 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkippedPlural.text", dupeCount) +
"\n";
228 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkipped.text", dupeCount) +
"\n";
230 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN;
234 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrorsPlural.text", badCount) +
"\n";
236 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrors.text", badCount) +
"\n";
238 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR;
240 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.addKeywordResults.text"),
245 setFocusOnKeywordTextBox();
247 return (goodCount >= 1 && dupeCount == 0);
256 private void deleteKeywordAction(
int[] selectedKeywords) {
257 tableModel.deleteSelected(selectedKeywords);
258 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
267 @SuppressWarnings(
"unchecked")
269 private
void initComponents() {
271 listEditorPanel =
new javax.swing.JPanel();
272 jScrollPane1 =
new javax.swing.JScrollPane();
273 keywordTable =
new javax.swing.JTable();
274 ingestMessagesCheckbox =
new javax.swing.JCheckBox();
275 keywordsLabel =
new javax.swing.JLabel();
276 newKeywordsButton =
new javax.swing.JButton();
277 deleteWordButton =
new javax.swing.JButton();
278 editWordButton =
new javax.swing.JButton();
280 setMinimumSize(
new java.awt.Dimension(0, 0));
282 listEditorPanel.setMinimumSize(
new java.awt.Dimension(0, 0));
284 jScrollPane1.setPreferredSize(
new java.awt.Dimension(340, 300));
286 keywordTable.setModel(tableModel);
287 keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
288 keywordTable.setGridColor(
new java.awt.Color(153, 153, 153));
289 keywordTable.setMaximumSize(
new java.awt.Dimension(30000, 30000));
290 keywordTable.getTableHeader().setReorderingAllowed(
false);
291 jScrollPane1.setViewportView(keywordTable);
293 ingestMessagesCheckbox.setSelected(
true);
294 ingestMessagesCheckbox.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.text"));
295 ingestMessagesCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.toolTipText"));
296 ingestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
297 public void actionPerformed(java.awt.event.ActionEvent evt) {
298 ingestMessagesCheckboxActionPerformed(evt);
302 keywordsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.keywordsLabel.text"));
304 newKeywordsButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/add16.png")));
305 newKeywordsButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.newKeywordsButton.text"));
306 newKeywordsButton.addActionListener(
new java.awt.event.ActionListener() {
307 public void actionPerformed(java.awt.event.ActionEvent evt) {
308 newKeywordsButtonActionPerformed(evt);
312 deleteWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/delete16.png")));
313 deleteWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.deleteWordButton.text"));
314 deleteWordButton.addActionListener(
new java.awt.event.ActionListener() {
315 public void actionPerformed(java.awt.event.ActionEvent evt) {
316 deleteWordButtonActionPerformed(evt);
320 editWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/edit16.png")));
321 editWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editWordButton.text"));
322 editWordButton.addActionListener(
new java.awt.event.ActionListener() {
323 public void actionPerformed(java.awt.event.ActionEvent evt) {
324 editWordButtonActionPerformed(evt);
328 javax.swing.GroupLayout listEditorPanelLayout =
new javax.swing.GroupLayout(listEditorPanel);
329 listEditorPanel.setLayout(listEditorPanelLayout);
330 listEditorPanelLayout.setHorizontalGroup(
331 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
332 .addGroup(listEditorPanelLayout.createSequentialGroup()
334 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
335 .addGroup(listEditorPanelLayout.createSequentialGroup()
336 .addComponent(keywordsLabel)
337 .addGap(0, 0, Short.MAX_VALUE))
338 .addGroup(listEditorPanelLayout.createSequentialGroup()
340 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
341 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
342 .addGroup(listEditorPanelLayout.createSequentialGroup()
343 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
344 .addComponent(ingestMessagesCheckbox)
345 .addGroup(listEditorPanelLayout.createSequentialGroup()
346 .addComponent(newKeywordsButton)
348 .addComponent(editWordButton)
350 .addComponent(deleteWordButton)))
351 .addGap(0, 0, Short.MAX_VALUE)))))
355 listEditorPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deleteWordButton, editWordButton, newKeywordsButton});
357 listEditorPanelLayout.setVerticalGroup(
358 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
359 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listEditorPanelLayout.createSequentialGroup()
361 .addComponent(keywordsLabel)
362 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
363 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
364 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
365 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
366 .addComponent(deleteWordButton)
367 .addComponent(newKeywordsButton)
368 .addComponent(editWordButton))
369 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
370 .addComponent(ingestMessagesCheckbox)
374 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
375 this.setLayout(layout);
376 layout.setHorizontalGroup(
377 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
378 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
380 layout.setVerticalGroup(
381 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382 .addGroup(layout.createSequentialGroup()
383 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
388 private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
389 if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.removeKwMsg"),
390 NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.deleteWordButtonActionPerformed.delConfirmMsg"),
391 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
392 deleteKeywordAction(keywordTable.getSelectedRows());
393 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
397 private void ingestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
398 currentKeywordList.setIngestMessages(ingestMessagesCheckbox.isSelected());
399 XmlKeywordSearchList updater = XmlKeywordSearchList.getCurrent();
400 updater.addList(currentKeywordList);
401 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
404 private void newKeywordsButtonActionPerformed(java.awt.event.ActionEvent evt) {
405 addKeywordsAction(
"",
true,
true);
408 private void editWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
409 int[] selectedKeywords = keywordTable.getSelectedRows();
410 if (selectedKeywords.length == 1) {
411 Keyword currentKeyword = currentKeywordList.getKeywords().get(selectedKeywords[0]);
412 if (addKeywordsAction(currentKeyword.getSearchTerm(), currentKeyword.searchTermIsLiteral(), currentKeyword.searchTermIsWholeWord())) {
413 deleteKeywordAction(selectedKeywords);
419 private javax.swing.JButton deleteWordButton;
420 private javax.swing.JButton editWordButton;
421 private javax.swing.JCheckBox ingestMessagesCheckbox;
422 private javax.swing.JScrollPane jScrollPane1;
423 private javax.swing.JTable keywordTable;
424 private javax.swing.JLabel keywordsLabel;
425 private javax.swing.JPanel listEditorPanel;
426 private javax.swing.JButton newKeywordsButton;
430 public void valueChanged(ListSelectionEvent e) {
432 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
433 currentKeywordList = null;
434 if (!listSelectionModel.isSelectionEmpty()) {
435 XmlKeywordSearchList loader = XmlKeywordSearchList.getCurrent();
436 if (listSelectionModel.getMinSelectionIndex() == listSelectionModel.getMaxSelectionIndex()) {
437 currentKeywordList = loader.getListsL(
false).get(listSelectionModel.getMinSelectionIndex());
445 public void store() {
454 KeywordList getCurrentKeywordList() {
455 return currentKeywordList;
458 void setCurrentKeywordList(KeywordList list) {
459 currentKeywordList = list;
471 return currentKeywordList == null ? 0 : currentKeywordList.getKeywords().size();
476 String colName = null;
480 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearchEditListPanel.kwColName");
483 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
494 if (currentKeywordList == null) {
497 Keyword word = currentKeywordList.getKeywords().get(rowIndex);
498 switch (columnIndex) {
500 ret = word.getSearchTerm();
503 ret = word.getSearchTermType();
506 logger.log(Level.SEVERE,
"Invalid table column index: {0}", columnIndex);
518 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
523 return getValueAt(0, c).getClass();
526 void addKeyword(Keyword keyword) {
527 if (!currentKeywordList.hasKeyword(keyword)) {
528 currentKeywordList.getKeywords().add(keyword);
530 fireTableDataChanged();
534 fireTableDataChanged();
538 void deleteSelected(
int[] selected) {
539 List<Keyword> words = currentKeywordList.getKeywords();
540 Arrays.sort(selected);
541 for (
int arrayi = selected.length - 1; arrayi >= 0; arrayi--) {
542 words.remove(selected[arrayi]);
551 void setFocusOnKeywordTextBox() {
552 newKeywordsButton.requestFocus();
boolean isCellEditable(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)
String getColumnName(int column)
Class<?> getColumnClass(int c)
Object getValueAt(int rowIndex, int columnIndex)