19 package org.sleuthkit.autopsy.keywordsearch;
 
   21 import java.awt.event.KeyEvent;
 
   23 import java.util.ArrayList;
 
   24 import java.util.List;
 
   25 import javax.swing.JFileChooser;
 
   26 import javax.swing.JOptionPane;
 
   27 import javax.swing.event.ListSelectionEvent;
 
   28 import javax.swing.event.ListSelectionListener;
 
   29 import javax.swing.filechooser.FileNameExtensionFilter;
 
   30 import javax.swing.table.AbstractTableModel;
 
   31 import org.netbeans.spi.options.OptionsPanelController;
 
   32 import org.openide.util.NbBundle;
 
   39 class GlobalListsManagementPanel 
extends javax.swing.JPanel implements OptionsPanel {
 
   41     private static final long serialVersionUID = 1L;
 
   43     private final Logger logger = Logger.
getLogger(GlobalListsManagementPanel.class.getName());
 
   44     private final KeywordListTableModel tableModel;
 
   48         this.globalListSettingsPanel = gsp;
 
   49         tableModel = 
new KeywordListTableModel();
 
   51         customizeComponents();
 
   54     private void customizeComponents() {
 
   55         listsTable.setAutoscrolls(
true);
 
   56         listsTable.setTableHeader(null);
 
   57         listsTable.setShowHorizontalLines(
false);
 
   58         listsTable.setShowVerticalLines(
false);
 
   60         listsTable.getParent().setBackground(listsTable.getBackground());
 
   62         listsTable.setCellSelectionEnabled(
false);
 
   63         listsTable.setRowSelectionAllowed(
true);
 
   66         listsTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
 
   68             public void valueChanged(ListSelectionEvent e) {
 
   69                 globalListSettingsPanel.setFocusOnKeywordTextBox();
 
   95     @SuppressWarnings(
"unchecked")
 
   97     private 
void initComponents() {
 
   99         jScrollPane1 = 
new javax.swing.JScrollPane();
 
  100         listsTable = 
new javax.swing.JTable();
 
  101         newListButton = 
new javax.swing.JButton();
 
  102         importButton = 
new javax.swing.JButton();
 
  103         keywordListsLabel = 
new javax.swing.JLabel();
 
  105         setMinimumSize(
new java.awt.Dimension(250, 0));
 
  107         listsTable.setModel(tableModel);
 
  108         listsTable.setMaximumSize(
new java.awt.Dimension(30000, 30000));
 
  109         listsTable.setShowHorizontalLines(
false);
 
  110         listsTable.setShowVerticalLines(
false);
 
  111         listsTable.getTableHeader().setReorderingAllowed(
false);
 
  112         listsTable.addKeyListener(
new java.awt.event.KeyAdapter() {
 
  113             public void keyPressed(java.awt.event.KeyEvent evt) {
 
  114                 listsTableKeyPressed(evt);
 
  117         jScrollPane1.setViewportView(listsTable);
 
  119         newListButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/new16.png"))); 
 
  120         newListButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, 
"GlobalListsManagementPanel.newListButton.text")); 
 
  121         newListButton.addActionListener(
new java.awt.event.ActionListener() {
 
  122             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  123                 newListButtonActionPerformed(evt);
 
  127         importButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/import16.png"))); 
 
  128         importButton.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, 
"GlobalListsManagementPanel.importButton.text")); 
 
  129         importButton.addActionListener(
new java.awt.event.ActionListener() {
 
  130             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  131                 importButtonActionPerformed(evt);
 
  135         keywordListsLabel.setText(
org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, 
"GlobalListsManagementPanel.keywordListsLabel.text")); 
 
  137         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  138         this.setLayout(layout);
 
  139         layout.setHorizontalGroup(
 
  140             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  141             .addGroup(layout.createSequentialGroup()
 
  143                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  144                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
 
  145                     .addGroup(layout.createSequentialGroup()
 
  146                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  147                             .addComponent(keywordListsLabel)
 
  148                             .addGroup(layout.createSequentialGroup()
 
  149                                 .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  151                                 .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
 
  152                         .addGap(0, 0, Short.MAX_VALUE)))
 
  155         layout.setVerticalGroup(
 
  156             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  157             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  159                 .addComponent(keywordListsLabel)
 
  160                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  161                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
 
  163                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  164                     .addComponent(newListButton)
 
  165                     .addComponent(importButton))
 
  170     private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  171         XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
 
  172         String listName = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.newKwListTitle"),
 
  173                 NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.newKeywordListMsg"), JOptionPane.PLAIN_MESSAGE, null, null, 
"");
 
  174         if (listName == null || listName.trim().equals(
"")) {
 
  177         boolean shouldAdd = 
false;
 
  178         if (writer.listExists(listName)) {
 
  179             if (writer.getList(listName).isEditable()) {
 
  180                 boolean replace = KeywordSearchUtil.displayConfirmDialog(
 
  181                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.newKeywordListMsg"),
 
  182                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsManagementPanel.newKeywordListDescription", listName),
 
  183                         KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
 
  188                 boolean replace = KeywordSearchUtil.displayConfirmDialog(
 
  189                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.newKeywordListMsg"),
 
  190                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsManagementPanel.newKeywordListDescription2", listName),
 
  191                         KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
 
  200             writer.addList(listName, 
new ArrayList<Keyword>());
 
  205         for (
int i = 0; i < listsTable.getRowCount(); i++) {
 
  206             if (listsTable.getValueAt(i, 0).equals(listName)) {
 
  207                 listsTable.getSelectionModel().addSelectionInterval(i, i);
 
  210         firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
 
  211         globalListSettingsPanel.setFocusOnKeywordTextBox();
 
  214     private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  216         JFileChooser chooser = 
new JFileChooser();
 
  217         final String[] AUTOPSY_EXTENSIONS = 
new String[]{
"xml"}; 
 
  218         final String[] ENCASE_EXTENSIONS = 
new String[]{
"txt"}; 
 
  219         FileNameExtensionFilter autopsyFilter = 
new FileNameExtensionFilter(
 
  220                 NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), AUTOPSY_EXTENSIONS);
 
  221         FileNameExtensionFilter encaseFilter = 
new FileNameExtensionFilter(
 
  222                 NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsManagementPanel.fileExtensionFilterLb2"), ENCASE_EXTENSIONS);
 
  223         chooser.addChoosableFileFilter(autopsyFilter);
 
  224         chooser.addChoosableFileFilter(encaseFilter);
 
  225         chooser.setAcceptAllFileFilterUsed(
false);
 
  226         chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
 
  228         String listName = null;
 
  229         int returnVal = chooser.showOpenDialog(
this);
 
  230         if (returnVal == JFileChooser.APPROVE_OPTION) {
 
  231             File selFile = chooser.getSelectedFile();
 
  232             if (selFile == null) {
 
  237             String fileAbs = selFile.getAbsolutePath();
 
  239             final KeywordSearchList reader;
 
  241             if (KeywordSearchUtil.isXMLList(fileAbs)) {
 
  242                 reader = 
new XmlKeywordSearchList(fileAbs);
 
  244                 reader = 
new EnCaseKeywordSearchList(fileAbs);
 
  247             if (!reader.load()) {
 
  248                 KeywordSearchUtil.displayDialog(
 
  249                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
 
  253             List<KeywordList> toImport = reader.getListsL();
 
  254             List<KeywordList> toImportConfirmed = 
new ArrayList<KeywordList>();
 
  256             final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
 
  258             for (KeywordList list : toImport) {
 
  260                 listName = list.getName();
 
  261                 if (writer.listExists(listName)) {
 
  262                     Object[] options = {NbBundle.getMessage(this.getClass(), 
"KeywordSearch.yesOwMsg"),
 
  263                         NbBundle.getMessage(this.getClass(), 
"KeywordSearch.noSkipMsg"),
 
  264                         NbBundle.getMessage(this.getClass(), 
"KeywordSearch.cancelImportMsg")};
 
  265                     int choice = JOptionPane.showOptionDialog(
this,
 
  266                             NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.overwriteListPrompt", listName),
 
  267                             NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.importOwConflict"),
 
  268                             JOptionPane.YES_NO_CANCEL_OPTION,
 
  269                             JOptionPane.QUESTION_MESSAGE,
 
  273                     if (choice == JOptionPane.OK_OPTION) {
 
  274                         toImportConfirmed.add(list);
 
  275                     } 
else if (choice == JOptionPane.CANCEL_OPTION) {
 
  281                     toImportConfirmed.add(list);
 
  286             if (toImportConfirmed.isEmpty()) {
 
  290             if (!writer.writeLists(toImportConfirmed)) {
 
  291                 KeywordSearchUtil.displayDialog(
 
  292                         NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(
this.getClass(), 
"KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
 
  299         if (listName != null) {
 
  300             for (
int i = 0; i < listsTable.getRowCount(); i++) {
 
  301                 if (listsTable.getValueAt(i, 0).equals(listName)) {
 
  302                     listsTable.getSelectionModel().addSelectionInterval(i, i);
 
  306         firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
 
  308     private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {
 
  309         if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
 
  310             int[] selected = listsTable.getSelectedRows();
 
  311             if (selected.length == 0) {
 
  313             } 
else if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(
this.getClass(), 
"KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(
this.getClass(), 
"KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
 
  314                 String listName = (String) listsTable.getModel().getValueAt(selected[0], 0);
 
  315                 XmlKeywordSearchList.getCurrent().deleteList(listName);
 
  316                 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
 
  325     private javax.swing.JButton importButton;
 
  326     private javax.swing.JScrollPane jScrollPane1;
 
  327     private javax.swing.JLabel keywordListsLabel;
 
  328     private javax.swing.JTable listsTable;
 
  329     private javax.swing.JButton newListButton;
 
  333     public void store() {
 
  339         listsTable.clearSelection();
 
  348         private final XmlKeywordSearchList 
listsHandle = XmlKeywordSearchList.getCurrent();
 
  357             return listsHandle.getNumberLists(
false);
 
  362             return NbBundle.getMessage(this.getClass(), 
"KeywordSearchListsManagementPanel.getColName.text");
 
  367             return listsHandle.getListNames(
false).get(rowIndex);
 
  376         public void setValueAt(Object aValue, 
int rowIndex, 
int columnIndex) {
 
  377             throw new UnsupportedOperationException(
 
  378                     NbBundle.getMessage(
this.getClass(), 
"KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
 
  387         void deleteSelected(
int[] selected) {
 
  388             List<String> toDel = 
new ArrayList<>();
 
  389             for (
int i = 0; i < selected.length; i++) {
 
  390                 toDel.add((String) 
getValueAt(0, selected[i]));
 
  392             for (String del : toDel) {
 
  393                 listsHandle.deleteList(del);
 
  399             fireTableDataChanged();
 
  403     void addListSelectionListener(ListSelectionListener l) {
 
  404         listsTable.getSelectionModel().addListSelectionListener(l);
 
final XmlKeywordSearchList listsHandle
Object getValueAt(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)
Class<?> getColumnClass(int c)
String getColumnName(int column)
boolean isCellEditable(int rowIndex, int columnIndex)
synchronized static Logger getLogger(String name)