Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SlackFileFilterNode.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 
38 public class SlackFileFilterNode extends FilterNode {
39 
42 
43  static {
44  UserPreferences.addChangeListener(new PreferenceChangeListener() {
45  @Override
46  public void preferenceChange(PreferenceChangeEvent evt) {
47  switch (evt.getKey()) {
49  filterFromDataSources = UserPreferences.hideSlackFilesInDataSourcesTree();
50  break;
52  filterFromViews = UserPreferences.hideSlackFilesInViewsTree();
53  break;
54  }
55  }
56  });
57  }
58 
59  public enum SelectionContext {
60 
61  DATA_SOURCES(NbBundle.getMessage(SlackFileFilterNode.class, "SlackFileFilterNode.selectionContext.dataSources")),
62  VIEWS(NbBundle.getMessage(SlackFileFilterNode.class, "SlackFileFilterNode.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 SlackFileFilterNode(Node arg, SelectionContext context) {
94  super(arg, new SlackFileFilterChildren(arg, context));
95  }
96 
97  private SlackFileFilterNode(Node arg, boolean filter) {
98  super(arg, new SlackFileFilterChildren(arg, filter));
99  }
100 
108  public static SelectionContext getSelectionContext(Node n) {
109  if (n == null || n.getParentNode() == null) {
110  // Parent of root node or root node. Occurs during case open / close.
111  return SelectionContext.OTHER;
112  } else if (n.getParentNode().getParentNode() == null) {
113  // One level below root node. Should be one of DataSources, Views, or Results
114  return SelectionContext.getContextFromName(n.getDisplayName());
115  } else {
116  return getSelectionContext(n.getParentNode());
117  }
118  }
119 
128  private static class SlackFileFilterChildren extends FilterNode.Children {
129 
133  private boolean filter;
134 
141  private SlackFileFilterChildren(Node arg, boolean filter) {
142  super(arg);
143  this.filter = filter;
144  }
145 
153  super(arg);
154 
155  switch (context) {
156  case DATA_SOURCES:
157  filter = filterFromDataSources;
158  break;
159  case VIEWS:
160  filter = filterFromViews;
161  break;
162  default:
163  filter = false;
164  break;
165  }
166  }
167 
168  @Override
169  protected Node[] createNodes(Node arg) {
170  if (filter) {
171  // Filter out child nodes that represent slack files
172  AbstractFile file = arg.getLookup().lookup(AbstractFile.class);
173  if ((file != null) && file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
174  return new Node[]{};
175  }
176  }
177  return new Node[]{new SlackFileFilterNode(arg, filter)};
178  }
179  }
180 }
SlackFileFilterChildren(Node arg, SlackFileFilterNode.SelectionContext context)
static final String HIDE_SLACK_FILES_IN_DATA_SOURCES_TREE
SlackFileFilterNode(Node arg, SelectionContext context)
static void addChangeListener(PreferenceChangeListener listener)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.