19 package org.sleuthkit.autopsy.directorytree;
21 import java.awt.EventQueue;
22 import java.awt.event.ActionEvent;
23 import java.beans.PropertyVetoException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Objects;
29 import java.util.logging.Level;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
33 import javax.swing.AbstractAction;
34 import org.apache.commons.lang3.StringUtils;
35 import org.openide.nodes.AbstractNode;
36 import org.openide.explorer.ExplorerManager;
37 import org.openide.explorer.view.TreeView;
38 import org.openide.nodes.Children;
39 import org.openide.nodes.Node;
40 import org.openide.util.NbBundle.Messages;
93 this.content = artifactNode.getLookup().lookup(
Content.class);
94 if (this.content != null && this.content instanceof
AbstractFile) {
95 AbstractFile file = (AbstractFile) content;
99 this.setEnabled(
false);
116 this.content = fileSystemContentNode.getLookup().lookup(
Content.class);
131 this.content = abstractAbstractFileNode.getLookup().lookup(
Content.class);
164 "ViewContextAction.errorMessage.cannotFindDirectory=Failed to locate directory.",
165 "ViewContextAction.errorMessage.cannotSelectDirectory=Failed to select directory in tree.",
166 "ViewContextAction.errorMessage.cannotFindNode=Failed to locate data source node in tree.",
167 "ViewContextAction.errorMessage.unsupportedParent=Unable to navigate to content not supported in this release."
170 EventQueue.invokeLater(() -> {
176 logger.log(Level.WARNING, String.format(
"Could not navigate to unsupported content with id: %d", parentContent.
getId()));
184 Node parentTreeViewNode = null;
185 if (parentContent != null) {
194 if (parentTreeViewNode == null) {
196 logger.log(Level.SEVERE,
"Failed to locate data source node in tree.");
200 setNodeSelection(this.content, parentTreeViewNode, treeViewTopComponent, treeViewExplorerMgr);
225 logger.log(Level.SEVERE, String.format(
"Could not get parent of Content object: %s", content), ex);
244 Children rootChildren = treeViewExplorerMgr.getRootContext().getChildren();
246 if (rootDsNode != null) {
249 if (dataSource != null) {
252 if (potentialParentTreeViewNode != null) {
253 return potentialParentTreeViewNode;
284 Children rootChildren = treeViewExplorerMgr.getRootContext().getChildren();
292 List<Node> dataSourceLevelNodes = Stream.of(rootChildren.getNodes(
true))
294 .collect(Collectors.toList());
296 for (Node treeNode : dataSourceLevelNodes) {
298 if (!(treeNode.getName().equals(dsname))) {
307 if (parentTreeViewNode != null) {
309 return parentTreeViewNode;
314 logger.log(Level.SEVERE,
"Failed to locate data source node in tree.", ex);
338 BlackboardArtifact artifact = ((BlackboardArtifact) content);
344 logger.log(Level.SEVERE,
"Could not find associated content from artifact with id %d", artifact.
getId());
348 TreeView treeView = treeViewTopComponent.getTree();
349 treeView.expandNode(parentTreeViewNode);
350 if (treeViewTopComponent.
getSelectedNode().equals(parentTreeViewNode)) {
357 treeViewTopComponent.respondSelection(treeViewExplorerMgr.getSelectedNodes(),
new Node[]{parentTreeViewNode});
360 treeViewExplorerMgr.setExploredContextAndSelection(parentTreeViewNode,
new Node[]{parentTreeViewNode});
361 }
catch (PropertyVetoException ex) {
363 logger.log(Level.SEVERE,
"Failed to select the parent node in the tree view", ex);
378 return Collections.emptyList();
379 }
else if (node.getLookup().lookup(
Host.class) != null
380 || node.getLookup().lookup(
Person.class) != null
383 Children children = node.getChildren();
384 Node[] childNodes = children == null ? null : children.getNodes(
true);
385 if (childNodes == null) {
386 return Collections.emptyList();
389 return Stream.of(node.getChildren().getNodes(
true))
391 .collect(Collectors.toList());
393 return Arrays.asList(node);
413 List<Content> contentBranch = parentContent.
accept(ancestorVisitor);
414 Collections.reverse(contentBranch);
427 Node dummyRootNode =
new DirectoryTreeFilterNode(
new AbstractNode(
new RootContentChildren(contentBranch)),
true);
428 Children ancestorChildren = dummyRootNode.getChildren();
431 if (ancestorChildren.getNodesCount() == 1 && StringUtils.equals(ancestorChildren.getNodeAt(0).getName(), node.getName())) {
441 Children treeNodeChildren = node.getChildren();
442 Node parentTreeViewNode = null;
443 for (
int i = 0; i < ancestorChildren.getNodesCount(); i++) {
444 Node ancestorNode = ancestorChildren.getNodeAt(i);
445 Node[] treeNodeChilds = treeNodeChildren.getNodes(
true);
446 for (
int j = 0; j < treeNodeChilds.length; j++) {
447 Node treeNode = treeNodeChilds[j];
448 if (ancestorNode.getName().equals(treeNode.getName())) {
449 parentTreeViewNode = treeNode;
450 treeNodeChildren = treeNode.getChildren();
455 return parentTreeViewNode;
465 List<Content> lineage =
new ArrayList<>();
469 lineage.add(content);
474 logger.log(Level.SEVERE, String.format(
"Could not get parent of Content object: %s", content), ex);
476 return parent == null ? lineage : parent.
accept(
this);
504 logger.log(Level.SEVERE, String.format(
"Could not get parent of Content object: %s", content), ex);
506 return parent == null ? lineage : parent.
accept(
this);
List< Node > getDataSourceLevelNodes(Node node)
static String getNameIdentifier()
void setDirectoryListingActive()
Node getParentNodeGroupedByPersonHost(ExplorerManager treeViewExplorerMgr, Content parentContent)
static boolean hideSlackFilesInDataSourcesTree()
ViewContextAction(String displayName, Content content)
TskData.TSK_DB_FILES_TYPE_ENUM getType()
ViewContextAction(String displayName, BlackboardArtifactNode artifactNode)
Content getContentById(long id)
ViewContextAction(String displayName, AbstractFsContentNode<?extends AbstractFile > fileSystemContentNode)
SleuthkitCase getSleuthkitCase()
Node findParentNodeInTree(Content parentContent, Node node)
static final long serialVersionUID
static String getUnknownPersonId()
TskData.FileKnown getKnown()
List< Content > visit(VolumeSystem volumeSystem)
ExplorerManager getExplorerManager()
SleuthkitCase getSleuthkitCase()
ViewContextAction(String displayName, AbstractAbstractFileNode<?extends AbstractFile > abstractAbstractFileNode)
static Boolean getGroupItemsInTreeByDataSource()
Content getParentContent(Content content)
void setNodeSelection(Content content, Node parentTreeViewNode, DirectoryTreeTopComponent treeViewTopComponent, ExplorerManager treeViewExplorerMgr)
void actionPerformed(ActionEvent event)
List< Content > defaultVisit(Content content)
List< Content > visit(FileSystem fileSystem)
static boolean hideKnownFilesInDataSourcesTree()
synchronized static Logger getLogger(String name)
static final Logger logger
static Case getCurrentCaseThrows()
public< T > T accept(ContentVisitor< T > v)
void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo)
static String getNameIdentifier()
DataSource getDataSource(long objectId)
Node getParentNodeGroupedByDataSource(ExplorerManager treeViewExplorerMgr, Content parentContent)
static synchronized DirectoryTreeTopComponent findInstance()
List< Content > skipToParent(Content content)
static void error(String message)