Autopsy  4.19.3
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.ArrayList;
22 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JCheckBox;
27 import javax.swing.JLabel;
28 import javax.swing.event.ListSelectionListener;
29 import org.openide.util.NbBundle;
34 import org.sleuthkit.datamodel.DataSource;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
40 final class DataSourceFilterPanel extends AbstractDiscoveryFilterPanel {
41 
42  private static final long serialVersionUID = 1L;
43  private final static Logger logger = Logger.getLogger(DataSourceFilterPanel.class.getName());
44 
48  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
49  DataSourceFilterPanel() {
50  initComponents();
51  setUpDataSourceFilter();
52  this.add(dataSourceCheckBoxList);
53  }
54 
60  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
61  private void initComponents() {
62 
63  dataSourceCheckbox = new javax.swing.JCheckBox();
64  dataSourceCheckBoxList = new org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<>();
65 
66  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckbox, org.openide.util.NbBundle.getMessage(DataSourceFilterPanel.class, "DataSourceFilterPanel.dataSourceCheckbox.text")); // NOI18N
67  dataSourceCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
68  dataSourceCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
69  dataSourceCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
70  dataSourceCheckbox.addActionListener(new java.awt.event.ActionListener() {
71  public void actionPerformed(java.awt.event.ActionEvent evt) {
72  dataSourceCheckboxActionPerformed(evt);
73  }
74  });
75 
76  setMinimumSize(new java.awt.Dimension(250, 30));
77  setPreferredSize(new java.awt.Dimension(250, 50));
78  setRequestFocusEnabled(false);
79  setLayout(new java.awt.BorderLayout());
80  add(dataSourceCheckBoxList, java.awt.BorderLayout.CENTER);
81  }// </editor-fold>//GEN-END:initComponents
82 
83  private void dataSourceCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckboxActionPerformed
84  dataSourceCheckBoxList.setEnabled(dataSourceCheckbox.isSelected());
85  }//GEN-LAST:event_dataSourceCheckboxActionPerformed
86 
87 
88  // Variables declaration - do not modify//GEN-BEGIN:variables
89  private org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<DataSource> dataSourceCheckBoxList;
90  private javax.swing.JCheckBox dataSourceCheckbox;
91  // End of variables declaration//GEN-END:variables
92 
93  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
94  @Override
95  void configurePanel(boolean selected, List<?> selectedItems) {
96  dataSourceCheckbox.setSelected(selected);
97  if (dataSourceCheckbox.isEnabled() && dataSourceCheckbox.isSelected()) {
98  dataSourceCheckBoxList.setEnabled(true);
99  if (selectedItems != null) {
100  List<DataSource> dsList = new ArrayList<>();
101  for (Object item : selectedItems) {
102  if (item instanceof DataSource) {
103  dsList.add((DataSource) item);
104  }
105  }
106  if (!dsList.isEmpty()) {
107  dataSourceCheckBoxList.setSelectedElements(dsList);
108  }
109  }
110  } else {
111  dataSourceCheckBoxList.setEnabled(false);
112  }
113  }
114 
115  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
116  @Override
117  JCheckBox getCheckbox() {
118  return dataSourceCheckbox;
119  }
120 
121  @Override
122  JLabel getAdditionalLabel() {
123  return null;
124  }
125 
129  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
130  private void setUpDataSourceFilter() {
131  try {
132  dataSourceCheckBoxList.clearList();
133  List<DataSource> dataSources = Case.getCurrentCase().getSleuthkitCase().getDataSources();
134  Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareToIgnoreCase(ds2.getName()));
135  for (DataSource ds : dataSources) {
136  dataSourceCheckBoxList.addElement(ds.getName() + " (ID: " + ds.getId() + ")", null, ds);
137  }
138 
139  } catch (TskCoreException ex) {
140  logger.log(Level.SEVERE, "Error loading data sources", ex);
141  dataSourceCheckbox.setEnabled(false);
142  dataSourceCheckBoxList.setEnabled(false);
143  }
144  }
145 
146  @Override
147  void addListSelectionListener(ListSelectionListener listener) {
148  dataSourceCheckBoxList.addListSelectionListener(listener);
149  }
150 
151  @Override
152  boolean isFilterSupported() {
153  return !dataSourceCheckBoxList.isEmpty();
154  }
155 
156  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
157  @NbBundle.Messages({"DataSourceFilterPanel.error.text=At least one data source must be selected."})
158  @Override
159  String checkForError() {
160  if (dataSourceCheckbox.isSelected() && dataSourceCheckBoxList.getSelectedElements().isEmpty()) {
161  return Bundle.DataSourceFilterPanel_error_text();
162  }
163  return "";
164  }
165 
166  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
167  @Override
168  AbstractFilter getFilter() {
169  if (dataSourceCheckbox.isSelected()) {
170  List<DataSource> dataSources = dataSourceCheckBoxList.getSelectedElements();
171  return new SearchFiltering.DataSourceFilter(dataSources);
172  }
173  return null;
174  }
175 
176 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.