Autopsy  4.19.1
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-2021 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 
161  void setDataSourceSelected(long dataSourceId) {
162  this.dataSourceCheckBox.setSelected(true);
163  setComponentsEnabled();
164  String dataSourceName = dataSourceMap.get(dataSourceId);
165  dataSourceList.setSelectedValue(dataSourceName, true);
166  }
167 
173  @SuppressWarnings("unchecked")
174  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
175  private void initComponents() {
176 
177  jScrollPane1 = new javax.swing.JScrollPane();
178  dataSourceList = new javax.swing.JList<>();
179  dataSourceCheckBox = new javax.swing.JCheckBox();
180  dataSourceNoteLabel = new javax.swing.JLabel();
181 
182  setMinimumSize(new java.awt.Dimension(150, 150));
183  setPreferredSize(new java.awt.Dimension(150, 150));
184 
185  dataSourceList.setModel(new DefaultListModel<String>());
186  dataSourceList.setEnabled(false);
187  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
188  jScrollPane1.setViewportView(dataSourceList);
189 
190  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceCheckBox.text")); // NOI18N
191  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
192  public void actionPerformed(java.awt.event.ActionEvent evt) {
193  dataSourceCheckBoxActionPerformed(evt);
194  }
195  });
196 
197  dataSourceNoteLabel.setFont(dataSourceNoteLabel.getFont().deriveFont(dataSourceNoteLabel.getFont().getSize()-1f));
198  org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLabel.text")); // NOI18N
199  dataSourceNoteLabel.setEnabled(false);
200 
201  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
202  this.setLayout(layout);
203  layout.setHorizontalGroup(
204  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205  .addGroup(layout.createSequentialGroup()
206  .addComponent(dataSourceCheckBox)
207  .addGap(0, 0, Short.MAX_VALUE))
208  .addGroup(layout.createSequentialGroup()
209  .addContainerGap()
210  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
212  .addGroup(layout.createSequentialGroup()
213  .addComponent(dataSourceNoteLabel)
214  .addGap(0, 0, Short.MAX_VALUE)))
215  .addContainerGap())
216  );
217  layout.setVerticalGroup(
218  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
220  .addComponent(dataSourceCheckBox)
221  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
223  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
224  .addComponent(dataSourceNoteLabel)
225  .addContainerGap())
226  );
227 
228  dataSourceCheckBox.getAccessibleContext().setAccessibleName("");
229  }// </editor-fold>//GEN-END:initComponents
230 
231  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
232  setComponentsEnabled();
233  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
234  this.dataSourceList.setSelectedIndices(new int[0]);
235  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
236 
237  // Variables declaration - do not modify//GEN-BEGIN:variables
238  private javax.swing.JCheckBox dataSourceCheckBox;
239  private javax.swing.JList<String> dataSourceList;
240  private javax.swing.JLabel dataSourceNoteLabel;
241  private javax.swing.JScrollPane jScrollPane1;
242  // End of variables declaration//GEN-END:variables
243 }
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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