mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
refactored search action target to make use of swingworker pattern
This commit is contained in:
parent
b8d9d2d4b2
commit
9edda4c63a
@ -22,10 +22,14 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingWorker;
|
||||||
import org.openide.util.Exceptions;
|
import org.openide.util.Exceptions;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.windows.TopComponent;
|
import org.openide.windows.TopComponent;
|
||||||
|
import org.openide.windows.WindowManager;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
|
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
|
||||||
import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent;
|
import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent;
|
||||||
@ -36,15 +40,15 @@ import org.sleuthkit.datamodel.SleuthkitCase;
|
|||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Panel used for common files search configuration and configuration business logic.
|
* Panel used for common files search configuration and configuration business
|
||||||
* Nested within CommonFilesDialog.
|
* logic. Nested within CommonFilesDialog.
|
||||||
*/
|
*/
|
||||||
public final class CommonFilesPanel extends javax.swing.JPanel {
|
public final class CommonFilesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class .getName());
|
private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form CommonFilesPanel
|
* Creates new form CommonFilesPanel
|
||||||
*/
|
*/
|
||||||
@ -71,30 +75,55 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
|
|||||||
String title = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.title");
|
String title = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.title");
|
||||||
String pathText = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.pathText");
|
String pathText = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.pathText");
|
||||||
|
|
||||||
List<AbstractFile> contentList = null;
|
new SwingWorker<List<AbstractFile>, Void>() {
|
||||||
try {
|
|
||||||
Case currentCase = Case.getOpenCase();
|
|
||||||
SleuthkitCase tskDb = currentCase.getSleuthkitCase();
|
|
||||||
|
|
||||||
//TODO this is sort of a misues of the findAllFilesWhere function and seems brittle...
|
|
||||||
//...consider doing something else
|
|
||||||
contentList = tskDb.findAllFilesWhere("1 == 1 GROUP BY md5 HAVING COUNT(*) > 1;");
|
|
||||||
} catch (TskCoreException | NoCurrentCaseException ex) {
|
|
||||||
LOGGER.log(Level.WARNING, "Error while trying to get common files.", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contentList == null) {
|
@Override
|
||||||
contentList = Collections.<AbstractFile>emptyList();
|
protected List<AbstractFile> doInBackground() throws Exception {
|
||||||
}
|
|
||||||
|
|
||||||
CommonFilesNode sn = new CommonFilesNode(contentList);
|
List<AbstractFile> contentList = null;
|
||||||
final TopComponent searchResultWin = DataResultTopComponent.createInstance(
|
try {
|
||||||
title,
|
Case currentCase = Case.getOpenCase();
|
||||||
pathText,
|
SleuthkitCase tskDb = currentCase.getSleuthkitCase();
|
||||||
new TableFilterNode(sn, true, sn.getName()),
|
|
||||||
contentList.size());
|
|
||||||
|
|
||||||
searchResultWin.requestActive(); // make it the active top component
|
//TODO this is sort of a misues of the findAllFilesWhere function and seems brittle...
|
||||||
|
//...consider doing something else
|
||||||
|
contentList = tskDb.findAllFilesWhere("1 == 1 GROUP BY md5 HAVING COUNT(*) > 1;");
|
||||||
|
} catch (TskCoreException | NoCurrentCaseException ex) {
|
||||||
|
LOGGER.log(Level.WARNING, "Error while trying to get common files.", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contentList == null) {
|
||||||
|
contentList = Collections.<AbstractFile>emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
super.done();
|
||||||
|
|
||||||
|
List<AbstractFile> contentList = null;
|
||||||
|
CommonFilesNode sn = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
contentList = get();
|
||||||
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
|
LOGGER.log(Level.WARNING, "Error while trying to get common files.", ex);
|
||||||
|
contentList = Collections.<AbstractFile>emptyList();
|
||||||
|
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), ex.getCause().getMessage(), "", JOptionPane.ERROR_MESSAGE);
|
||||||
|
} finally {
|
||||||
|
sn = new CommonFilesNode(contentList);
|
||||||
|
|
||||||
|
final TopComponent searchResultWin = DataResultTopComponent.createInstance(
|
||||||
|
title,
|
||||||
|
pathText,
|
||||||
|
new TableFilterNode(sn, true, sn.getName()),
|
||||||
|
contentList.size());
|
||||||
|
searchResultWin.requestActive(); // make it the active top component
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user