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

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