move default file and dir node actions from actions decorator to the Node classes, so all nodes have them by default.

This commit is contained in:
adam-m 2013-02-12 16:48:44 -05:00 committed by Sean-M
parent 832b4467a6
commit 834c88882a
4 changed files with 58 additions and 41 deletions

View File

@ -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<Directory> {
*/
@Override
public Action[] getActions(boolean popup) {
return new Action[]{};
List<Action> actions = new ArrayList<Action>();
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

View File

@ -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<File> {
*/
@Override
public Action[] getActions(boolean popup) {
return new Action[]{};
List<Action> actionsList = new ArrayList<Action>();
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

View File

@ -168,16 +168,12 @@ public class DataResultFilterNode extends FilterNode {
@Override
public List<Action> visit(DirectoryNode dir) {
//preserve the default node's actions
List<Action> actions = new ArrayList<Action>();
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<Action> visit(FileNode f) {
//preserve the default node's actions
List<Action> actions = new ArrayList<Action>();
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;
}

View File

@ -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<Content> 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<Content>> {
List<Content> ret = new ArrayList<Content>();
private List<Content> 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<Content> visit(FileSystem fs) {
return visitParentButDontAddMe(fs);
}
@Override
public List<Content> visit(VolumeSystem vs) {
return visitParentButDontAddMe(vs);