Autopsy  4.10.0
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  */
19 package org.sleuthkit.autopsy.directorytree;
20 
21 import org.openide.nodes.Node;
22 import org.openide.util.NbBundle;
23 import static org.sleuthkit.autopsy.directorytree.Bundle.*;
24 
25 @NbBundle.Messages({"SelectionContext.dataSources=Data Sources",
26  "SelectionContext.dataSourceFiles=Data Source Files",
27  "SelectionContext.views=Views"})
28 enum SelectionContext {
29  DATA_SOURCES(SelectionContext_dataSources()),
30  VIEWS(SelectionContext_views()),
31  OTHER(""), // Subnode of another node.
32  DATA_SOURCE_FILES(SelectionContext_dataSourceFiles());
33 
34  private final String displayName;
35 
36  private SelectionContext(String displayName) {
37  this.displayName = displayName;
38  }
39 
40  public static SelectionContext getContextFromName(String name) {
41  if (name.equals(DATA_SOURCES.getName()) || name.equals(DATA_SOURCE_FILES.getName())) {
42  return DATA_SOURCES;
43  } else if (name.equals(VIEWS.getName())) {
44  return VIEWS;
45  } else {
46  return OTHER;
47  }
48  }
49 
50  private String getName() {
51  return displayName;
52  }
53 
61  public static SelectionContext getSelectionContext(Node n) {
62  if (n == null || n.getParentNode() == null) {
63  // Parent of root node or root node. Occurs during case open / close.
64  return SelectionContext.OTHER;
65  } else if (n.getParentNode().getParentNode() == null) {
66  // One level below root node. Should be one of DataSources, Views, or Results
67  return SelectionContext.getContextFromName(n.getDisplayName());
68  } else {
69  // In Group by Data Source mode, the node under root is the data source name, and
70  // under that is Data Source Files, Views, or Results. Before moving up the tree, check
71  // if one of those applies.
72  if (n.getParentNode().getParentNode().getParentNode() == null) {
73  SelectionContext context = SelectionContext.getContextFromName(n.getDisplayName());
74  if (context != SelectionContext.OTHER) {
75  return context;
76  }
77  }
78 
79  return getSelectionContext(n.getParentNode());
80  }
81  }
82 
83 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.