cleaned up handling of history in directory tree

This commit is contained in:
Brian Carrier 2013-09-11 20:40:15 -04:00 committed by jmillman
parent bccc887039
commit 09f57cd48c
2 changed files with 610 additions and 602 deletions

View File

@ -47,7 +47,7 @@ import org.sleuthkit.autopsy.datamodel.EmailExtracted.EmailExtractedFolderNode;
import org.sleuthkit.autopsy.datamodel.EmailExtracted.EmailExtractedRootNode; import org.sleuthkit.autopsy.datamodel.EmailExtracted.EmailExtractedRootNode;
import org.sleuthkit.autopsy.datamodel.ExtractedContentNode; import org.sleuthkit.autopsy.datamodel.ExtractedContentNode;
import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.FileNode;
import org.sleuthkit.autopsy.datamodel.FileSearchFilterNode; import org.sleuthkit.autopsy.datamodel.FileTypeNode;
import org.sleuthkit.autopsy.datamodel.FileSize.FileSizeRootChildren.FileSizeNode; import org.sleuthkit.autopsy.datamodel.FileSize.FileSizeRootChildren.FileSizeNode;
import org.sleuthkit.autopsy.datamodel.FileSize.FileSizeRootNode; import org.sleuthkit.autopsy.datamodel.FileSize.FileSizeRootNode;
import org.sleuthkit.autopsy.datamodel.HashsetHits.HashsetHitsRootNode; import org.sleuthkit.autopsy.datamodel.HashsetHits.HashsetHitsRootNode;
@ -60,7 +60,7 @@ import org.sleuthkit.autopsy.datamodel.VirtualDirectoryNode;
import org.sleuthkit.autopsy.datamodel.LayoutFileNode; import org.sleuthkit.autopsy.datamodel.LayoutFileNode;
import org.sleuthkit.autopsy.datamodel.RecentFilesFilterNode; import org.sleuthkit.autopsy.datamodel.RecentFilesFilterNode;
import org.sleuthkit.autopsy.datamodel.RecentFilesNode; import org.sleuthkit.autopsy.datamodel.RecentFilesNode;
import org.sleuthkit.autopsy.datamodel.SearchFiltersNode; import org.sleuthkit.autopsy.datamodel.FileTypesNode;
import org.sleuthkit.autopsy.datamodel.Tags.TagNodeRoot; import org.sleuthkit.autopsy.datamodel.Tags.TagNodeRoot;
import org.sleuthkit.autopsy.datamodel.Tags.TagsNodeRoot; import org.sleuthkit.autopsy.datamodel.Tags.TagsNodeRoot;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
@ -452,12 +452,12 @@ public class DataResultFilterNode extends FilterNode {
} }
@Override @Override
public AbstractAction visit(FileSearchFilterNode fsfn) { public AbstractAction visit(FileTypeNode fsfn) {
return openChild(fsfn); return openChild(fsfn);
} }
@Override @Override
public AbstractAction visit(SearchFiltersNode sfn) { public AbstractAction visit(FileTypesNode sfn) {
return openChild(sfn); return openChild(sfn);
} }

View File

@ -219,10 +219,16 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
// change the cursor to "waiting cursor" for this operation // change the cursor to "waiting cursor" for this operation
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// update the back and forward List
// the end is the current place,
String[] currentNodePath = backList.pollLast(); String[] currentNodePath = backList.pollLast();
String[] newCurrentNodePath = backList.peekLast();
forwardList.addLast(currentNodePath); forwardList.addLast(currentNodePath);
forwardButton.setEnabled(true);
/* We peek instead of poll because we use its existence
* in the list later on so that we do not reset the forward list
* after the selection occurs. */
String[] newCurrentNodePath = backList.peekLast();
// enable / disable the back and forward button // enable / disable the back and forward button
if (backList.size() > 1) { if (backList.size() > 1) {
@ -230,39 +236,31 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
} else { } else {
backButton.setEnabled(false); backButton.setEnabled(false);
} }
this.forwardButton.setEnabled(true);
// update the selection on directory tree // update the selection on directory tree
setSelectedNode(newCurrentNodePath, null); setSelectedNode(newCurrentNodePath, null);
this.setCursor(null); this.setCursor(null);
}//GEN-LAST:event_backButtonActionPerformed }//GEN-LAST:event_backButtonActionPerformed
private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardButtonActionPerformed private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardButtonActionPerformed
// change the cursor to "waiting cursor" for this operation // change the cursor to "waiting cursor" for this operation
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// try {
// update the back and forward List
//int newCurrentIndex = forwardList.size() - 1;
String[] newCurrentNodePath = forwardList.pollLast();
//forwardList.remove(newCurrentIndex);
backList.addLast(newCurrentNodePath);
// enable / disable the back and forward button String[] newCurrentNodePath = forwardList.pollLast();
if (!forwardList.isEmpty()) { if (!forwardList.isEmpty()) {
forwardButton.setEnabled(true); forwardButton.setEnabled(true);
} else { } else {
forwardButton.setEnabled(false); forwardButton.setEnabled(false);
} }
this.backButton.setEnabled(true);
backList.addLast(newCurrentNodePath);
backButton.setEnabled(true);
// update the selection on directory tree // update the selection on directory tree
setSelectedNode(newCurrentNodePath, null); setSelectedNode(newCurrentNodePath, null);
this.setCursor(null); this.setCursor(null);
}//GEN-LAST:event_forwardButtonActionPerformed }//GEN-LAST:event_forwardButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton backButton; private javax.swing.JButton backButton;
@ -337,7 +335,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root ((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root
} else { } else {
// if there's at least one image, load the image and open the top component // if there's at least one image, load the image and open the top component
List<Object> items = new ArrayList<Object>(); List<Object> items = new ArrayList<>();
final SleuthkitCase tskCase = currentCase.getSleuthkitCase(); final SleuthkitCase tskCase = currentCase.getSleuthkitCase();
items.add(new DataSources(tskCase)); items.add(new DataSources(tskCase));
items.add(new Views(tskCase)); items.add(new Views(tskCase));
@ -375,7 +373,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root ((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root
// Reset the forward and back lists because we're resetting the root context // Reset the forward and back lists because we're resetting the root context
resetHistoryListAndButtons(); resetHistory();
Children childNodes = em.getRootContext().getChildren(); Children childNodes = em.getRootContext().getChildren();
TreeView tree = getTree(); TreeView tree = getTree();
@ -533,7 +531,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
// case opened // case opened
if (newValue != null) { if (newValue != null) {
resetHistoryListAndButtons(); resetHistory();
} }
} // if the image is added to the case } // if the image is added to the case
else if (changed.equals(Case.CASE_ADD_DATA_SOURCE)) { else if (changed.equals(Case.CASE_ADD_DATA_SOURCE)) {
@ -671,20 +669,31 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
}); });
// update the back and forward list // update the back and forward list
Node[] selectedNode = em.getSelectedNodes(); updateHistory(em.getSelectedNodes());
if (selectedNode.length > 0) { }
Node selectedContext = selectedNode[0];
final String[] selectedPath = NodeOp.createPath(selectedContext, em.getRootContext()); private void updateHistory(Node[] selectedNodes) {
if (selectedNodes.length == 0) {
return;
}
Node selectedNode = selectedNodes[0];
String selectedNodeName = selectedNode.getName();
/* get the previous entry to make sure we don't duplicate it.
* Motivation for this is also that if we used the back button,
* then we already added the 'current' node to 'back' and we will
* detect that and not reset the forward list.
*/
String[] currentLast = backList.peekLast(); String[] currentLast = backList.peekLast();
String lastNodeName = null; String lastNodeName = null;
if (currentLast != null) { if (currentLast != null) {
lastNodeName = currentLast[currentLast.length - 1]; lastNodeName = currentLast[currentLast.length - 1];
} }
String selectedNodeName = selectedContext.getName();
if (currentLast == null || !selectedNodeName.equals(lastNodeName)) { if (currentLast == null || !selectedNodeName.equals(lastNodeName)) {
//add to the list if the last if not the same as current //add to the list if the last if not the same as current
final String[] selectedPath = NodeOp.createPath(selectedNode, em.getRootContext());
backList.addLast(selectedPath); // add the node to the "backList" backList.addLast(selectedPath); // add the node to the "backList"
if (backList.size() > 1) { if (backList.size() > 1) {
backButton.setEnabled(true); backButton.setEnabled(true);
@ -696,6 +705,17 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
forwardButton.setEnabled(false); // disable the forward Button forwardButton.setEnabled(false); // disable the forward Button
} }
} }
/**
* Resets the back and forward list, and also disable the back and forward
* buttons.
*/
private void resetHistory() {
// clear the back and forward list
backList.clear();
forwardList.clear();
backButton.setEnabled(false);
forwardButton.setEnabled(false);
} }
@Override @Override
@ -708,17 +728,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
pcs.removePropertyChangeListener(listener); pcs.removePropertyChangeListener(listener);
} }
/**
* Resets the back and forward list, and also disable the back and forward
* buttons.
*/
private void resetHistoryListAndButtons() {
// clear the back and forward list
backList.clear();
forwardList.clear();
backButton.setEnabled(false);
forwardButton.setEnabled(false);
}
/** /**
* Gets the tree on this DirectoryTreeTopComponent. * Gets the tree on this DirectoryTreeTopComponent.
@ -845,19 +855,17 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
if (path.length > 0 && (rootNodeName == null || path[0].equals(rootNodeName))) { if (path.length > 0 && (rootNodeName == null || path[0].equals(rootNodeName))) {
try { try {
final TreeView tree = getTree();
Node newSelection = NodeOp.findPath(em.getRootContext(), path); Node newSelection = NodeOp.findPath(em.getRootContext(), path);
//resetHistoryListAndButtons();
if (newSelection != null) { if (newSelection != null) {
if (rootNodeName != null) { if (rootNodeName != null) {
//called from tree auto refresh context //called from tree auto refresh context
//remove last from backlist, because auto select will result in duplication //remove last from backlist, because auto select will result in duplication
backList.pollLast(); backList.pollLast();
} }
//select
//tree.expandNode(newSelection);
em.setExploredContextAndSelection(newSelection, new Node[]{newSelection}); em.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
} }
// We need to set the selection, which will refresh dataresult and get rid of the oob exception // We need to set the selection, which will refresh dataresult and get rid of the oob exception
} catch (NodeNotFoundException ex) { } catch (NodeNotFoundException ex) {
logger.log(Level.WARNING, "Node not found", ex); logger.log(Level.WARNING, "Node not found", ex);