Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CompoundFilter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-15 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.filters;
20 
21 import java.util.List;
22 import java.util.Objects;
23 import javafx.beans.Observable;
24 import javafx.collections.FXCollections;
25 import javafx.collections.ListChangeListener;
26 import javafx.collections.ObservableList;
27 
44 public abstract class CompoundFilter<SubFilterType extends Filter> extends AbstractFilter {
45 
49  private final ObservableList<SubFilterType> subFilters = FXCollections.observableArrayList();
50 
51  public final ObservableList<SubFilterType> getSubFilters() {
52  return subFilters;
53  }
54 
60  public CompoundFilter(List<SubFilterType> subFilters) {
61  super();
62 
63  //listen to changes in list of subfilters and add active state listener to newly added filters
64  this.subFilters.addListener((ListChangeListener.Change<? extends SubFilterType> c) -> {
65  while (c.next()) {
66  addSubFilterListeners(c.getAddedSubList());
67  }
68  });
69  this.subFilters.setAll(subFilters);
70 
71  this.selectedProperty().addListener(activeProperty -> {
72  getSubFilters().forEach(subFilter -> subFilter.setDisabled(isActive() == false));
73  });
74  this.disabledProperty().addListener(activeProperty -> {
75  getSubFilters().forEach(subFilter -> subFilter.setDisabled(isActive() == false));
76  });
77  }
78 
79  private void addSubFilterListeners(List<? extends SubFilterType> newSubfilters) {
80  for (SubFilterType sf : newSubfilters) {
81  //if a subfilter changes active state
82  sf.selectedProperty().addListener((Observable observable) -> {
83  //set this filter acttive af any of the subfilters are active.
84  setSelected(getSubFilters().parallelStream().anyMatch(Filter::isSelected));
85  });
86  }
87  }
88 
89  static <SubFilterType extends Filter> boolean areSubFiltersEqual(final CompoundFilter<SubFilterType> oneFilter, final CompoundFilter<SubFilterType> otherFilter) {
90  if (oneFilter.getSubFilters().size() != otherFilter.getSubFilters().size()) {
91  return false;
92  }
93  for (int i = 0; i < oneFilter.getSubFilters().size(); i++) {
94  final SubFilterType subFilter = oneFilter.getSubFilters().get(i);
95  final SubFilterType otherSubFilter = otherFilter.getSubFilters().get(i);
96  if (subFilter.equals(otherSubFilter) == false
97  || subFilter.isDisabled() != otherSubFilter.isDisabled()
98  || subFilter.isSelected() != otherSubFilter.isSelected()) {
99  return false;
100  }
101  }
102  return true;
103  }
104 
105  @Override
106  public int hashCode() {
107  int hash = 3;
108  hash = 61 * hash + Objects.hashCode(this.subFilters);
109  return hash;
110  }
111 }
void addSubFilterListeners(List<?extends SubFilterType > newSubfilters)
final ObservableList< SubFilterType > getSubFilters()
CompoundFilter(List< SubFilterType > subFilters)
final ObservableList< SubFilterType > subFilters

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.