Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilterTreeItem.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-16 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.timeline.ui.filtering;
20 
21 import javafx.collections.ListChangeListener;
22 import javafx.collections.MapChangeListener;
23 import javafx.collections.ObservableMap;
24 import javafx.scene.control.TreeItem;
27 
31 final public class FilterTreeItem extends TreeItem<Filter> {
32 
43  public FilterTreeItem(Filter filter, ObservableMap<Filter, Boolean> expansionMap) {
44  super(filter);
45 
46  //listen to changes in the expansion map, and update expansion state of filter object
47  expansionMap.addListener((MapChangeListener.Change<? extends Filter, ? extends Boolean> change) -> {
48  if (change.getKey().equals(filter)) {
49  setExpanded(expansionMap.get(change.getKey()));
50  }
51  });
52 
53  if (expansionMap.containsKey(filter)) {
54  setExpanded(expansionMap.get(filter));
55  }
56 
57  //keep expanion map upto date if user expands/collapses filter
58  expandedProperty().addListener(expandedProperty -> expansionMap.put(filter, isExpanded()));
59 
60  //if the filter is a compound filter, add its subfilters to the tree
61  if (filter instanceof CompoundFilter<?>) {
62  final CompoundFilter<?> compoundFilter = (CompoundFilter<?>) filter;
63 
64  //add all sub filters
65  compoundFilter.getSubFilters().forEach(subFilter -> getChildren().add(new FilterTreeItem(subFilter, expansionMap)));
66 
67  //listen to changes in sub filters and keep tree in sync
68  compoundFilter.getSubFilters().addListener((ListChangeListener.Change<? extends Filter> c) -> {
69  while (c.next()) {
70  for (Filter subfFilter : c.getAddedSubList()) {
71  setExpanded(true); //emphasize new filters by expanding parent to make sure they are visible
72  getChildren().add(new FilterTreeItem(subfFilter, expansionMap));
73  }
74  }
75  });
76 
77  /*
78  * enforce the following relationship between a compound filter and
79  * its subfilters: if a compound filter's active property changes,
80  * disable the subfilters if the compound filter is not active.
81  */
82  compoundFilter.activeProperty().addListener(activeProperty -> {
83  disableSubFiltersIfNotActive(compoundFilter);
84  });
85 
86  disableSubFiltersIfNotActive(compoundFilter);
87  }
88  }
89 
95  static private void disableSubFiltersIfNotActive(CompoundFilter<?> compoundFilter) {
96  boolean inactive = compoundFilter.isActive() == false;
97  compoundFilter.getSubFilters().forEach(subFilter -> subFilter.setDisabled(inactive));
98  }
99 }
final ObservableList< SubFilterType > getSubFilters()
static void disableSubFiltersIfNotActive(CompoundFilter<?> compoundFilter)
FilterTreeItem(Filter filter, ObservableMap< Filter, Boolean > expansionMap)

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