Autopsy 4.22.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 */
19package org.sleuthkit.autopsy.filesearch;
20
21import java.beans.PropertyChangeEvent;
22import java.io.File;
23import java.util.ArrayList;
24import java.util.Collections;
25import java.util.EnumSet;
26import java.util.HashMap;
27import java.util.HashSet;
28import java.util.List;
29import java.util.Map;
30import java.util.Set;
31import java.util.logging.Level;
32import javax.swing.DefaultListModel;
33import javax.swing.event.ListSelectionEvent;
34import javax.swing.event.ListSelectionListener;
35import org.sleuthkit.autopsy.casemodule.Case;
36import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
37import org.sleuthkit.autopsy.coreutils.Logger;
38import org.sleuthkit.datamodel.DataSource;
39import org.sleuthkit.datamodel.SleuthkitCase;
40import org.sleuthkit.datamodel.TskCoreException;
41
45@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
46public class DataSourcePanel extends javax.swing.JPanel {
47
48 private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName());
49 private static final long serialVersionUID = 1L;
50 private final Map<Long, String> dataSourceMap = new HashMap<>();
51
55 public DataSourcePanel() {
57 resetDataSourcePanel();
58
59 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.DATA_SOURCE_ADDED), (PropertyChangeEvent evt) -> {
60 if(evt.getPropertyName().equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
61 List<String> strings = getDataSourceArray();
62 for (String dataSource : strings) {
63 DefaultListModel<String> model = (DefaultListModel<String>) dataSourceList.getModel();
64 if(!model.contains(dataSource)) {
65 model.addElement(dataSource);
66 }
67 }
68 }
69 });
70 }
71
76 final void resetDataSourcePanel() {
77 dataSourceList.clearSelection();
78 //remove all list selection listeners
79 for (ListSelectionListener listener : dataSourceList.getListSelectionListeners()){
80 dataSourceList.removeListSelectionListener(listener);
81 }
82 ((DefaultListModel<String>) dataSourceList.getModel()).clear();
83 List<String> strings = getDataSourceArray();
84 for (String dataSource : strings) {
85 ((DefaultListModel<String>) dataSourceList.getModel()).addElement(dataSource);
86 }
87 dataSourceList.setEnabled(false);
88 dataSourceCheckBox.setSelected(false);
89 dataSourceNoteLabel.setEnabled(false);
90 if (dataSourceList.getModel().getSize() > 1) {
91 dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
92 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
93 });
94 dataSourceCheckBox.setEnabled(true);
95 } else {
96 /*
97 * Disable data source filtering since there aren't multiple data
98 * sources to choose from.
99 */
100 this.dataSourceCheckBox.setEnabled(false);
101 }
102 }
103
109 private List<String> getDataSourceArray() {
110 List<String> dsList = new ArrayList<>();
111 try {
112 Case currentCase = Case.getCurrentCaseThrows();
113 SleuthkitCase tskDb = currentCase.getSleuthkitCase();
114 List<DataSource> dataSources = tskDb.getDataSources();
115 Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
116 for (DataSource ds : dataSources) {
117 String dsName = ds.getName();
118 File dataSourceFullName = new File(dsName);
119 String displayName = dataSourceFullName.getName();
120 dataSourceMap.put(ds.getId(), displayName);
121 dsList.add(displayName);
122 }
123 } catch (NoCurrentCaseException ex) {
124 logger.log(Level.SEVERE, "Unable to get current open case.", ex);
125 } catch (TskCoreException ex) {
126 logger.log(Level.SEVERE, "Failed to get data source info from database.", ex);
127 }
128 return dsList;
129 }
130
136 Set<Long> getDataSourcesSelected() {
137 Set<Long> dataSourceObjIdSet = new HashSet<>();
138 List<String> dataSources = dataSourceList.getSelectedValuesList();
139 for (Long key : dataSourceMap.keySet()) {
140 String value = dataSourceMap.get(key);
141 for (String dataSource : dataSources) {
142 if (value.equals(dataSource)) {
143 dataSourceObjIdSet.add(key);
144 }
145 }
146 }
147 return dataSourceObjIdSet;
148 }
149
155 boolean isSelected() {
156 return this.dataSourceCheckBox.isSelected();
157 }
158
163 final void setComponentsEnabled() {
164 boolean enabled = this.isSelected();
165 this.dataSourceList.setEnabled(enabled);
166 this.dataSourceNoteLabel.setEnabled(enabled);
167 }
168
175 void setDataSourceSelected(long dataSourceId) {
176 this.dataSourceCheckBox.setSelected(true);
177 setComponentsEnabled();
178 String dataSourceName = dataSourceMap.get(dataSourceId);
179 dataSourceList.setSelectedValue(dataSourceName, true);
180 }
181
187 @SuppressWarnings("unchecked")
188 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
189 private void initComponents() {
190
191 jScrollPane1 = new javax.swing.JScrollPane();
192 dataSourceList = new javax.swing.JList<>();
193 dataSourceCheckBox = new javax.swing.JCheckBox();
194 dataSourceNoteLabel = new javax.swing.JLabel();
195
196 setMinimumSize(new java.awt.Dimension(150, 150));
197 setPreferredSize(new java.awt.Dimension(150, 150));
198
199 dataSourceList.setModel(new DefaultListModel<String>());
200 dataSourceList.setEnabled(false);
201 dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
202 jScrollPane1.setViewportView(dataSourceList);
203
204 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceCheckBox.text")); // NOI18N
205 dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
207 dataSourceCheckBoxActionPerformed(evt);
208 }
209 });
210
211 dataSourceNoteLabel.setFont(dataSourceNoteLabel.getFont().deriveFont(dataSourceNoteLabel.getFont().getSize()-1f));
212 org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLabel.text")); // NOI18N
213 dataSourceNoteLabel.setEnabled(false);
214
215 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
216 this.setLayout(layout);
217 layout.setHorizontalGroup(
218 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219 .addGroup(layout.createSequentialGroup()
220 .addComponent(dataSourceCheckBox)
221 .addGap(0, 0, Short.MAX_VALUE))
222 .addGroup(layout.createSequentialGroup()
223 .addContainerGap()
224 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
225 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
226 .addGroup(layout.createSequentialGroup()
227 .addComponent(dataSourceNoteLabel)
228 .addGap(0, 0, Short.MAX_VALUE)))
229 .addContainerGap())
230 );
231 layout.setVerticalGroup(
232 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
234 .addComponent(dataSourceCheckBox)
235 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
236 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
237 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
238 .addComponent(dataSourceNoteLabel)
239 .addContainerGap())
240 );
241
242 dataSourceCheckBox.getAccessibleContext().setAccessibleName("");
243 }// </editor-fold>//GEN-END:initComponents
244
245 private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
246 setComponentsEnabled();
247 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
248 this.dataSourceList.setSelectedIndices(new int[0]);
249 }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
250
251 // Variables declaration - do not modify//GEN-BEGIN:variables
252 private javax.swing.JCheckBox dataSourceCheckBox;
253 private javax.swing.JList<String> dataSourceList;
254 private javax.swing.JLabel dataSourceNoteLabel;
255 private javax.swing.JScrollPane jScrollPane1;
256 // End of variables declaration//GEN-END:variables
257}
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition Case.java:712
synchronized static Logger getLogger(String name)
Definition Logger.java:124
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.