Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DirectoryTreeFilterNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.directorytree;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import javax.swing.Action;
28 import org.openide.nodes.FilterNode;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
32 import org.openide.util.lookup.ProxyLookup;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.Directory;
40 import org.sleuthkit.datamodel.Image;
41 import org.sleuthkit.datamodel.TskCoreException;
42 import org.sleuthkit.datamodel.VirtualDirectory;
43 
49 class DirectoryTreeFilterNode extends FilterNode {
50 
51  private static final Action collapseAll = new CollapseAction(
52  NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
53 
54  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
55 
59  DirectoryTreeFilterNode(Node arg, boolean createChildren) {
60  super(arg, DirectoryTreeFilterChildren.createInstance(arg, createChildren),
61  new ProxyLookup(Lookups.singleton(new OriginalNode(arg)),
62  arg.getLookup()));
63  }
64 
65  @Override
66  public String getDisplayName() {
67  final Node orig = getOriginal();
68 
69  String name = orig.getDisplayName();
70 
71  //do not show children counts for non content nodes
72  if (orig instanceof AbstractContentNode) {
73  //show only for file content nodes
74  AbstractFile file = getLookup().lookup(AbstractFile.class);
75  if (file != null) {
76  try {
77  final int numChildren = file.getChildrenCount();
78  name = name + " (" + numChildren + ")";
79  } catch (TskCoreException ex) {
80  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
81  }
82 
83  }
84  }
85 
86  return name;
87  }
88 
96  @Override
97  public Action[] getActions(boolean popup) {
98  List<Action> actions = new ArrayList<>();
99 
100  final Content content = this.getLookup().lookup(Content.class);
101  if (content != null) {
102  actions.addAll(DirectoryTreeFilterNode.getDetailActions(content));
103 
104  //extract dir action
105  Directory dir = this.getLookup().lookup(Directory.class);
106  if (dir != null) {
107  actions.add(ExtractAction.getInstance());
108  actions.add(new AbstractAction(
109  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) {
110  @Override
111  public void actionPerformed(ActionEvent e) {
112  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(dir);
113  ingestDialog.display();
114  }
115  });
116  }
117 
118  final Image img = this.getLookup().lookup(Image.class);
119 
120  VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class);
121  // determine if the virtualDireory is at root-level (Logical File Set).
122  boolean isRootVD = false;
123  if (virtualDirectory != null) {
124  try {
125  if (virtualDirectory.getParent() == null) {
126  isRootVD = true;
127  }
128  } catch (TskCoreException ex) {
129  logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS
130  }
131  }
132 
133  // 'run ingest' action and 'file search' action are added only if the
134  // selected node is img node or a root level virtual directory.
135  if (img != null || isRootVD) {
136  actions.add(new FileSearchAction(
137  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text")));
138  actions.add(new AbstractAction(
139  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) {
140  @Override
141  public void actionPerformed(ActionEvent e) {
142  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.<Content>singletonList(content));
143  ingestDialog.display();
144  }
145  });
146  }
147  }
148 
149  //check if delete actions should be added
150  final Node orig = getOriginal();
151  //TODO add a mechanism to determine if DisplayableItemNode
152  if (orig instanceof DisplayableItemNode) {
153  actions.addAll(getDeleteActions((DisplayableItemNode) orig));
154  }
155 
156  actions.add(collapseAll);
157  return actions.toArray(new Action[actions.size()]);
158  }
159 
160  private static List<Action> getDeleteActions(DisplayableItemNode original) {
161  List<Action> actions = new ArrayList<>();
162  //actions.addAll(original.accept(getDeleteActionVisitor));
163  return actions;
164  }
165 
166  private static List<Action> getDetailActions(Content c) {
167  List<Action> actions = new ArrayList<>();
168 
169  actions.addAll(ExplorerNodeActionVisitor.getActions(c));
170 
171  return actions;
172  }
173 
174  //FIXME: this seems like a big hack -jm
175  public static class OriginalNode {
176 
177  private final Node original;
178 
179  OriginalNode(Node original) {
180  this.original = original;
181  }
182 
183  Node getNode() {
184  return original;
185  }
186  }
187 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.