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 class GlobalEditListPanel
extends javax.swing.JPanel implements ListSelectionListener, OptionsPanel {
46 private static final Logger logger = Logger.getLogger(GlobalEditListPanel.class.getName());
47 private static final long serialVersionUID = 1L;
48 private final KeywordTableModel tableModel;
49 private KeywordList currentKeywordList;
54 GlobalEditListPanel() {
55 tableModel =
new KeywordTableModel();
57 customizeComponents();
60 private void customizeComponents() {
61 newKeywordsButton.setToolTipText((NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.customizeComponents.addWordToolTip")));
62 deleteWordButton.setToolTipText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.customizeComponents.removeSelectedMsg"));
64 keywordTable.getParent().setBackground(keywordTable.getBackground());
65 final int width = jScrollPane1.getPreferredSize().width;
66 keywordTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
68 for (
int i = 0; i < keywordTable.getColumnCount(); i++) {
69 column = keywordTable.getColumnModel().getColumn(i);
71 column.setPreferredWidth(((
int) (width * 0.90)));
73 column.setPreferredWidth(((
int) (width * 0.10)));
76 keywordTable.setCellSelectionEnabled(
false);
77 keywordTable.setRowSelectionAllowed(
true);
79 final ListSelectionModel lsm = keywordTable.getSelectionModel();
80 lsm.addListSelectionListener(
new ListSelectionListener() {
82 public void valueChanged(ListSelectionEvent e) {
83 boolean canDelete = !(lsm.isSelectionEmpty() || currentKeywordList.isEditable() || IngestManager.getInstance().isIngestRunning());
84 boolean canEdit = canDelete && (lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex());
85 deleteWordButton.setEnabled(canDelete);
86 editWordButton.setEnabled(canEdit);
92 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
94 public void propertyChange(PropertyChangeEvent evt) {
95 Object source = evt.getSource();
96 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
97 EventQueue.invokeLater(() -> {
108 void setButtonStates() {
109 boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
110 boolean isListSelected = currentKeywordList != null;
113 boolean canEditList = isListSelected && !isIngestRunning;
114 ingestMessagesCheckbox.setEnabled(canEditList);
115 ingestMessagesCheckbox.setSelected(currentKeywordList != null && currentKeywordList.getIngestMessages());
118 boolean canAddWord = canEditList && !currentKeywordList.isEditable();
119 newKeywordsButton.setEnabled(canAddWord);
122 if ((currentKeywordList == null) || (currentKeywordList.getKeywords().isEmpty())) {
123 deleteWordButton.setEnabled(
false);
124 editWordButton.setEnabled(
false);
128 @NbBundle.Messages({
"GlobalEditListPanel.editKeyword.title=Edit Keyword",
129 "GlobalEditListPanel.warning.title=Warning",
130 "GlobalEditListPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
138 private boolean addKeywordsAction(String existingKeywords,
boolean isLiteral,
boolean isWholeWord) {
139 String keywordsToRedisplay = existingKeywords;
140 AddKeywordsDialog dialog =
new AddKeywordsDialog();
146 if (!existingKeywords.isEmpty()) {
147 dialog.setTitle(NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editKeyword.title"));
149 while (badCount > 0) {
150 dialog.setInitialKeywordList(keywordsToRedisplay, isLiteral, isWholeWord);
156 keywordsToRedisplay =
"";
157 boolean displayedBoundaryWarning =
false;
159 if (!dialog.getKeywords().isEmpty()) {
161 for (String newWord : dialog.getKeywords()) {
162 if (newWord.isEmpty()) {
166 final Keyword keyword =
new Keyword(newWord, !dialog.isKeywordRegex(), dialog.isKeywordExact(), currentKeywordList.getName(), newWord);
167 if (currentKeywordList.hasKeyword(keyword)) {
173 if (( ! displayedBoundaryWarning) && dialog.isKeywordRegex()) {
174 if(newWord.startsWith(
"^") ||
175 (newWord.endsWith(
"$") && ! newWord.endsWith(
"\\$"))) {
177 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.title"),
178 NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.warning.text"),
179 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
181 displayedBoundaryWarning =
true;
186 boolean valid =
true;
188 Pattern.compile(newWord);
189 }
catch (PatternSyntaxException ex1) {
191 }
catch (IllegalArgumentException ex2) {
197 keywordsToRedisplay += newWord +
"\n";
203 tableModel.addKeyword(keyword);
206 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
207 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
209 if ((badCount > 0) || (dupeCount > 0)) {
215 KeywordSearchUtil.DIALOG_MESSAGE_TYPE level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO;
218 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAddedPlural.text", goodCount) +
"\n";
220 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordsAdded.text", goodCount) +
"\n";
225 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkippedPlural.text", dupeCount) +
"\n";
227 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordDupesSkipped.text", dupeCount) +
"\n";
229 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN;
233 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrorsPlural.text", badCount) +
"\n";
235 summary += NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.keywordErrors.text", badCount) +
"\n";
237 level = KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR;
239 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"GlobalEditListPanel.addKeywordResults.text"),
244 setFocusOnKeywordTextBox();
246 return (goodCount >= 1 && dupeCount == 0);
255 private void deleteKeywordAction(
int[] selectedKeywords) {
256 tableModel.deleteSelected(selectedKeywords);
257 XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
266 @SuppressWarnings(
"unchecked")
268 private
void initComponents() {
270 listEditorPanel =
new javax.swing.JPanel();
271 jScrollPane1 =
new javax.swing.JScrollPane();
272 keywordTable =
new javax.swing.JTable();
273 ingestMessagesCheckbox =
new javax.swing.JCheckBox();
274 keywordsLabel =
new javax.swing.JLabel();
275 newKeywordsButton =
new javax.swing.JButton();
276 deleteWordButton =
new javax.swing.JButton();
277 editWordButton =
new javax.swing.JButton();
279 setMinimumSize(
new java.awt.Dimension(0, 0));
281 listEditorPanel.setMinimumSize(
new java.awt.Dimension(0, 0));
283 jScrollPane1.setPreferredSize(
new java.awt.Dimension(340, 300));
285 keywordTable.setModel(tableModel);
286 keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
287 keywordTable.setGridColor(
new java.awt.Color(153, 153, 153));
288 keywordTable.setMaximumSize(
new java.awt.Dimension(30000, 30000));
289 keywordTable.getTableHeader().setReorderingAllowed(
false);
290 jScrollPane1.setViewportView(keywordTable);
292 ingestMessagesCheckbox.setSelected(
true);
293 ingestMessagesCheckbox.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.text"));
294 ingestMessagesCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.ingestMessagesCheckbox.toolTipText"));
295 ingestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
296 public void actionPerformed(java.awt.event.ActionEvent evt) {
297 ingestMessagesCheckboxActionPerformed(evt);
301 keywordsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.keywordsLabel.text"));
303 newKeywordsButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/add16.png")));
304 newKeywordsButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.newKeywordsButton.text"));
305 newKeywordsButton.addActionListener(
new java.awt.event.ActionListener() {
306 public void actionPerformed(java.awt.event.ActionEvent evt) {
307 newKeywordsButtonActionPerformed(evt);
311 deleteWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/delete16.png")));
312 deleteWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"KeywordSearchEditListPanel.deleteWordButton.text"));
313 deleteWordButton.addActionListener(
new java.awt.event.ActionListener() {
314 public void actionPerformed(java.awt.event.ActionEvent evt) {
315 deleteWordButtonActionPerformed(evt);
319 editWordButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/edit16.png")));
320 editWordButton.setText(
org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class,
"GlobalEditListPanel.editWordButton.text"));
321 editWordButton.addActionListener(
new java.awt.event.ActionListener() {
322 public void actionPerformed(java.awt.event.ActionEvent evt) {
323 editWordButtonActionPerformed(evt);
327 javax.swing.GroupLayout listEditorPanelLayout =
new javax.swing.GroupLayout(listEditorPanel);
328 listEditorPanel.setLayout(listEditorPanelLayout);
329 listEditorPanelLayout.setHorizontalGroup(
330 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331 .addGroup(listEditorPanelLayout.createSequentialGroup()
333 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334 .addGroup(listEditorPanelLayout.createSequentialGroup()
335 .addComponent(keywordsLabel)
336 .addGap(0, 0, Short.MAX_VALUE))
337 .addGroup(listEditorPanelLayout.createSequentialGroup()
339 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
340 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
341 .addGroup(listEditorPanelLayout.createSequentialGroup()
342 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
343 .addComponent(ingestMessagesCheckbox)
344 .addGroup(listEditorPanelLayout.createSequentialGroup()
345 .addComponent(newKeywordsButton)
347 .addComponent(editWordButton)
349 .addComponent(deleteWordButton)))
350 .addGap(0, 0, Short.MAX_VALUE)))))
354 listEditorPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deleteWordButton, editWordButton, newKeywordsButton});
356 listEditorPanelLayout.setVerticalGroup(
357 listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
358 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listEditorPanelLayout.createSequentialGroup()
360 .addComponent(keywordsLabel)
361 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
362 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
363 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
364 .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
365 .addComponent(deleteWordButton)
366 .addComponent(newKeywordsButton)
367 .addComponent(editWordButton))
368 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
369 .addComponent(ingestMessagesCheckbox)
373 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
374 this.setLayout(layout);
375 layout.setHorizontalGroup(
376 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
377 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
379 layout.setVerticalGroup(
380 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
381 .addGroup(layout.createSequentialGroup()
382 .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
387 private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
388 if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.removeKwMsg"),
389 NbBundle.getMessage(
this.getClass(),
"KeywordSearchEditListPanel.deleteWordButtonActionPerformed.delConfirmMsg"),
390 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
391 deleteKeywordAction(keywordTable.getSelectedRows());
392 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
396 private void ingestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
397 currentKeywordList.setIngestMessages(ingestMessagesCheckbox.isSelected());
398 XmlKeywordSearchList updater = XmlKeywordSearchList.getCurrent();
399 updater.addList(currentKeywordList);
400 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
403 private void newKeywordsButtonActionPerformed(java.awt.event.ActionEvent evt) {
404 addKeywordsAction(
"",
true,
true);
407 private void editWordButtonActionPerformed(java.awt.event.ActionEvent evt) {
408 int[] selectedKeywords = keywordTable.getSelectedRows();
409 if (selectedKeywords.length == 1) {
410 Keyword currentKeyword = currentKeywordList.getKeywords().get(selectedKeywords[0]);
411 if (addKeywordsAction(currentKeyword.getSearchTerm(), currentKeyword.searchTermIsLiteral(), currentKeyword.searchTermIsWholeWord())) {
412 deleteKeywordAction(selectedKeywords);
418 private javax.swing.JButton deleteWordButton;
419 private javax.swing.JButton editWordButton;
420 private javax.swing.JCheckBox ingestMessagesCheckbox;
421 private javax.swing.JScrollPane jScrollPane1;
422 private javax.swing.JTable keywordTable;
423 private javax.swing.JLabel keywordsLabel;
424 private javax.swing.JPanel listEditorPanel;
425 private javax.swing.JButton newKeywordsButton;
429 public void valueChanged(ListSelectionEvent e) {
431 ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
432 currentKeywordList = null;
433 if (!listSelectionModel.isSelectionEmpty()) {
434 XmlKeywordSearchList loader = XmlKeywordSearchList.getCurrent();
435 if (listSelectionModel.getMinSelectionIndex() == listSelectionModel.getMaxSelectionIndex()) {
436 currentKeywordList = loader.getListsL(
false).get(listSelectionModel.getMinSelectionIndex());
444 public void store() {
453 KeywordList getCurrentKeywordList() {
454 return currentKeywordList;
457 void setCurrentKeywordList(KeywordList list) {
458 currentKeywordList = list;
470 return currentKeywordList == null ? 0 : currentKeywordList.getKeywords().size();
475 String colName = null;
479 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearchEditListPanel.kwColName");
482 colName = NbBundle.getMessage(this.getClass(),
"KeywordSearch.typeColLbl");
493 if (currentKeywordList == null) {
496 Keyword word = currentKeywordList.getKeywords().get(rowIndex);
497 switch (columnIndex) {
499 ret = word.getSearchTerm();
502 ret = word.getSearchTermType();
505 logger.log(Level.SEVERE,
"Invalid table column index: {0}", columnIndex);
517 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
525 void addKeyword(Keyword keyword) {
526 if (!currentKeywordList.hasKeyword(keyword)) {
527 currentKeywordList.getKeywords().add(keyword);
529 fireTableDataChanged();
533 fireTableDataChanged();
537 void deleteSelected(
int[] selected) {
538 List<Keyword> words = currentKeywordList.getKeywords();
539 Arrays.sort(selected);
540 for (
int arrayi = selected.length - 1; arrayi >= 0; arrayi--) {
541 words.remove(selected[arrayi]);
550 void setFocusOnKeywordTextBox() {
551 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)