19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.event.KeyEvent;
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.openide.util.NbBundle;
27 import javax.swing.JFileChooser;
28 import javax.swing.JOptionPane;
29 import javax.swing.event.ListSelectionListener;
30 import javax.swing.filechooser.FileNameExtensionFilter;
31 import javax.swing.table.AbstractTableModel;
37 class GlobalListsManagementPanel
extends javax.swing.JPanel implements OptionsPanel {
39 private Logger logger = Logger.getLogger(GlobalListsManagementPanel.class.getName());
40 private KeywordListTableModel tableModel;
42 GlobalListsManagementPanel() {
43 tableModel =
new KeywordListTableModel();
45 customizeComponents();
48 private void customizeComponents() {
49 listsTable.setAutoscrolls(
true);
50 listsTable.setTableHeader(null);
51 listsTable.setShowHorizontalLines(
false);
52 listsTable.setShowVerticalLines(
false);
54 listsTable.getParent().setBackground(listsTable.getBackground());
56 listsTable.setCellSelectionEnabled(
false);
57 listsTable.setRowSelectionAllowed(
true);
83 @SuppressWarnings(
"unchecked")
85 private
void initComponents() {
87 jScrollPane1 =
new javax.swing.JScrollPane();
88 listsTable =
new javax.swing.JTable();
89 newListButton =
new javax.swing.JButton();
90 importButton =
new javax.swing.JButton();
91 keywordListsLabel =
new javax.swing.JLabel();
93 setMinimumSize(
new java.awt.Dimension(250, 0));
94 setPreferredSize(
new java.awt.Dimension(250, 492));
96 jScrollPane1.setPreferredSize(
new java.awt.Dimension(200, 402));
98 listsTable.setModel(tableModel);
99 listsTable.setShowHorizontalLines(
false);
100 listsTable.setShowVerticalLines(
false);
101 listsTable.getTableHeader().setReorderingAllowed(
false);
102 listsTable.addKeyListener(
new java.awt.event.KeyAdapter() {
103 public void keyPressed(java.awt.event.KeyEvent evt) {
104 listsTableKeyPressed(evt);
107 jScrollPane1.setViewportView(listsTable);
109 newListButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/new16.png")));
110 newListButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.newListButton.text"));
111 newListButton.addActionListener(
new java.awt.event.ActionListener() {
112 public void actionPerformed(java.awt.event.ActionEvent evt) {
113 newListButtonActionPerformed(evt);
117 importButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/import16.png")));
118 importButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.importButton.text"));
119 importButton.addActionListener(
new java.awt.event.ActionListener() {
120 public void actionPerformed(java.awt.event.ActionEvent evt) {
121 importButtonActionPerformed(evt);
125 keywordListsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.keywordListsLabel.text"));
127 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
128 this.setLayout(layout);
129 layout.setHorizontalGroup(
130 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131 .addGroup(layout.createSequentialGroup()
133 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
135 .addGroup(layout.createSequentialGroup()
136 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addComponent(keywordListsLabel)
138 .addGroup(layout.createSequentialGroup()
139 .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
141 .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
142 .addGap(0, 0, Short.MAX_VALUE)))
145 layout.setVerticalGroup(
146 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
149 .addComponent(keywordListsLabel)
150 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
151 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
152 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
153 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(newListButton)
155 .addComponent(importButton))
160 private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {
161 XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
162 String listName = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKwListTitle"),
163 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"), JOptionPane.PLAIN_MESSAGE, null, null,
"");
164 if (listName == null || listName.trim().equals(
"")) {
167 boolean shouldAdd =
false;
168 if (writer.listExists(listName)) {
169 if (writer.getList(listName).isLocked()) {
170 boolean replace = KeywordSearchUtil.displayConfirmDialog(
171 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"),
172 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.newKeywordListDescription", listName),
173 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
178 boolean replace = KeywordSearchUtil.displayConfirmDialog(
179 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"),
180 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.newKeywordListDescription2", listName),
181 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
190 writer.addList(listName,
new ArrayList<Keyword>());
195 for (
int i = 0; i < listsTable.getRowCount(); i++) {
196 if (listsTable.getValueAt(i, 0).equals(listName)) {
197 listsTable.getSelectionModel().addSelectionInterval(i, i);
202 private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {
204 JFileChooser chooser =
new JFileChooser();
205 final String[] AUTOPSY_EXTENSIONS =
new String[]{
"xml"};
206 final String[] ENCASE_EXTENSIONS =
new String[]{
"txt"};
207 FileNameExtensionFilter autopsyFilter =
new FileNameExtensionFilter(
208 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), AUTOPSY_EXTENSIONS);
209 FileNameExtensionFilter encaseFilter =
new FileNameExtensionFilter(
210 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.fileExtensionFilterLb2"), ENCASE_EXTENSIONS);
211 chooser.addChoosableFileFilter(autopsyFilter);
212 chooser.addChoosableFileFilter(encaseFilter);
213 chooser.setAcceptAllFileFilterUsed(
false);
214 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
216 String listName = null;
217 int returnVal = chooser.showOpenDialog(
this);
218 if (returnVal == JFileChooser.APPROVE_OPTION) {
219 File selFile = chooser.getSelectedFile();
220 if (selFile == null) {
225 String fileAbs = selFile.getAbsolutePath();
227 final KeywordSearchList reader;
229 if (KeywordSearchUtil.isXMLList(fileAbs)) {
230 reader =
new XmlKeywordSearchList(fileAbs);
232 reader =
new EnCaseKeywordSearchList(fileAbs);
235 if (!reader.load()) {
236 KeywordSearchUtil.displayDialog(
237 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(),
"KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
241 List<KeywordList> toImport = reader.getListsL();
242 List<KeywordList> toImportConfirmed =
new ArrayList<KeywordList>();
244 final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
246 for (KeywordList list : toImport) {
248 listName = list.getName();
249 if (writer.listExists(listName)) {
250 Object[] options = {NbBundle.getMessage(this.getClass(),
"KeywordSearch.yesOwMsg"),
251 NbBundle.getMessage(this.getClass(),
"KeywordSearch.noSkipMsg"),
252 NbBundle.getMessage(this.getClass(),
"KeywordSearch.cancelImportMsg")};
253 int choice = JOptionPane.showOptionDialog(
this,
254 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.overwriteListPrompt", listName),
255 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.importOwConflict"),
256 JOptionPane.YES_NO_CANCEL_OPTION,
257 JOptionPane.QUESTION_MESSAGE,
261 if (choice == JOptionPane.OK_OPTION) {
262 toImportConfirmed.add(list);
263 }
else if (choice == JOptionPane.CANCEL_OPTION) {
269 toImportConfirmed.add(list);
274 if (toImportConfirmed.isEmpty()) {
278 if (!writer.writeLists(toImportConfirmed)) {
279 KeywordSearchUtil.displayDialog(
280 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(),
"KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
287 if (listName != null) {
288 for (
int i = 0; i < listsTable.getRowCount(); i++) {
289 if (listsTable.getValueAt(i, 0).equals(listName)) {
290 listsTable.getSelectionModel().addSelectionInterval(i, i);
295 private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {
296 if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
297 int[] selected = listsTable.getSelectedRows();
298 if (selected.length == 0) {
300 }
else if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(),
"KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(
this.getClass(),
"KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
301 String listName = (String) listsTable.getModel().getValueAt(selected[0], 0);
302 XmlKeywordSearchList.getCurrent().deleteList(listName);
311 private javax.swing.JButton importButton;
312 private javax.swing.JScrollPane jScrollPane1;
313 private javax.swing.JLabel keywordListsLabel;
314 private javax.swing.JTable listsTable;
315 private javax.swing.JButton newListButton;
319 public void store() {
325 listsTable.clearSelection();
334 private XmlKeywordSearchList
listsHandle = XmlKeywordSearchList.getCurrent();
343 return listsHandle.getNumberLists(
false);
348 return NbBundle.getMessage(this.getClass(),
"KeywordSearchListsManagementPanel.getColName.text");
353 return listsHandle.getListNames(
false).get(rowIndex);
362 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
363 throw new UnsupportedOperationException(
364 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
373 void deleteSelected(
int[] selected) {
374 List<String> toDel =
new ArrayList<>();
375 for (
int i = 0; i < selected.length; i++) {
376 toDel.add((String)
getValueAt(0, selected[i]));
378 for (String del : toDel) {
379 listsHandle.deleteList(del);
385 fireTableDataChanged();
389 void addListSelectionListener(ListSelectionListener l) {
390 listsTable.getSelectionModel().addListSelectionListener(l);
Object getValueAt(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)
XmlKeywordSearchList listsHandle
Class<?> getColumnClass(int c)
String getColumnName(int column)
boolean isCellEditable(int rowIndex, int columnIndex)