Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceFilterPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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.discovery;
20 
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.stream.Collectors;
24 import javax.swing.DefaultListModel;
25 import javax.swing.JCheckBox;
26 import javax.swing.JLabel;
27 import javax.swing.JList;
30 import org.sleuthkit.datamodel.DataSource;
31 import org.sleuthkit.datamodel.TskCoreException;
32 
36 final class DataSourceFilterPanel extends AbstractDiscoveryFilterPanel {
37 
38  private static final long serialVersionUID = 1L;
39  private final static Logger logger = Logger.getLogger(DataSourceFilterPanel.class.getName());
40 
44  DataSourceFilterPanel() {
45  initComponents();
46  setUpDataSourceFilter();
47  }
48 
54  @SuppressWarnings("unchecked")
55  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
56  private void initComponents() {
57 
58  dataSourceCheckbox = new javax.swing.JCheckBox();
59  dataSourceScrollPane = new javax.swing.JScrollPane();
60  dataSourceList = new javax.swing.JList<>();
61 
62  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckbox, org.openide.util.NbBundle.getMessage(DataSourceFilterPanel.class, "DataSourceFilterPanel.dataSourceCheckbox.text")); // NOI18N
63  dataSourceCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
64  dataSourceCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
65  dataSourceCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
66  dataSourceCheckbox.addActionListener(new java.awt.event.ActionListener() {
67  public void actionPerformed(java.awt.event.ActionEvent evt) {
68  dataSourceCheckboxActionPerformed(evt);
69  }
70  });
71 
72  setMinimumSize(new java.awt.Dimension(250, 30));
73  setPreferredSize(new java.awt.Dimension(250, 30));
74  setRequestFocusEnabled(false);
75 
76  dataSourceScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
77 
78  dataSourceList.setModel(new DefaultListModel<DataSourceItem>());
79  dataSourceList.setEnabled(false);
80  dataSourceList.setVisibleRowCount(5);
81  dataSourceScrollPane.setViewportView(dataSourceList);
82 
83  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
84  this.setLayout(layout);
85  layout.setHorizontalGroup(
86  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
87  .addComponent(dataSourceScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
88  );
89  layout.setVerticalGroup(
90  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
91  .addGroup(layout.createSequentialGroup()
92  .addComponent(dataSourceScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
93  .addGap(0, 0, 0))
94  );
95  }// </editor-fold>//GEN-END:initComponents
96 
97  private void dataSourceCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckboxActionPerformed
98  dataSourceList.setEnabled(dataSourceCheckbox.isSelected());
99  }//GEN-LAST:event_dataSourceCheckboxActionPerformed
100 
101 
102  // Variables declaration - do not modify//GEN-BEGIN:variables
103  private javax.swing.JCheckBox dataSourceCheckbox;
104  private javax.swing.JList<DataSourceItem> dataSourceList;
105  private javax.swing.JScrollPane dataSourceScrollPane;
106  // End of variables declaration//GEN-END:variables
107 
108  @Override
109  void configurePanel(boolean selected, int[] indicesSelected) {
110  dataSourceCheckbox.setSelected(selected);
111  if (dataSourceCheckbox.isEnabled() && dataSourceCheckbox.isSelected()) {
112  dataSourceScrollPane.setEnabled(true);
113  dataSourceList.setEnabled(true);
114  if (indicesSelected != null) {
115  dataSourceList.setSelectedIndices(indicesSelected);
116  }
117  } else {
118  dataSourceScrollPane.setEnabled(false);
119  dataSourceList.setEnabled(false);
120  }
121  }
122 
123  @Override
124  JCheckBox getCheckbox() {
125  return dataSourceCheckbox;
126  }
127 
128  @Override
129  JLabel getAdditionalLabel() {
130  return null;
131  }
132 
136  private void setUpDataSourceFilter() {
137  int count = 0;
138  try {
139  DefaultListModel<DataSourceItem> dsListModel = (DefaultListModel<DataSourceItem>) dataSourceList.getModel();
140  dsListModel.removeAllElements();
141  for (DataSource ds : Case.getCurrentCase().getSleuthkitCase().getDataSources()) {
142  dsListModel.add(count, new DataSourceItem(ds));
143  }
144  } catch (TskCoreException ex) {
145  logger.log(Level.SEVERE, "Error loading data sources", ex);
146  dataSourceCheckbox.setEnabled(false);
147  dataSourceList.setEnabled(false);
148  }
149  }
150 
151  @Override
152  JList<?> getList() {
153  return dataSourceList;
154  }
155 
160  private class DataSourceItem {
161 
162  private final DataSource ds;
163 
169  DataSourceItem(DataSource ds) {
170  this.ds = ds;
171  }
172 
178  DataSource getDataSource() {
179  return ds;
180  }
181 
182  @Override
183  public String toString() {
184  return ds.getName() + " (ID: " + ds.getId() + ")";
185  }
186  }
187 
188  @Override
189  String checkForError() {
190  if (dataSourceCheckbox.isSelected() && dataSourceList.getSelectedValuesList().isEmpty()) {
191  return "At least one size must be selected";
192  }
193  return "";
194  }
195 
196  @Override
197  FileSearchFiltering.FileFilter getFilter() {
198  if (dataSourceCheckbox.isSelected()) {
199  List<DataSource> dataSources = dataSourceList.getSelectedValuesList().stream().map(t -> t.getDataSource()).collect(Collectors.toList());
200  return new FileSearchFiltering.DataSourceFilter(dataSources);
201  }
202  return null;
203  }
204 }

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