refactored search action target to make use of swingworker pattern

This commit is contained in:
Brian Sweeney 2018-03-12 11:21:37 -06:00
parent b8d9d2d4b2
commit 9edda4c63a

View File

@ -22,10 +22,14 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent;
@ -36,8 +40,8 @@ import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
/**
* Panel used for common files search configuration and configuration business logic.
* Nested within CommonFilesDialog.
* Panel used for common files search configuration and configuration business
* logic. Nested within CommonFilesDialog.
*/
public final class CommonFilesPanel extends javax.swing.JPanel {
@ -71,6 +75,11 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
String title = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.title");
String pathText = NbBundle.getMessage(this.getClass(), "CommonFilesPanel.search.results.pathText");
new SwingWorker<List<AbstractFile>, Void>() {
@Override
protected List<AbstractFile> doInBackground() throws Exception {
List<AbstractFile> contentList = null;
try {
Case currentCase = Case.getOpenCase();
@ -87,15 +96,35 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
contentList = Collections.<AbstractFile>emptyList();
}
CommonFilesNode sn = new CommonFilesNode(contentList);
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();
}
/**
* This method is called from within the constructor to initialize the form.