Autopsy  3.1
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;
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  }
109 
110  final Image img = this.getLookup().lookup(Image.class);
111 
112  VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class);
113  // determine if the virtualDireory is at root-level (Logical File Set).
114  boolean isRootVD = false;
115  if (virtualDirectory != null) {
116  try {
117  if (virtualDirectory.getParent() == null) {
118  isRootVD = true;
119  }
120  } catch (TskCoreException ex) {
121  logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS
122  }
123  }
124 
125  // 'run ingest' action and 'file search' action are added only if the
126  // selected node is img node or a root level virtual directory.
127  if (img != null || isRootVD) {
128  actions.add(new FileSearchAction(
129  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text")));
130  actions.add(new AbstractAction(
131  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) {
132  @Override
133  public void actionPerformed(ActionEvent e) {
134  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.<Content>singletonList(content));
135  ingestDialog.display();
136  }
137  });
138  }
139  }
140 
141  //check if delete actions should be added
142  final Node orig = getOriginal();
143  //TODO add a mechanism to determine if DisplayableItemNode
144  if (orig instanceof DisplayableItemNode) {
145  actions.addAll(getDeleteActions((DisplayableItemNode) orig));
146  }
147 
148  actions.add(collapseAll);
149  return actions.toArray(new Action[actions.size()]);
150  }
151 
152  private static List<Action> getDeleteActions(DisplayableItemNode original) {
153  List<Action> actions = new ArrayList<>();
154  //actions.addAll(original.accept(getDeleteActionVisitor));
155  return actions;
156  }
157 
158  private static List<Action> getDetailActions(Content c) {
159  List<Action> actions = new ArrayList<>();
160 
161  actions.addAll(ExplorerNodeActionVisitor.getActions(c));
162 
163  return actions;
164  }
165 
166  //FIXME: this seems like a big hack -jm
167  public static class OriginalNode {
168 
169  private final Node original;
170 
171  OriginalNode(Node original) {
172  this.original = original;
173  }
174 
175  Node getNode() {
176  return original;
177  }
178  }
179 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.