Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SelectionContext.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2011-2017 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 */
19package org.sleuthkit.autopsy.directorytree;
20
21import java.util.Objects;
22import org.openide.nodes.Node;
23import org.openide.util.NbBundle;
24import org.sleuthkit.autopsy.casemodule.CasePreferences;
25import org.sleuthkit.autopsy.datamodel.DataSourceFilesNode;
26import org.sleuthkit.autopsy.datamodel.DataSourcesNode;
27import static org.sleuthkit.autopsy.directorytree.Bundle.*;
28
29@NbBundle.Messages({"SelectionContext.dataSources=Data Sources",
30 "SelectionContext.dataSourceFiles=Data Source Files",
31 "SelectionContext.views=Views"})
33 DATA_SOURCES(SelectionContext_dataSources()),
34 VIEWS(SelectionContext_views()),
35 OTHER(""), // Subnode of another node.
36 DATA_SOURCE_FILES(SelectionContext_dataSourceFiles());
37
38 private final String displayName;
39
40 private SelectionContext(String displayName) {
41 this.displayName = displayName;
42 }
43
44 public static SelectionContext getContextFromName(String name) {
45 if (name.equals(DATA_SOURCES.getName()) || name.equals(DATA_SOURCE_FILES.getName())) {
46 return DATA_SOURCES;
47 } else if (name.equals(VIEWS.getName())) {
48 return VIEWS;
49 } else {
50 return OTHER;
51 }
52 }
53
54 private String getName() {
55 return displayName;
56 }
57
65 public static SelectionContext getSelectionContext(Node n) {
66 if (n == null || n.getParentNode() == null) {
67 // Parent of root node or root node. Occurs during case open / close.
68 return SelectionContext.OTHER;
69 } else if ((!Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true) && DataSourcesNode.getNameIdentifier().equals(n.getParentNode().getName()))
70 || (Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true) && DataSourceFilesNode.getNameIdentifier().equals(n.getParentNode().getName()))) {
71 // if group by data type and root is the DataSourcesNode or
72 // if group by persons/hosts and parent of DataSourceFilesNode
73 // then it is a data source node
74 return SelectionContext.DATA_SOURCES;
75 } else if (n.getParentNode().getParentNode() == null) {
76 // One level below root node. Should be one of DataSources, Views, or Results
77 return SelectionContext.getContextFromName(n.getDisplayName());
78 } else {
79 // In Group by Data Source mode, the node under root is the data source name, and
80 // under that is Data Source Files, Views, or Results. Before moving up the tree, check
81 // if one of those applies.
82 if (n.getParentNode().getParentNode().getParentNode() == null) {
83 SelectionContext context = SelectionContext.getContextFromName(n.getDisplayName());
84 if (context != SelectionContext.OTHER) {
85 return context;
86 }
87 }
88
89 return getSelectionContext(n.getParentNode());
90 }
91 }
92
93}
static SelectionContext getContextFromName(String name)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.