20 package org.sleuthkit.autopsy.keywordsearch;
22 import java.awt.event.KeyEvent;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.openide.util.NbBundle;
28 import javax.swing.JFileChooser;
29 import javax.swing.JOptionPane;
30 import javax.swing.event.ListSelectionListener;
31 import javax.swing.filechooser.FileNameExtensionFilter;
32 import javax.swing.table.AbstractTableModel;
38 class GlobalListsManagementPanel
extends javax.swing.JPanel implements OptionsPanel {
40 private Logger logger = Logger.getLogger(GlobalListsManagementPanel.class.getName());
41 private KeywordListTableModel tableModel;
43 GlobalListsManagementPanel() {
44 tableModel =
new KeywordListTableModel();
46 customizeComponents();
49 private void customizeComponents() {
50 listsTable.setAutoscrolls(
true);
51 listsTable.setTableHeader(null);
52 listsTable.setShowHorizontalLines(
false);
53 listsTable.setShowVerticalLines(
false);
55 listsTable.getParent().setBackground(listsTable.getBackground());
57 listsTable.setCellSelectionEnabled(
false);
58 listsTable.setRowSelectionAllowed(
true);
90 @SuppressWarnings(
"unchecked")
92 private
void initComponents() {
94 jScrollPane1 =
new javax.swing.JScrollPane();
95 listsTable =
new javax.swing.JTable();
96 newListButton =
new javax.swing.JButton();
97 importButton =
new javax.swing.JButton();
98 keywordListsLabel =
new javax.swing.JLabel();
100 setMinimumSize(
new java.awt.Dimension(250, 0));
101 setPreferredSize(
new java.awt.Dimension(250, 492));
103 jScrollPane1.setPreferredSize(
new java.awt.Dimension(200, 402));
105 listsTable.setModel(tableModel);
106 listsTable.setShowHorizontalLines(
false);
107 listsTable.setShowVerticalLines(
false);
108 listsTable.getTableHeader().setReorderingAllowed(
false);
109 listsTable.addKeyListener(
new java.awt.event.KeyAdapter() {
110 public void keyPressed(java.awt.event.KeyEvent evt) {
111 listsTableKeyPressed(evt);
114 jScrollPane1.setViewportView(listsTable);
116 newListButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/new16.png")));
117 newListButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.newListButton.text"));
118 newListButton.addActionListener(
new java.awt.event.ActionListener() {
119 public void actionPerformed(java.awt.event.ActionEvent evt) {
120 newListButtonActionPerformed(evt);
124 importButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/import16.png")));
125 importButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.importButton.text"));
126 importButton.addActionListener(
new java.awt.event.ActionListener() {
127 public void actionPerformed(java.awt.event.ActionEvent evt) {
128 importButtonActionPerformed(evt);
132 keywordListsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class,
"KeywordSearchListsManagementPanel.keywordListsLabel.text"));
134 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
135 this.setLayout(layout);
136 layout.setHorizontalGroup(
137 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
138 .addGroup(layout.createSequentialGroup()
140 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141 .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
142 .addGroup(layout.createSequentialGroup()
143 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addComponent(keywordListsLabel)
145 .addGroup(layout.createSequentialGroup()
146 .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
148 .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
149 .addGap(0, 0, Short.MAX_VALUE)))
152 layout.setVerticalGroup(
153 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
156 .addComponent(keywordListsLabel)
157 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
158 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
159 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
160 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
161 .addComponent(newListButton)
162 .addComponent(importButton))
167 private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {
168 XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
169 String listName = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKwListTitle"),
170 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"), JOptionPane.PLAIN_MESSAGE, null, null,
"");
171 if (listName == null || listName.trim().equals(
"")) {
174 boolean shouldAdd =
false;
175 if (writer.listExists(listName)) {
176 if (writer.getList(listName).isLocked() ) {
177 boolean replace = KeywordSearchUtil.displayConfirmDialog(
178 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"),
179 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.newKeywordListDescription", listName),
180 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
186 boolean replace = KeywordSearchUtil.displayConfirmDialog(
187 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.newKeywordListMsg"),
188 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.newKeywordListDescription2", listName),
189 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
198 writer.addList(listName,
new ArrayList<Keyword>());
203 for (
int i = 0; i < listsTable.getRowCount(); i++) {
204 if (listsTable.getValueAt(i, 0).equals(listName)) {
205 listsTable.getSelectionModel().addSelectionInterval(i, i);
210 private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {
212 JFileChooser chooser =
new JFileChooser();
213 final String[] EXTENSION =
new String[]{
"xml",
"txt"};
214 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
215 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), EXTENSION);
216 chooser.setFileFilter(filter);
217 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
219 String listName = null;
220 int returnVal = chooser.showOpenDialog(
this);
221 if (returnVal == JFileChooser.APPROVE_OPTION) {
222 File selFile = chooser.getSelectedFile();
223 if (selFile == null) {
228 String fileAbs = selFile.getAbsolutePath();
230 final KeywordSearchList reader;
232 if(KeywordSearchUtil.isXMLList(fileAbs)) {
233 reader =
new XmlKeywordSearchList(fileAbs);
235 reader =
new EnCaseKeywordSearchList(fileAbs);
238 if (!reader.load()) {
239 KeywordSearchUtil.displayDialog(
240 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(),
"KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
244 List<KeywordList> toImport = reader.getListsL();
245 List<KeywordList> toImportConfirmed =
new ArrayList<KeywordList>();
247 final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
249 for (KeywordList list : toImport) {
251 listName = list.getName();
252 if (writer.listExists(listName)) {
253 Object[] options = {NbBundle.getMessage(this.getClass(),
"KeywordSearch.yesOwMsg"),
254 NbBundle.getMessage(this.getClass(),
"KeywordSearch.noSkipMsg"),
255 NbBundle.getMessage(this.getClass(),
"KeywordSearch.cancelImportMsg")};
256 int choice = JOptionPane.showOptionDialog(
this,
257 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.overwriteListPrompt", listName),
258 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.importOwConflict"),
259 JOptionPane.YES_NO_CANCEL_OPTION,
260 JOptionPane.QUESTION_MESSAGE,
264 if (choice == JOptionPane.OK_OPTION) {
265 toImportConfirmed.add(list);
266 }
else if (choice == JOptionPane.CANCEL_OPTION) {
272 toImportConfirmed.add(list);
277 if (toImportConfirmed.isEmpty()) {
281 if (!writer.writeLists(toImportConfirmed)) {
282 KeywordSearchUtil.displayDialog(
283 NbBundle.getMessage(
this.getClass(),
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(),
"KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
290 if (listName != null) {
291 for (
int i = 0; i < listsTable.getRowCount(); i++) {
292 if (listsTable.getValueAt(i, 0).equals(listName)) {
293 listsTable.getSelectionModel().addSelectionInterval(i, i);
298 private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {
299 if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
300 int[] selected = listsTable.getSelectedRows();
301 if (selected.length == 0) {
303 }
else if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(),
"KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(
this.getClass(),
"KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
304 String listName = (String) listsTable.getModel().getValueAt(selected[0], 0);
305 XmlKeywordSearchList.getCurrent().deleteList(listName);
314 private javax.swing.JButton importButton;
315 private javax.swing.JScrollPane jScrollPane1;
316 private javax.swing.JLabel keywordListsLabel;
317 private javax.swing.JTable listsTable;
318 private javax.swing.JButton newListButton;
322 public void store() {
328 listsTable.clearSelection();
337 private XmlKeywordSearchList
listsHandle = XmlKeywordSearchList.getCurrent();
346 return listsHandle.getNumberLists(
false);
351 return NbBundle.getMessage(this.getClass(),
"KeywordSearchListsManagementPanel.getColName.text");
356 return listsHandle.getListNames(
false).get(rowIndex);
365 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
366 throw new UnsupportedOperationException(
367 NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
376 void deleteSelected(
int[] selected) {
377 List<String> toDel =
new ArrayList<>();
378 for(
int i = 0; i < selected.length; i++){
379 toDel.add((String)
getValueAt(0, selected[i]));
381 for (String del : toDel) {
382 listsHandle.deleteList(del);
388 fireTableDataChanged();
392 void addListSelectionListener(ListSelectionListener l) {
393 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)