19 package org.sleuthkit.autopsy.filesearch;
21 import java.beans.PropertyChangeEvent;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.EnumSet;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
31 import java.util.logging.Level;
32 import javax.swing.DefaultListModel;
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
45 @SuppressWarnings(
"PMD.SingularField")
49 private static final long serialVersionUID = 1L;
50 private final Map<Long, String> dataSourceMap =
new HashMap<>();
57 resetDataSourcePanel();
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);
76 final void resetDataSourcePanel() {
77 dataSourceList.clearSelection();
79 for (ListSelectionListener listener : dataSourceList.getListSelectionListeners()){
80 dataSourceList.removeListSelectionListener(listener);
82 ((DefaultListModel<String>) dataSourceList.getModel()).clear();
83 List<String> strings = getDataSourceArray();
84 for (String dataSource : strings) {
85 ((DefaultListModel<String>) dataSourceList.getModel()).addElement(dataSource);
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);
94 dataSourceCheckBox.setEnabled(
true);
100 this.dataSourceCheckBox.setEnabled(
false);
110 List<String> dsList =
new ArrayList<>();
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);
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);
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);
147 return dataSourceObjIdSet;
155 boolean isSelected() {
156 return this.dataSourceCheckBox.isSelected();
163 final void setComponentsEnabled() {
164 boolean enabled = this.isSelected();
165 this.dataSourceList.setEnabled(enabled);
166 this.dataSourceNoteLabel.setEnabled(enabled);
175 void setDataSourceSelected(
long dataSourceId) {
176 this.dataSourceCheckBox.setSelected(
true);
177 setComponentsEnabled();
178 String dataSourceName = dataSourceMap.get(dataSourceId);
179 dataSourceList.setSelectedValue(dataSourceName,
true);
187 @SuppressWarnings(
"unchecked")
189 private
void initComponents() {
191 jScrollPane1 =
new javax.swing.JScrollPane();
192 dataSourceList =
new javax.swing.JList<>();
193 dataSourceCheckBox =
new javax.swing.JCheckBox();
194 dataSourceNoteLabel =
new javax.swing.JLabel();
196 setMinimumSize(
new java.awt.Dimension(150, 150));
197 setPreferredSize(
new java.awt.Dimension(150, 150));
199 dataSourceList.setModel(
new DefaultListModel<String>());
200 dataSourceList.setEnabled(
false);
201 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
202 jScrollPane1.setViewportView(dataSourceList);
204 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox,
org.openide.util.NbBundle.getMessage(
DataSourcePanel.class,
"DataSourcePanel.dataSourceCheckBox.text"));
205 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
207 dataSourceCheckBoxActionPerformed(evt);
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"));
213 dataSourceNoteLabel.setEnabled(
false);
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()
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)))
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)
242 dataSourceCheckBox.getAccessibleContext().setAccessibleName(
"");
246 setComponentsEnabled();
247 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
248 this.dataSourceList.setSelectedIndices(
new int[0]);
javax.swing.JList< String > dataSourceList
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
List< String > getDataSourceArray()
javax.swing.JCheckBox dataSourceCheckBox
javax.swing.JScrollPane jScrollPane1
SleuthkitCase getSleuthkitCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
javax.swing.JLabel dataSourceNoteLabel