19 package org.sleuthkit.autopsy.filesearch;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.DefaultListModel;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
43 @SuppressWarnings(
"PMD.SingularField")
47 private static final long serialVersionUID = 1L;
48 private final Map<Long, String> dataSourceMap =
new HashMap<>();
55 resetDataSourcePanel();
62 final void resetDataSourcePanel() {
63 dataSourceList.clearSelection();
65 for (ListSelectionListener listener : dataSourceList.getListSelectionListeners()){
66 dataSourceList.removeListSelectionListener(listener);
68 ((DefaultListModel<String>) dataSourceList.getModel()).clear();
69 List<String> strings = getDataSourceArray();
70 for (String dataSource : strings) {
71 ((DefaultListModel<String>) dataSourceList.getModel()).addElement(dataSource);
73 dataSourceList.setEnabled(
false);
74 dataSourceCheckBox.setSelected(
false);
75 dataSourceNoteLabel.setEnabled(
false);
76 if (dataSourceList.getModel().getSize() > 1) {
77 dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
78 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
80 dataSourceCheckBox.setEnabled(
true);
86 this.dataSourceCheckBox.setEnabled(
false);
96 List<String> dsList =
new ArrayList<>();
100 List<DataSource> dataSources = tskDb.getDataSources();
101 Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
102 for (DataSource ds : dataSources) {
103 String dsName = ds.getName();
104 File dataSourceFullName =
new File(dsName);
105 String displayName = dataSourceFullName.getName();
106 dataSourceMap.put(ds.getId(), displayName);
107 dsList.add(displayName);
110 logger.log(Level.SEVERE,
"Unable to get current open case.", ex);
111 }
catch (TskCoreException ex) {
112 logger.log(Level.SEVERE,
"Failed to get data source info from database.", ex);
122 Set<Long> getDataSourcesSelected() {
123 Set<Long> dataSourceObjIdSet =
new HashSet<>();
124 List<String> dataSources = dataSourceList.getSelectedValuesList();
125 for (Long key : dataSourceMap.keySet()) {
126 String value = dataSourceMap.get(key);
127 for (String dataSource : dataSources) {
128 if (value.equals(dataSource)) {
129 dataSourceObjIdSet.add(key);
133 return dataSourceObjIdSet;
141 boolean isSelected() {
142 return this.dataSourceCheckBox.isSelected();
149 final void setComponentsEnabled() {
150 boolean enabled = this.isSelected();
151 this.dataSourceList.setEnabled(enabled);
152 this.dataSourceNoteLabel.setEnabled(enabled);
161 void setDataSourceSelected(
long dataSourceId) {
162 this.dataSourceCheckBox.setSelected(
true);
163 setComponentsEnabled();
164 String dataSourceName = dataSourceMap.get(dataSourceId);
165 dataSourceList.setSelectedValue(dataSourceName,
true);
173 @SuppressWarnings(
"unchecked")
175 private
void initComponents() {
177 jScrollPane1 =
new javax.swing.JScrollPane();
178 dataSourceList =
new javax.swing.JList<>();
179 dataSourceCheckBox =
new javax.swing.JCheckBox();
180 dataSourceNoteLabel =
new javax.swing.JLabel();
182 setMinimumSize(
new java.awt.Dimension(150, 150));
183 setPreferredSize(
new java.awt.Dimension(150, 150));
185 dataSourceList.setModel(
new DefaultListModel<String>());
186 dataSourceList.setEnabled(
false);
187 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
188 jScrollPane1.setViewportView(dataSourceList);
190 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox,
org.openide.util.NbBundle.getMessage(
DataSourcePanel.class,
"DataSourcePanel.dataSourceCheckBox.text"));
191 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
192 public void actionPerformed(java.awt.event.ActionEvent evt) {
193 dataSourceCheckBoxActionPerformed(evt);
197 dataSourceNoteLabel.setFont(dataSourceNoteLabel.getFont().deriveFont(dataSourceNoteLabel.getFont().getSize()-1f));
198 org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel,
org.openide.util.NbBundle.getMessage(
DataSourcePanel.class,
"DataSourcePanel.dataSourceNoteLabel.text"));
199 dataSourceNoteLabel.setEnabled(
false);
201 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
202 this.setLayout(layout);
203 layout.setHorizontalGroup(
204 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205 .addGroup(layout.createSequentialGroup()
206 .addComponent(dataSourceCheckBox)
207 .addGap(0, 0, Short.MAX_VALUE))
208 .addGroup(layout.createSequentialGroup()
210 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
212 .addGroup(layout.createSequentialGroup()
213 .addComponent(dataSourceNoteLabel)
214 .addGap(0, 0, Short.MAX_VALUE)))
217 layout.setVerticalGroup(
218 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
220 .addComponent(dataSourceCheckBox)
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
223 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
224 .addComponent(dataSourceNoteLabel)
228 dataSourceCheckBox.getAccessibleContext().setAccessibleName(
"");
232 setComponentsEnabled();
233 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
234 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()
javax.swing.JLabel dataSourceNoteLabel