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;
113 ingestWarningLabel.setVisible(isIngestRunning);
115 boolean canEditList = isListSelected && !isIngestRunning;
116 ingestMessagesCheckbox.setEnabled(canEditList);
117 ingestMessagesCheckbox.setSelected(currentKeywordList != null && currentKeywordList.getIngestMessages());
120 boolean canAddWord = canEditList && !currentKeywordList.isEditable();
121 newKeywordsButton.setEnabled(canAddWord);
124 if ((currentKeywordList == null) || (currentKeywordList.getKeywords().isEmpty())) {
125 deleteWordButton.setEnabled(
false);
126 editWordButton.setEnabled(
false);
130 @NbBundle.Messages({
"GlobalEditListPanel.editKeyword.title=Edit Keyword",
131 "GlobalEditListPanel.warning.title=Warning",
132 "GlobalEditListPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
140 private boolean addKeywordsAction(String existingKeywords,
boolean isLiteral,
boolean isWholeWord) {
141 String keywordsToRedisplay = existingKeywords;
142 AddKeywordsDialog dialog =
new AddKeywordsDialog();
148 if (!existingKeywords.isEmpty()) {
149 dialog.setTitle(NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editKeyword.title"));
151 while (badCount > 0) {
152 dialog.setInitialKeywordList(keywordsToRedisplay, isLiteral, isWholeWord);
158 keywordsToRedisplay =
"";
159 boolean displayedBoundaryWarning =
false;
161 if (!dialog.getKeywords().isEmpty()) {
163 for (String newWord : dialog.getKeywords()) {
164 if (newWord.isEmpty()) {
168 final Keyword keyword =
new Keyword(newWord, !dialog.isKeywordRegex(), dialog.isKeywordExact(), currentKeywordList.getName(), newWord);
169 if (currentKeywordList.hasKeyword(keyword)) {
175 if (( ! displayedBoundaryWarning) && dialog.isKeywordRegex()) {
176 if(newWord.startsWith(
"^") ||
177 (newWord.endsWith(
"$") && ! newWord.endsWith(
"\\$"))) {
179 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.title"),
180 NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.text"),
181 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
183 displayedBoundaryWarning =
true;
188 boolean valid =
true;
190 Pattern.compile(newWord);
191 }
catch (PatternSyntaxException ex1) {
193 }
catch (IllegalArgumentException ex2) {
199 keywordsToRedisplay += newWord +
"\n";
205 tableModel.addKeyword(keyword);
208 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
209 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
211 if ((badCount > 0) || (dupeCount > 0)) {
217 KeywordSearchUtil.DIALOG_MESSAGE_TYPE level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO;
220 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAddedPlural.text", goodCount) +
"\n";
222 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAdded.text", goodCount) +
"\n";
227 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkippedPlural.text", dupeCount) +
"\n";
229 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkipped.text", dupeCount) +
"\n";
231 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN;
235 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrorsPlural.text", badCount) +
"\n";
237 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrors.text", badCount) +
"\n";
239 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR;
241 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.addKeywordResults.text"),
246 setFocusOnKeywordTextBox();
248 return (goodCount >= 1 && dupeCount == 0);
257 private void deleteKeywordAction(
int[] selectedKeywords) {
258 tableModel.deleteSelected(selectedKeywords);
259 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
268 @SuppressWarnings(
"unchecked")
270 private
void initComponents() {
272 listEditorPanel =
new javax.swing.JPanel();
273 jScrollPane1 =
new javax.swing.JScrollPane();
274 keywordTable =
new javax.swing.JTable();
275 ingestMessagesCheckbox =
new javax.swing.JCheckBox();
276 keywordsLabel =
new javax.swing.JLabel();
277 newKeywordsButton =
new javax.swing.JButton();
278 deleteWordButton =
new javax.swing.JButton();
279 editWordButton =
new javax.swing.JButton();
280 ingestWarningLabel =
new javax.swing.JLabel();
282 setMinimumSize(
new java.awt.Dimension(0, 0));
284 listEditorPanel.setMinimumSize(
new java.awt.Dimension(0, 0));
286 jScrollPane1.setPreferredSize(
new java.awt.Dimension(340, 300));
288 keywordTable.setModel(tableModel);
289 keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
290 keywordTable.setGridColor(
new java.awt.Color(153, 153, 153));
291 keywordTable.setMaximumSize(
new java.awt.Dimension(30000, 30000));
292 keywordTable.getTableHeader().setReorderingAllowed(
false);
293 jScrollPane1.setViewportView(keywordTable);
295 ingestMessagesCheckbox.setSelected(
true);
296 ingestMessagesCheckbox.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.text"));
297 ingestMessagesCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.toolTipText"));
298 ingestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
299 public void actionPerformed(java.awt.event.ActionEvent evt) {
300 ingestMessagesCheckboxActionPerformed(evt);
304 keywordsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.keywordsLabel.text"));
306 newKeywordsButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/add16.png")));
307 newKeywordsButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.newKeywordsButton.text"));
308 newKeywordsButton.addActionListener(
new java.awt.event.ActionListener() {
309 public void actionPerformed(java.awt.event.ActionEvent evt) {
310 newKeywordsButtonActionPerformed(evt);
314 deleteWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/delete16.png")));
315 deleteWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.deleteWordButton.text"));
316 deleteWordButton.addActionListener(
new java.awt.event.ActionListener() {
317 public void actionPerformed(java.awt.event.ActionEvent evt) {
318 deleteWordButtonActionPerformed(evt);
322 editWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/edit16.png")));
323 editWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editWordButton.text"));
324 editWordButton.addActionListener(
new java.awt.event.ActionListener() {
325 public void actionPerformed(java.awt.event.ActionEvent evt) {
326 editWordButtonActionPerformed(evt);
330 ingestWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
331 ingestWarningLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.ingestWarningLabel.text"));
333 javax.swing.GroupLayout listEditorPanelLayout =
new javax.swing.GroupLayout(listEditorPanel);
334 listEditorPanel.setLayout(listEditorPanelLayout);
335 listEditorPanelLayout.setHorizontalGroup(
336 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337 .addGroup(listEditorPanelLayout.createSequentialGroup()
339 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
340 .addGroup(listEditorPanelLayout.createSequentialGroup()
341 .addComponent(keywordsLabel)
342 .addGap(0, 0, Short.MAX_VALUE))
343 .addGroup(listEditorPanelLayout.createSequentialGroup()
345 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
347 .addGroup(listEditorPanelLayout.createSequentialGroup()
348 .addComponent(newKeywordsButton)
350 .addComponent(editWordButton)
352 .addComponent(deleteWordButton)
353 .addGap(0, 0, Short.MAX_VALUE))
354 .addGroup(listEditorPanelLayout.createSequentialGroup()
355 .addComponent(ingestMessagesCheckbox)
356 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
357 .addComponent(ingestWarningLabel)))))
361 listEditorPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deleteWordButton, editWordButton, newKeywordsButton});
363 listEditorPanelLayout.setVerticalGroup(
364 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listEditorPanelLayout.createSequentialGroup()
367 .addComponent(keywordsLabel)
368 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
369 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
370 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
372 .addComponent(deleteWordButton)
373 .addComponent(newKeywordsButton)
374 .addComponent(editWordButton))
375 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
376 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
377 .addComponent(ingestMessagesCheckbox)
378 .addComponent(ingestWarningLabel))
382 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
383 this.setLayout(layout);
384 layout.setHorizontalGroup(
385 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
386 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
388 layout.setVerticalGroup(
389 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
390 .addGroup(layout.createSequentialGroup()
391 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
396 private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
397 if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.removeKwMsg"),
398 NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.deleteWordButtonActionPerformed.delConfirmMsg"),
399 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
400 deleteKeywordAction(keywordTable.getSelectedRows());
401 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
405 private void ingestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
406 currentKeywordList.setIngestMessages(ingestMessagesCheckbox.isSelected());
407 XmlKeywordSearchList updater = XmlKeywordSearchList.getCurrent();
408 updater.addList(currentKeywordList);
409 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
412 private void newKeywordsButtonActionPerformed(java.awt.event.ActionEvent evt) {
413 addKeywordsAction(
"",
true,
true);
416 private void editWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
417 int[] selectedKeywords = keywordTable.getSelectedRows();
418 if (selectedKeywords.length == 1) {
419 Keyword currentKeyword = currentKeywordList.getKeywords().get(selectedKeywords[0]);
420 if (addKeywordsAction(currentKeyword.getSearchTerm(), currentKeyword.searchTermIsLiteral(), currentKeyword.searchTermIsWholeWord())) {
421 deleteKeywordAction(selectedKeywords);
427 private javax.swing.JButton deleteWordButton;
428 private javax.swing.JButton editWordButton;
429 private javax.swing.JCheckBox ingestMessagesCheckbox;
430 private javax.swing.JLabel ingestWarningLabel;
431 private javax.swing.JScrollPane jScrollPane1;
432 private javax.swing.JTable keywordTable;
433 private javax.swing.JLabel keywordsLabel;
434 private javax.swing.JPanel listEditorPanel;
435 private javax.swing.JButton newKeywordsButton;
439 public void valueChanged(ListSelectionEvent e) {
441 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
442 currentKeywordList = null;
443 if (!listSelectionModel.isSelectionEmpty()) {
444 XmlKeywordSearchList loader = XmlKeywordSearchList.getCurrent();
445 if (listSelectionModel.getMinSelectionIndex() == listSelectionModel.getMaxSelectionIndex()) {
446 currentKeywordList = loader.getListsL(
false).get(listSelectionModel.getMinSelectionIndex());
454 public void store() {
463 KeywordList getCurrentKeywordList() {
464 return currentKeywordList;
467 void setCurrentKeywordList(KeywordList list) {
468 currentKeywordList = list;
480 return currentKeywordList == null ? 0 : currentKeywordList.getKeywords().size();
485 String colName = null;
489 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearchEditListPanel.kwColName");
492 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
503 if (currentKeywordList == null) {
506 Keyword word = currentKeywordList.getKeywords().get(rowIndex);
507 switch (columnIndex) {
512 ret = word.getSearchTermType();
515 logger.log(Level.SEVERE,
"Invalid table column index: {0}", columnIndex);
527 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
532 return getValueAt(0, c).getClass();
535 void addKeyword(
Keyword keyword) {
536 if (!currentKeywordList.hasKeyword(keyword)) {
537 currentKeywordList.getKeywords().add(keyword);
539 fireTableDataChanged();
543 fireTableDataChanged();
547 void deleteSelected(
int[] selected) {
548 List<Keyword> words = currentKeywordList.getKeywords();
549 Arrays.sort(selected);
550 for (
int arrayi = selected.length - 1; arrayi >= 0; arrayi--) {
551 words.remove(selected[arrayi]);
560 void setFocusOnKeywordTextBox() {
561 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)