From 834c88882acb47fcea327b76a264d3164718fec8 Mon Sep 17 00:00:00 2001 From: adam-m Date: Tue, 12 Feb 2013 16:48:44 -0500 Subject: [PATCH] move default file and dir node actions from actions decorator to the Node classes, so all nodes have them by default. --- .../autopsy/datamodel/DirectoryNode.java | 18 +++++++++- .../sleuthkit/autopsy/datamodel/FileNode.java | 22 ++++++++++++- .../directorytree/DataResultFilterNode.java | 26 +++++---------- .../directorytree/ViewContextAction.java | 33 +++++++------------ 4 files changed, 58 insertions(+), 41 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java index 5ecf7aa4fc..6a4d6a3252 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java @@ -18,7 +18,13 @@ */ package org.sleuthkit.autopsy.datamodel; +import java.util.ArrayList; +import java.util.List; import javax.swing.Action; +import org.sleuthkit.autopsy.directorytree.ExtractAction; +import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; +import org.sleuthkit.autopsy.directorytree.TagFileAction; +import org.sleuthkit.autopsy.directorytree.ViewContextAction; import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM; @@ -60,7 +66,17 @@ public class DirectoryNode extends AbstractFsContentNode { */ @Override public Action[] getActions(boolean popup) { - return new Action[]{}; + List actions = new ArrayList(); + if (!getDirectoryBrowseMode()) { + actions.add(new ViewContextAction("View File in Directory", this)); + actions.add(null); // creates a menu separator + } + actions.add(new NewWindowViewAction("View in New Window", this)); + actions.add(null); // creates a menu separator + actions.add(new ExtractAction("Extract Directory", this)); + actions.add(null); // creates a menu separator + actions.add(new TagFileAction(this)); + return actions.toArray(new Action[0]); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/FileNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/FileNode.java index 8486998c2d..2533dcf2e1 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/FileNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/FileNode.java @@ -18,7 +18,15 @@ */ package org.sleuthkit.autopsy.datamodel; +import java.util.ArrayList; +import java.util.List; import javax.swing.Action; +import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; +import org.sleuthkit.autopsy.directorytree.ExtractAction; +import org.sleuthkit.autopsy.directorytree.HashSearchAction; +import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; +import org.sleuthkit.autopsy.directorytree.TagFileAction; +import org.sleuthkit.autopsy.directorytree.ViewContextAction; import org.sleuthkit.datamodel.File; import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM; @@ -62,7 +70,19 @@ public class FileNode extends AbstractFsContentNode { */ @Override public Action[] getActions(boolean popup) { - return new Action[]{}; + List actionsList = new ArrayList(); + if (!this.getDirectoryBrowseMode()) { + actionsList.add(new ViewContextAction("View File in Directory", this)); + actionsList.add(null); // creates a menu separator + } + actionsList.add(new NewWindowViewAction("View in New Window", this)); + actionsList.add(new ExternalViewerAction("Open in External Viewer", this)); + actionsList.add(null); // creates a menu separator + actionsList.add(new ExtractAction("Extract File", this)); + actionsList.add(new HashSearchAction("Search for files with the same MD5 hash", this)); + actionsList.add(null); // creates a menu separator + actionsList.add(new TagFileAction(this)); + return actionsList.toArray(new Action[0]); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/Core/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index 35d86fb70c..22bf4a9a7d 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -168,16 +168,12 @@ public class DataResultFilterNode extends FilterNode { @Override public List visit(DirectoryNode dir) { + //preserve the default node's actions List actions = new ArrayList(); - if (!dir.getDirectoryBrowseMode()) { - actions.add(new ViewContextAction("View File in Directory", dir)); - actions.add(null); // creates a menu separator + for (Action action : dir.getActions(true)) { + actions.add(action); } - actions.add(new NewWindowViewAction("View in New Window", dir)); - actions.add(null); // creates a menu separator - actions.add(new ExtractAction("Extract Directory", dir)); - actions.add(null); // creates a menu separator - actions.add(new TagFileAction(dir)); + return actions; } @@ -204,18 +200,12 @@ public class DataResultFilterNode extends FilterNode { @Override public List visit(FileNode f) { + //preserve the default node's actions List actions = new ArrayList(); - if (!f.getDirectoryBrowseMode()) { - actions.add(new ViewContextAction("View File in Directory", f)); - actions.add(null); // creates a menu separator + for (Action action : f.getActions(true)) { + actions.add(action); } - actions.add(new NewWindowViewAction("View in New Window", f)); - actions.add(new ExternalViewerAction("Open in External Viewer", f)); - actions.add(null); // creates a menu separator - actions.add(new ExtractAction("Extract File", f)); - actions.add(new HashSearchAction("Search for files with the same MD5 hash", f)); - actions.add(null); // creates a menu separator - actions.add(new TagFileAction(f)); + return actions; } diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java index 7683dce2b7..16b3ea29e8 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java @@ -32,7 +32,6 @@ import org.openide.explorer.view.TreeView; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; import org.sleuthkit.autopsy.datamodel.AbstractFsContentNode; import org.sleuthkit.autopsy.datamodel.BlackboardArtifactNode; @@ -40,21 +39,14 @@ import org.sleuthkit.autopsy.datamodel.ImagesNode; import org.sleuthkit.autopsy.datamodel.RootContentChildren; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentVisitor; -import org.sleuthkit.datamodel.Directory; -import org.sleuthkit.datamodel.File; import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.Image; -import org.sleuthkit.datamodel.VirtualDirectory; -import org.sleuthkit.datamodel.LayoutFile; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.datamodel.Volume; import org.sleuthkit.datamodel.VolumeSystem; /** * View the directory content associated with the given Artifact */ -class ViewContextAction extends AbstractAction { +public class ViewContextAction extends AbstractAction { private Content content; private static final Logger logger = Logger.getLogger(ViewContextAction.class.getName()); @@ -62,14 +54,14 @@ class ViewContextAction extends AbstractAction { public ViewContextAction(String title, BlackboardArtifactNode node) { super(title); this.content = node.getLookup().lookup(Content.class); - + } - + public ViewContextAction(String title, AbstractFsContentNode node) { super(title); this.content = node.getLookup().lookup(Content.class); } - + public ViewContextAction(String title, Content content) { super(title); this.content = content; @@ -78,7 +70,6 @@ class ViewContextAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { - @Override public void run() { // create a list of Content objects starting with content's @@ -86,7 +77,7 @@ class ViewContextAction extends AbstractAction { ReverseHierarchyVisitor vtor = new ReverseHierarchyVisitor(); List hierarchy = content.accept(vtor); Collections.reverse(hierarchy); - + Node generated = new DirectoryTreeFilterNode(new AbstractNode(new RootContentChildren(hierarchy)), true); Children genChilds = generated.getChildren(); @@ -125,7 +116,6 @@ class ViewContextAction extends AbstractAction { // Another thread is needed because we have to wait for dataResult to populate EventQueue.invokeLater(new Runnable() { - @Override public void run() { DataResultTopComponent dataResult = directoryTree.getDirectoryListing(); @@ -150,15 +140,16 @@ class ViewContextAction extends AbstractAction { /** * The ReverseHierarchyVisitor class is designed to return a list of Content * objects starting with the one the user calls 'accept' with and ending at - * the Image object. Please NOTE that Content objects in this hierarchy of + * the Image object. Please NOTE that Content objects in this hierarchy of * type VolumeSystem and FileSystem are skipped. This seems to be necessary - * because org.sleuthkit.autopsy.datamodel.AbstractContentChildren.CreateSleuthkitNodeVisitor + * because + * org.sleuthkit.autopsy.datamodel.AbstractContentChildren.CreateSleuthkitNodeVisitor * does not support these types. */ private class ReverseHierarchyVisitor extends ContentVisitor.Default> { - + List ret = new ArrayList(); - + private List visitParentButDontAddMe(Content content) { Content parent = null; try { @@ -180,12 +171,12 @@ class ViewContextAction extends AbstractAction { } return parent == null ? ret : parent.accept(this); } - + @Override public List visit(FileSystem fs) { return visitParentButDontAddMe(fs); } - + @Override public List visit(VolumeSystem vs) { return visitParentButDontAddMe(vs);