Autopsy  4.17.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.ui;
20 
21 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.stream.Collectors;
26 import javax.swing.DefaultListModel;
27 import javax.swing.JCheckBox;
28 import javax.swing.JLabel;
29 import javax.swing.JList;
30 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.DataSource;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 final class DataSourceFilterPanel extends AbstractDiscoveryFilterPanel {
42 
43  private static final long serialVersionUID = 1L;
44  private final static Logger logger = Logger.getLogger(DataSourceFilterPanel.class.getName());
45 
49  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
50  DataSourceFilterPanel() {
51  initComponents();
52  setUpDataSourceFilter();
53  }
54 
60  @SuppressWarnings("unchecked")
61  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
62  private void initComponents() {
63 
64  dataSourceCheckbox = new javax.swing.JCheckBox();
65  dataSourceScrollPane = new javax.swing.JScrollPane();
66  dataSourceList = new javax.swing.JList<>();
67 
68  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckbox, org.openide.util.NbBundle.getMessage(DataSourceFilterPanel.class, "DataSourceFilterPanel.dataSourceCheckbox.text")); // NOI18N
69  dataSourceCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
70  dataSourceCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
71  dataSourceCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
72  dataSourceCheckbox.addActionListener(new java.awt.event.ActionListener() {
73  public void actionPerformed(java.awt.event.ActionEvent evt) {
74  dataSourceCheckboxActionPerformed(evt);
75  }
76  });
77 
78  setMinimumSize(new java.awt.Dimension(250, 30));
79  setPreferredSize(new java.awt.Dimension(250, 30));
80  setRequestFocusEnabled(false);
81 
82  dataSourceScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
83 
84  dataSourceList.setModel(new DefaultListModel<DataSourceItem>());
85  dataSourceList.setEnabled(false);
86  dataSourceList.setVisibleRowCount(5);
87  dataSourceScrollPane.setViewportView(dataSourceList);
88 
89  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
90  this.setLayout(layout);
91  layout.setHorizontalGroup(
92  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93  .addComponent(dataSourceScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
94  );
95  layout.setVerticalGroup(
96  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97  .addGroup(layout.createSequentialGroup()
98  .addComponent(dataSourceScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
99  .addGap(0, 0, 0))
100  );
101  }// </editor-fold>//GEN-END:initComponents
102 
103  private void dataSourceCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckboxActionPerformed
104  dataSourceList.setEnabled(dataSourceCheckbox.isSelected());
105  }//GEN-LAST:event_dataSourceCheckboxActionPerformed
106 
107 
108  // Variables declaration - do not modify//GEN-BEGIN:variables
109  private javax.swing.JCheckBox dataSourceCheckbox;
110  private javax.swing.JList<DataSourceItem> dataSourceList;
111  private javax.swing.JScrollPane dataSourceScrollPane;
112  // End of variables declaration//GEN-END:variables
113 
114  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
115  @Override
116  void configurePanel(boolean selected, int[] indicesSelected) {
117  dataSourceCheckbox.setSelected(selected);
118  if (dataSourceCheckbox.isEnabled() && dataSourceCheckbox.isSelected()) {
119  dataSourceScrollPane.setEnabled(true);
120  dataSourceList.setEnabled(true);
121  if (indicesSelected != null) {
122  dataSourceList.setSelectedIndices(indicesSelected);
123  }
124  } else {
125  dataSourceScrollPane.setEnabled(false);
126  dataSourceList.setEnabled(false);
127  }
128  }
129 
130  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
131  @Override
132  JCheckBox getCheckbox() {
133  return dataSourceCheckbox;
134  }
135 
136  @Override
137  JLabel getAdditionalLabel() {
138  return null;
139  }
140 
144  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
145  private void setUpDataSourceFilter() {
146  int count = 0;
147  try {
148  DefaultListModel<DataSourceItem> dsListModel = (DefaultListModel<DataSourceItem>) dataSourceList.getModel();
149  dsListModel.removeAllElements();
150  List<DataSource> dataSources = Case.getCurrentCase().getSleuthkitCase().getDataSources();
151  Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareToIgnoreCase(ds2.getName()));
152  for (DataSource ds : dataSources) {
153  dsListModel.add(count, new DataSourceItem(ds));
154  count++;
155  }
156 
157  } catch (TskCoreException ex) {
158  logger.log(Level.SEVERE, "Error loading data sources", ex);
159  dataSourceCheckbox.setEnabled(false);
160  dataSourceList.setEnabled(false);
161  }
162  }
163 
164  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
165  @Override
166  JList<?> getList() {
167  return dataSourceList;
168  }
169 
174  private class DataSourceItem {
175 
176  private final DataSource ds;
177 
183  DataSourceItem(DataSource ds) {
184  this.ds = ds;
185  }
186 
192  DataSource getDataSource() {
193  return ds;
194  }
195 
196  @Override
197  public String toString() {
198  return ds.getName() + " (ID: " + ds.getId() + ")";
199  }
200  }
201 
203  @NbBundle.Messages({"DataSourceFilterPanel.error.text=At least one data source must be selected."})
204  @Override
205  String checkForError() {
206  if (dataSourceCheckbox.isSelected() && dataSourceList.getSelectedValuesList().isEmpty()) {
207  return Bundle.DataSourceFilterPanel_error_text();
208  }
209  return "";
210  }
211 
212  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
213  @Override
214  AbstractFilter getFilter() {
215  if (dataSourceCheckbox.isSelected()) {
216  List<DataSource> dataSources = dataSourceList.getSelectedValuesList().stream().map(t -> t.getDataSource()).collect(Collectors.toList());
217  return new SearchFiltering.DataSourceFilter(dataSources);
218  }
219  return null;
220  }
221 }

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