19 package org.sleuthkit.autopsy.commonfilesearch;
21 import java.sql.SQLException;
22 import java.util.ArrayList;
23 import java.util.Collection;
25 import java.util.Map.Entry;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import javax.swing.ComboBoxModel;
29 import javax.swing.SwingUtilities;
30 import javax.swing.SwingWorker;
31 import org.openide.explorer.ExplorerManager;
32 import org.openide.util.NbBundle;
47 @SuppressWarnings(
"PMD.SingularField")
50 private static final long serialVersionUID = 1L;
52 private static final Long NO_DATA_SOURCE_SELECTED = -1L;
58 private boolean singleDataSource =
false;
59 private String selectedDataSource =
"";
67 "CommonFilesPanel.title=Common Files Panel",
68 "CommonFilesPanel.exception=Unexpected Exception loading DataSources."})
72 this.setupDataSources();
74 this.errorText.setVisible(
false);
84 "CommonFilesPanel.buildDataSourceMap.done.tskCoreException=Unable to run query against DB.",
85 "CommonFilesPanel.buildDataSourceMap.done.noCurrentCaseException=Unable to open case file.",
86 "CommonFilesPanel.buildDataSourceMap.done.exception=Unexpected exception building data sources map.",
87 "CommonFilesPanel.buildDataSourceMap.done.interupted=Something went wrong building the Common Files Search dialog box.",
88 "CommonFilesPanel.buildDataSourceMap.done.sqlException=Unable to query db for data sources.",
89 "CommonFilesPanel.buildDataSourcesMap.updateUi.noDataSources=No data sources were found."})
92 new SwingWorker<Map<Long, String>, Void>() {
94 private void updateUi() {
99 if (dataSourcesNames.length > 0) {
104 boolean multipleDataSources = this.caseHasMultipleSources();
108 if (!multipleDataSources) {
110 withinDataSourceSelected(
true);
120 private boolean caseHasMultipleSources() {
125 protected Map<Long, String> doInBackground()
throws NoCurrentCaseException, TskCoreException, SQLException {
131 protected void done() {
138 }
catch (InterruptedException ex) {
139 LOGGER.log(Level.SEVERE,
"Interrupted while building Common Files Search dialog.", ex);
141 }
catch (ExecutionException ex) {
143 Throwable inner = ex.getCause();
144 if (inner instanceof TskCoreException) {
145 LOGGER.log(Level.SEVERE,
"Failed to load data sources from database.", ex);
146 errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_tskCoreException();
147 }
else if (inner instanceof NoCurrentCaseException) {
148 LOGGER.log(Level.SEVERE,
"Current case has been closed.", ex);
149 errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_noCurrentCaseException();
150 }
else if (inner instanceof SQLException) {
151 LOGGER.log(Level.SEVERE,
"Unable to query db for data sources.", ex);
152 errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_sqlException();
154 LOGGER.log(Level.SEVERE,
"Unexpected exception while building Common Files Search dialog panel.", ex);
155 errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_exception();
164 "CommonFilesPanel.search.results.titleAll=Common Files (All Data Sources)",
165 "CommonFilesPanel.search.results.titleSingle=Common Files (Match Within Data Source: %s)",
166 "CommonFilesPanel.search.results.pathText=Common Files Search Results",
167 "CommonFilesPanel.search.done.tskCoreException=Unable to run query against DB.",
168 "CommonFilesPanel.search.done.noCurrentCaseException=Unable to open case file.",
169 "CommonFilesPanel.search.done.exception=Unexpected exception running Common Files Search.",
170 "CommonFilesPanel.search.done.interupted=Something went wrong finding common files.",
171 "CommonFilesPanel.search.done.sqlException=Unable to query db for files or data sources."})
173 String pathText = Bundle.CommonFilesPanel_search_results_pathText();
175 new SwingWorker<CommonFilesMetadata, Void>() {
177 private String tabTitle;
179 private void setTitleForAllDataSources() {
180 this.tabTitle = Bundle.CommonFilesPanel_search_results_titleAll();
183 private void setTitleForSingleSource(Long dataSourceId) {
184 final String CommonFilesPanel_search_results_titleSingle = Bundle.CommonFilesPanel_search_results_titleSingle();
185 final Object[] dataSourceName =
new Object[]{dataSourceMap.get(dataSourceId)};
187 this.tabTitle = String.format(CommonFilesPanel_search_results_titleSingle, dataSourceName);
190 private Long determineDataSourceId() {
195 selectedObjId = dataSource.getKey();
200 return selectedObjId;
204 @SuppressWarnings({
"BoxedValueEquality",
"NumberEquality"})
206 Long dataSourceId = determineDataSourceId();
209 boolean filterByMedia =
false;
210 boolean filterByDocuments =
false;
211 if (selectedFileCategoriesButton.isSelected()) {
212 if (pictureVideoCheckbox.isSelected()) {
213 filterByMedia =
true;
215 if (documentsCheckbox.isSelected()) {
216 filterByDocuments =
true;
222 setTitleForAllDataSources();
226 setTitleForSingleSource(dataSourceId);
237 protected void done() {
251 Collection<DataResultViewer> viewers =
new ArrayList<>(1);
256 }
catch (InterruptedException ex) {
257 LOGGER.log(Level.SEVERE,
"Interrupted while loading Common Files", ex);
259 }
catch (ExecutionException ex) {
261 Throwable inner = ex.getCause();
262 if (inner instanceof TskCoreException) {
263 LOGGER.log(Level.SEVERE,
"Failed to load files from database.", ex);
264 errorMessage = Bundle.CommonFilesPanel_search_done_tskCoreException();
265 }
else if (inner instanceof NoCurrentCaseException) {
266 LOGGER.log(Level.SEVERE,
"Current case has been closed.", ex);
267 errorMessage = Bundle.CommonFilesPanel_search_done_noCurrentCaseException();
268 }
else if (inner instanceof SQLException) {
269 LOGGER.log(Level.SEVERE,
"Unable to query db for files.", ex);
270 errorMessage = Bundle.CommonFilesPanel_search_done_sqlException();
272 LOGGER.log(Level.SEVERE,
"Unexpected exception while running Common Files Search.", ex);
273 errorMessage = Bundle.CommonFilesPanel_search_done_exception();
286 @SuppressWarnings(
"unchecked")
288 private
void initComponents() {
290 dataSourcesButtonGroup =
new javax.swing.ButtonGroup();
291 fileTypeFilterButtonGroup =
new javax.swing.ButtonGroup();
292 searchButton =
new javax.swing.JButton();
293 allDataSourcesRadioButton =
new javax.swing.JRadioButton();
294 withinDataSourceRadioButton =
new javax.swing.JRadioButton();
295 selectDataSourceComboBox =
new javax.swing.JComboBox<>();
296 commonFilesSearchLabel =
new javax.swing.JLabel();
297 cancelButton =
new javax.swing.JButton();
298 allFileCategoriesRadioButton =
new javax.swing.JRadioButton();
299 selectedFileCategoriesButton =
new javax.swing.JRadioButton();
300 pictureVideoCheckbox =
new javax.swing.JCheckBox();
301 documentsCheckbox =
new javax.swing.JCheckBox();
302 dataSourceLabel =
new javax.swing.JLabel();
303 categoriesLabel =
new javax.swing.JLabel();
304 errorText =
new javax.swing.JLabel();
306 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.searchButton.text"));
307 searchButton.setEnabled(
false);
308 searchButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
309 searchButton.addActionListener(
new java.awt.event.ActionListener() {
310 public void actionPerformed(java.awt.event.ActionEvent evt) {
311 searchButtonActionPerformed(evt);
315 dataSourcesButtonGroup.add(allDataSourcesRadioButton);
316 allDataSourcesRadioButton.setSelected(
true);
317 org.openide.awt.Mnemonics.setLocalizedText(allDataSourcesRadioButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.allDataSourcesRadioButton.text"));
318 allDataSourcesRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
319 allDataSourcesRadioButton.addActionListener(
new java.awt.event.ActionListener() {
320 public void actionPerformed(java.awt.event.ActionEvent evt) {
321 allDataSourcesRadioButtonActionPerformed(evt);
325 dataSourcesButtonGroup.add(withinDataSourceRadioButton);
326 org.openide.awt.Mnemonics.setLocalizedText(withinDataSourceRadioButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.withinDataSourceRadioButton.text"));
327 withinDataSourceRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
328 withinDataSourceRadioButton.addActionListener(
new java.awt.event.ActionListener() {
329 public void actionPerformed(java.awt.event.ActionEvent evt) {
330 withinDataSourceRadioButtonActionPerformed(evt);
334 selectDataSourceComboBox.setModel(dataSourcesList);
335 selectDataSourceComboBox.setEnabled(
false);
336 selectDataSourceComboBox.addActionListener(
new java.awt.event.ActionListener() {
337 public void actionPerformed(java.awt.event.ActionEvent evt) {
338 selectDataSourceComboBoxActionPerformed(evt);
342 org.openide.awt.Mnemonics.setLocalizedText(commonFilesSearchLabel,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.commonFilesSearchLabel.text"));
343 commonFilesSearchLabel.setFocusable(
false);
345 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.cancelButton.text"));
346 cancelButton.setActionCommand(
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.cancelButton.actionCommand"));
347 cancelButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
348 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
349 public void actionPerformed(java.awt.event.ActionEvent evt) {
350 cancelButtonActionPerformed(evt);
354 fileTypeFilterButtonGroup.add(allFileCategoriesRadioButton);
355 org.openide.awt.Mnemonics.setLocalizedText(allFileCategoriesRadioButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.allFileCategoriesRadioButton.text"));
356 allFileCategoriesRadioButton.setToolTipText(
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.allFileCategoriesRadioButton.toolTipText"));
357 allFileCategoriesRadioButton.addActionListener(
new java.awt.event.ActionListener() {
358 public void actionPerformed(java.awt.event.ActionEvent evt) {
359 allFileCategoriesRadioButtonActionPerformed(evt);
363 fileTypeFilterButtonGroup.add(selectedFileCategoriesButton);
364 selectedFileCategoriesButton.setSelected(
true);
365 org.openide.awt.Mnemonics.setLocalizedText(selectedFileCategoriesButton,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.selectedFileCategoriesButton.text"));
366 selectedFileCategoriesButton.setToolTipText(
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.selectedFileCategoriesButton.toolTipText"));
367 selectedFileCategoriesButton.addActionListener(
new java.awt.event.ActionListener() {
368 public void actionPerformed(java.awt.event.ActionEvent evt) {
369 selectedFileCategoriesButtonActionPerformed(evt);
373 pictureVideoCheckbox.setSelected(
true);
374 org.openide.awt.Mnemonics.setLocalizedText(pictureVideoCheckbox,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.pictureVideoCheckbox.text"));
375 pictureVideoCheckbox.addActionListener(
new java.awt.event.ActionListener() {
376 public void actionPerformed(java.awt.event.ActionEvent evt) {
377 pictureVideoCheckboxActionPerformed(evt);
381 documentsCheckbox.setSelected(
true);
382 org.openide.awt.Mnemonics.setLocalizedText(documentsCheckbox,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.documentsCheckbox.text"));
383 documentsCheckbox.addActionListener(
new java.awt.event.ActionListener() {
384 public void actionPerformed(java.awt.event.ActionEvent evt) {
385 documentsCheckboxActionPerformed(evt);
389 org.openide.awt.Mnemonics.setLocalizedText(dataSourceLabel,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.text"));
390 dataSourceLabel.setName(
"");
392 org.openide.awt.Mnemonics.setLocalizedText(categoriesLabel,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.categoriesLabel.text"));
393 categoriesLabel.setName(
"");
395 errorText.setForeground(
new java.awt.Color(255, 0, 0));
396 org.openide.awt.Mnemonics.setLocalizedText(errorText,
org.openide.util.NbBundle.getMessage(
CommonFilesPanel.class,
"CommonFilesPanel.errorText.text"));
398 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
399 this.setLayout(layout);
400 layout.setHorizontalGroup(
401 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
402 .addGroup(layout.createSequentialGroup()
404 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
405 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
406 .addComponent(errorText)
407 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
408 .addComponent(searchButton)
409 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
410 .addComponent(cancelButton)
412 .addGroup(layout.createSequentialGroup()
413 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
414 .addComponent(categoriesLabel)
415 .addComponent(commonFilesSearchLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
416 .addComponent(dataSourceLabel)
417 .addGroup(layout.createSequentialGroup()
419 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
420 .addGroup(layout.createSequentialGroup()
422 .addComponent(selectDataSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE))
423 .addComponent(withinDataSourceRadioButton)
424 .addComponent(allDataSourcesRadioButton)
425 .addComponent(allFileCategoriesRadioButton)
426 .addComponent(selectedFileCategoriesButton)
427 .addGroup(layout.createSequentialGroup()
429 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
430 .addComponent(pictureVideoCheckbox)
431 .addComponent(documentsCheckbox))))))
432 .addGap(19, 19, 19))))
434 layout.setVerticalGroup(
435 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
436 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
438 .addComponent(commonFilesSearchLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
440 .addComponent(dataSourceLabel)
441 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
442 .addComponent(allDataSourcesRadioButton)
443 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
444 .addComponent(withinDataSourceRadioButton)
445 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
446 .addComponent(selectDataSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
448 .addComponent(categoriesLabel)
449 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
450 .addComponent(selectedFileCategoriesButton)
451 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
452 .addComponent(pictureVideoCheckbox)
453 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
454 .addComponent(documentsCheckbox)
455 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
456 .addComponent(allFileCategoriesRadioButton)
457 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
458 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
459 .addComponent(cancelButton)
460 .addComponent(searchButton)
461 .addComponent(errorText)))
467 SwingUtilities.windowForComponent(
this).dispose();
471 selectDataSourceComboBox.setEnabled(!allDataSourcesRadioButton.isSelected());
472 singleDataSource =
false;
476 final Object selectedItem = selectDataSourceComboBox.getSelectedItem();
477 if (selectedItem != null) {
478 selectedDataSource = selectedItem.toString();
480 selectedDataSource =
"";
485 withinDataSourceSelected(withinDataSourceRadioButton.isSelected());
489 SwingUtilities.windowForComponent(
this).dispose();
493 this.manageCheckBoxState();
494 this.toggleErrorTextAndSearchBox();
498 this.manageCheckBoxState();
502 this.toggleErrorTextAndSearchBox();
506 this.toggleErrorTextAndSearchBox();
510 if (!this.pictureVideoCheckbox.isSelected() && !this.documentsCheckbox.isSelected() && !this.allFileCategoriesRadioButton.isSelected()) {
511 this.searchButton.setEnabled(
false);
512 this.errorText.setVisible(
true);
514 this.searchButton.setEnabled(
true);
515 this.errorText.setVisible(
false);
520 selectDataSourceComboBox.setEnabled(selected);
521 if (selectDataSourceComboBox.isEnabled()) {
522 selectDataSourceComboBox.setSelectedIndex(0);
523 singleDataSource =
true;
529 if (this.allFileCategoriesRadioButton.isSelected()) {
531 this.pictureViewCheckboxState = this.pictureVideoCheckbox.isSelected();
532 this.documentsCheckboxState = this.documentsCheckbox.isSelected();
534 this.pictureVideoCheckbox.setEnabled(
false);
535 this.documentsCheckbox.setEnabled(
false);
538 if (this.selectedFileCategoriesButton.isSelected()) {
540 this.pictureVideoCheckbox.setSelected(this.pictureViewCheckboxState);
541 this.documentsCheckbox.setSelected(this.documentsCheckboxState);
543 this.pictureVideoCheckbox.setEnabled(
true);
544 this.documentsCheckbox.setEnabled(
true);
546 this.toggleErrorTextAndSearchBox();
void toggleErrorTextAndSearchBox()
javax.swing.JCheckBox pictureVideoCheckbox
void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel dataSourceLabel
void searchButtonActionPerformed(java.awt.event.ActionEvent evt)
boolean pictureViewCheckboxState
Map< Long, String > getDataSourceMap()
void selectDataSourceComboBoxActionPerformed(java.awt.event.ActionEvent evt)
void withinDataSourceRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
String selectedDataSource
void allDataSourcesRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JCheckBox documentsCheckbox
static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount)
void withinDataSourceSelected(boolean selected)
javax.swing.ButtonGroup dataSourcesButtonGroup
javax.swing.JLabel categoriesLabel
javax.swing.JRadioButton allDataSourcesRadioButton
javax.swing.JRadioButton selectedFileCategoriesButton
javax.swing.ButtonGroup fileTypeFilterButtonGroup
javax.swing.JButton searchButton
javax.swing.JLabel errorText
javax.swing.JButton cancelButton
void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JRadioButton allFileCategoriesRadioButton
javax.swing.JRadioButton withinDataSourceRadioButton
boolean documentsCheckboxState
static final Long NO_DATA_SOURCE_SELECTED
void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt)
static void info(String message)
javax.swing.JLabel commonFilesSearchLabel
ComboBoxModel< String > dataSourcesList
void manageCheckBoxState()
javax.swing.JComboBox< String > selectDataSourceComboBox
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)
static void error(String message)
Map< Long, String > dataSourceMap