Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourcePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.filesearch;
20 
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.logging.Level;
30 import javax.swing.DefaultListModel;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
36 import org.sleuthkit.datamodel.DataSource;
37 import org.sleuthkit.datamodel.SleuthkitCase;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
44 public class DataSourcePanel extends javax.swing.JPanel {
45 
46  private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName());
47  private static final long serialVersionUID = 1L;
48  private final Map<Long, String> dataSourceMap = new HashMap<>();
49 
53  public DataSourcePanel() {
54  initComponents();
55  resetDataSourcePanel();
56  }
57 
62  final void resetDataSourcePanel() {
63  dataSourceList.clearSelection();
64  //remove all list selection listeners
65  for (ListSelectionListener listener : dataSourceList.getListSelectionListeners()){
66  dataSourceList.removeListSelectionListener(listener);
67  }
68  ((DefaultListModel<String>) dataSourceList.getModel()).clear();
69  List<String> strings = getDataSourceArray();
70  for (String dataSource : strings) {
71  ((DefaultListModel<String>) dataSourceList.getModel()).addElement(dataSource);
72  }
73  dataSourceList.setEnabled(false);
74  dataSourceCheckBox.setSelected(false);
75  dataSourceNoteLabel.setEnabled(false);
76  if (dataSourceList.getModel().getSize() > 1) {
77  dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
78  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
79  });
80  dataSourceCheckBox.setEnabled(true);
81  } else {
82  /*
83  * Disable data source filtering since there aren't multiple data
84  * sources to choose from.
85  */
86  this.dataSourceCheckBox.setEnabled(false);
87  }
88  }
89 
95  private List<String> getDataSourceArray() {
96  List<String> dsList = new ArrayList<>();
97  try {
98  Case currentCase = Case.getCurrentCaseThrows();
99  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
100  List<DataSource> dataSources = tskDb.getDataSources();
101  Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
102  for (DataSource ds : dataSources) {
103  String dsName = ds.getName();
104  File dataSourceFullName = new File(dsName);
105  String displayName = dataSourceFullName.getName();
106  dataSourceMap.put(ds.getId(), displayName);
107  dsList.add(displayName);
108  }
109  } catch (NoCurrentCaseException ex) {
110  logger.log(Level.SEVERE, "Unable to get current open case.", ex);
111  } catch (TskCoreException ex) {
112  logger.log(Level.SEVERE, "Failed to get data source info from database.", ex);
113  }
114  return dsList;
115  }
116 
122  Set<Long> getDataSourcesSelected() {
123  Set<Long> dataSourceObjIdSet = new HashSet<>();
124  List<String> dataSources = dataSourceList.getSelectedValuesList();
125  for (Long key : dataSourceMap.keySet()) {
126  String value = dataSourceMap.get(key);
127  for (String dataSource : dataSources) {
128  if (value.equals(dataSource)) {
129  dataSourceObjIdSet.add(key);
130  }
131  }
132  }
133  return dataSourceObjIdSet;
134  }
135 
141  boolean isSelected() {
142  return this.dataSourceCheckBox.isSelected();
143  }
144 
149  final void setComponentsEnabled() {
150  boolean enabled = this.isSelected();
151  this.dataSourceList.setEnabled(enabled);
152  this.dataSourceNoteLabel.setEnabled(enabled);
153  }
154 
160  @SuppressWarnings("unchecked")
161  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
162  private void initComponents() {
163 
164  jScrollPane1 = new javax.swing.JScrollPane();
165  dataSourceList = new javax.swing.JList<>();
166  dataSourceCheckBox = new javax.swing.JCheckBox();
167  dataSourceNoteLabel = new javax.swing.JLabel();
168 
169  setMinimumSize(new java.awt.Dimension(150, 150));
170  setPreferredSize(new java.awt.Dimension(150, 150));
171 
172  dataSourceList.setModel(new DefaultListModel<String>());
173  dataSourceList.setEnabled(false);
174  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
175  jScrollPane1.setViewportView(dataSourceList);
176 
177  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceCheckBox.text")); // NOI18N
178  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
179  public void actionPerformed(java.awt.event.ActionEvent evt) {
180  dataSourceCheckBoxActionPerformed(evt);
181  }
182  });
183 
184  dataSourceNoteLabel.setFont(dataSourceNoteLabel.getFont().deriveFont(dataSourceNoteLabel.getFont().getSize()-1f));
185  org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLabel.text")); // NOI18N
186  dataSourceNoteLabel.setEnabled(false);
187 
188  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
189  this.setLayout(layout);
190  layout.setHorizontalGroup(
191  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192  .addGroup(layout.createSequentialGroup()
193  .addComponent(dataSourceCheckBox)
194  .addGap(0, 0, Short.MAX_VALUE))
195  .addGroup(layout.createSequentialGroup()
196  .addContainerGap()
197  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
199  .addGroup(layout.createSequentialGroup()
200  .addComponent(dataSourceNoteLabel)
201  .addGap(0, 0, Short.MAX_VALUE)))
202  .addContainerGap())
203  );
204  layout.setVerticalGroup(
205  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
207  .addComponent(dataSourceCheckBox)
208  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
210  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
211  .addComponent(dataSourceNoteLabel)
212  .addContainerGap())
213  );
214 
215  dataSourceCheckBox.getAccessibleContext().setAccessibleName("");
216  }// </editor-fold>//GEN-END:initComponents
217 
218  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
219  setComponentsEnabled();
220  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
221  this.dataSourceList.setSelectedIndices(new int[0]);
222  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
223 
224  // Variables declaration - do not modify//GEN-BEGIN:variables
225  private javax.swing.JCheckBox dataSourceCheckBox;
226  private javax.swing.JList<String> dataSourceList;
227  private javax.swing.JLabel dataSourceNoteLabel;
228  private javax.swing.JScrollPane jScrollPane1;
229  // End of variables declaration//GEN-END:variables
230 }
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.