Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KnownFileFilterNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.datamodel;
20 
21 import java.util.prefs.PreferenceChangeEvent;
22 import java.util.prefs.PreferenceChangeListener;
23 import org.openide.nodes.FilterNode;
24 import org.openide.nodes.Node;
25 import org.openide.util.NbBundle;
27 import org.sleuthkit.datamodel.AbstractFile;
28 import org.sleuthkit.datamodel.TskData;
29 
39 public class KnownFileFilterNode extends FilterNode {
40 
43 
44  static {
45  UserPreferences.addChangeListener(new PreferenceChangeListener() {
46  @Override
47  public void preferenceChange(PreferenceChangeEvent evt) {
48  switch (evt.getKey()) {
50  filterFromDataSources = UserPreferences.hideKnownFilesInDataSourcesTree();
51  break;
53  filterFromViews = UserPreferences.hideKnownFilesInViewsTree();
54  break;
55  }
56  }
57  });
58  }
59 
60  public enum SelectionContext {
61 
62  DATA_SOURCES(NbBundle.getMessage(KnownFileFilterNode.class, "KnownFileFilterNode.selectionContext.dataSources")),
63  VIEWS(NbBundle.getMessage(KnownFileFilterNode.class, "KnownFileFilterNode.selectionContext.views")),
64  OTHER(""); // Subnode of another node.
65 
66  private final String displayName;
67 
68  SelectionContext(String displayName) {
69  this.displayName = displayName;
70  }
71 
72  public static SelectionContext getContextFromName(String name) {
73  if (name.equals(DATA_SOURCES.getName())) {
74  return DATA_SOURCES;
75  } else if (name.equals(VIEWS.getName())) {
76  return VIEWS;
77  } else {
78  return OTHER;
79  }
80  }
81 
82  private String getName() {
83  return displayName;
84  }
85  }
86 
94  public KnownFileFilterNode(Node arg, SelectionContext context) {
95  super(arg, new KnownFileFilterChildren(arg, context));
96  }
97 
98  private KnownFileFilterNode(Node arg, boolean filter) {
99  super(arg, new KnownFileFilterChildren(arg, filter));
100  }
101 
109  public static SelectionContext getSelectionContext(Node n) {
110  if (n == null || n.getParentNode() == null) {
111  // Parent of root node or root node. Occurs during case open / close.
112  return SelectionContext.OTHER;
113  } else if (n.getParentNode().getParentNode() == null) {
114  // One level below root node. Should be one of DataSources, Views, or Results
115  return SelectionContext.getContextFromName(n.getDisplayName());
116  } else {
117  return getSelectionContext(n.getParentNode());
118  }
119  }
120 
129  private static class KnownFileFilterChildren extends FilterNode.Children {
130 
134  private boolean filter;
135 
142  private KnownFileFilterChildren(Node arg, boolean filter) {
143  super(arg);
144  this.filter = filter;
145  }
146 
154  super(arg);
155 
156  switch (context) {
157  case DATA_SOURCES:
158  filter = filterFromDataSources;
159  break;
160  case VIEWS:
161  filter = filterFromViews;
162  break;
163  default:
164  filter = false;
165  break;
166  }
167  }
168 
169  @Override
170  protected Node[] createNodes(Node arg) {
171  if (filter) {
172  // Filter out child nodes that represent known files
173  AbstractFile file = arg.getLookup().lookup(AbstractFile.class);
174  if (file != null && (file.getKnown() == TskData.FileKnown.KNOWN)) {
175  return new Node[]{};
176  }
177  }
178  return new Node[]{new KnownFileFilterNode(arg, filter)};
179  }
180  }
181 }
KnownFileFilterChildren(Node arg, KnownFileFilterNode.SelectionContext context)
KnownFileFilterNode(Node arg, SelectionContext context)
static final String HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE
static void addChangeListener(PreferenceChangeListener listener)

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.