19 package org.sleuthkit.autopsy.directorytree;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import org.openide.nodes.FilterNode;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle;
30 import org.openide.util.lookup.Lookups;
31 import org.openide.util.lookup.ProxyLookup;
39 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
53 class DirectoryTreeFilterNode
extends FilterNode {
55 private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
56 private static final Action collapseAllAction =
new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class,
"DirectoryTreeFilterNode.action.collapseAll.text"));
67 DirectoryTreeFilterNode(Node nodeToWrap,
boolean createChildren) {
69 DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
70 new ProxyLookup(Lookups.singleton(nodeToWrap), nodeToWrap.getLookup()));
80 public String getDisplayName() {
81 final Node orig = getOriginal();
82 String name = orig.getDisplayName();
84 if (orig instanceof AbstractContentNode) {
85 AbstractFile file = getLookup().lookup(AbstractFile.class);
86 if ((file != null) && (
false == (orig instanceof BlackboardArtifactNode))) {
88 int numVisibleChildren = getVisibleChildCount(file);
95 name = name +
" \u200E(\u200E" + numVisibleChildren +
")\u200E";
97 }
catch (TskCoreException ex) {
98 logger.log(Level.SEVERE,
"Error getting children count to display for file: " + file, ex);
100 }
else if (orig instanceof BlackboardArtifactNode) {
101 BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
103 int numAttachments = artifact.getChildrenCount();
104 name = name +
" \u200E(\u200E" + numAttachments +
")\u200E";
105 }
catch (TskCoreException ex) {
106 logger.log(Level.SEVERE,
"Error getting chidlren count for atifact: " + artifact, ex);
122 private int getVisibleChildCount(AbstractFile file)
throws TskCoreException {
123 List<Content> childList = file.getChildren();
125 int numVisibleChildren = childList.size();
126 boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
127 boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
129 if (purgeKnownFiles || purgeSlackFiles) {
131 for (
int i = 0; i < childList.size(); i++) {
132 Content child = childList.get(i);
133 if (child instanceof AbstractFile) {
134 AbstractFile childFile = (AbstractFile) child;
135 if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
136 || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
137 numVisibleChildren--;
139 }
else if (child instanceof BlackboardArtifact) {
140 BlackboardArtifact bba = (BlackboardArtifact) child;
143 if ((bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
144 && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
145 numVisibleChildren--;
151 return numVisibleChildren;
163 public Action[] getActions(
boolean context) {
164 List<Action> actions =
new ArrayList<>();
166 final Content content = this.getLookup().lookup(Content.class);
167 if (content != null) {
168 actions.addAll(Arrays.asList(super.getActions(
true)));
170 actions.add(collapseAllAction);
171 return actions.toArray(
new Action[actions.size()]);
180 public Node getOriginal() {
181 return super.getOriginal();