Autopsy  3.1
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;
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  DATA_SOURCES(NbBundle.getMessage(KnownFileFilterNode.class, "KnownFileFilterNode.selectionContext.dataSources")),
62  VIEWS(NbBundle.getMessage(KnownFileFilterNode.class, "KnownFileFilterNode.selectionContext.views")),
63  OTHER(""); // Subnode of another node.
64 
65  private final String displayName;
66 
67  SelectionContext(String displayName) {
68  this.displayName = displayName;
69  }
70 
71  public static SelectionContext getContextFromName(String name) {
72  if (name.equals(DATA_SOURCES.getName())) {
73  return DATA_SOURCES;
74  } else if (name.equals(VIEWS.getName())) {
75  return VIEWS;
76  } else {
77  return OTHER;
78  }
79  }
80 
81  private String getName() {
82  return displayName;
83  }
84  }
85 
93  public KnownFileFilterNode(Node arg, SelectionContext context) {
94  super(arg, new KnownFileFilterChildren(arg, context));
95  }
96 
97  private KnownFileFilterNode(Node arg, boolean filter) {
98  super(arg, new KnownFileFilterChildren(arg, filter));
99  }
100 
107  public static SelectionContext getSelectionContext(Node n) {
108  if (n == null || n.getParentNode() == null) {
109  // Parent of root node or root node. Occurs during case open / close.
110  return SelectionContext.OTHER;
111  } else if (n.getParentNode().getParentNode() == null) {
112  // One level below root node. Should be one of DataSources, Views, or Results
113  return SelectionContext.getContextFromName(n.getDisplayName());
114  } else {
115  return getSelectionContext(n.getParentNode());
116  }
117  }
118 
127  private static class KnownFileFilterChildren extends FilterNode.Children {
128 
130  private boolean filter;
131 
138  private KnownFileFilterChildren(Node arg, boolean filter) {
139  super(arg);
140  this.filter = filter;
141  }
142 
149  super(arg);
150 
151  switch (context) {
152  case DATA_SOURCES:
153  filter = filterFromDataSources;
154  break;
155  case VIEWS:
156  filter = filterFromViews;
157  break;
158  default:
159  filter = false;
160  break;
161  }
162  }
163 
164  @Override
165  protected Node[] createNodes(Node arg) {
166  if (filter) {
167  // Filter out child nodes that represent known files
168  AbstractFile file = arg.getLookup().lookup(AbstractFile.class);
169  if (file != null && (file.getKnown() == TskData.FileKnown.KNOWN)) {
170  return new Node[]{};
171  }
172  }
173  return new Node[] { new KnownFileFilterNode(arg, filter) };
174  }
175  }
176 }
KnownFileFilterChildren(Node arg, KnownFileFilterNode.SelectionContext context)
KnownFileFilterNode(Node arg, SelectionContext context)
static void addChangeListener(PreferenceChangeListener listener)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.