Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CompoundFilter.java
Go to the documentation of this file.
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package org.sleuthkit.autopsy.timeline.filters;
6 
7 import java.util.List;
8 import javafx.beans.Observable;
9 import javafx.beans.value.ObservableValue;
10 import javafx.collections.FXCollections;
11 import javafx.collections.ListChangeListener;
12 import javafx.collections.ObservableList;
13 
30 public abstract class CompoundFilter extends AbstractFilter {
31 
33  private final ObservableList<Filter> subFilters;
34 
35  public final ObservableList<Filter> getSubFilters() {
36  return subFilters;
37  }
38 
43  public CompoundFilter(ObservableList<Filter> subFilters) {
44  super();
45  this.subFilters = FXCollections.<Filter>synchronizedObservableList(subFilters);
46 
47  //listen to changes in list of subfilters and add active state listener to newly added filters
48  this.subFilters.addListener((ListChangeListener.Change<? extends Filter> c) -> {
49  while (c.next()) {
50  addListeners(c.getAddedSubList());
51  //TODO: remove listeners from removed subfilters
52  }
53  });
54 
55  //add listeners to subfilters
56  addListeners(subFilters);
57 
58  //disable subfilters if this filter is disabled
59  getDisabledProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
60  if (newValue) {
61  getSubFilters().forEach((Filter t) -> {
62  t.setDisabled(true);
63  });
64  } else {
65  final boolean isActive = !isActive();
66  getSubFilters().forEach((Filter t) -> {
67  t.setDisabled(isActive);
68  });
69  }
70  });
71 
72  //listen to active property and adjust subfilters active property
73  getActiveProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
74  if (newValue) {
75  // if this filter become active, and all its subfilters were inactive, make them all active
76  if (getSubFilters().stream().noneMatch(Filter::isActive)) {
77  getSubFilters().forEach((Filter filter) -> {
78  filter.setActive(true);
79  });
80  }
81  } else {
82  //if this filter beceoms inactive and all its subfilters where active, make them inactive
83  if (getSubFilters().stream().allMatch(Filter::isActive)) {
84  getSubFilters().forEach((Filter filter) -> {
85  filter.setActive(false);
86  });
87  }
88  }
89 
90  //disabled subfilters if this filter is not active
91  getSubFilters().forEach((Filter t) -> {
92  t.setDisabled(!newValue);
93  });
94  });
95  }
96 
97  private void addListeners(List<? extends Filter> newSubfilters) {
98  for (Filter sf : newSubfilters) {
99  //if a subfilter changes active state
100  sf.getActiveProperty().addListener((Observable observable) -> {
101  //set this filter acttive af any of the subfilters are active.
102  setActive(getSubFilters().parallelStream().anyMatch(Filter::isActive));
103  });
104  }
105  }
106 }
void addListeners(List<?extends Filter > newSubfilters)
CompoundFilter(ObservableList< Filter > subFilters)

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.