Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
CompoundFilterState.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-2019 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.datamodel;
20 
21 import com.google.common.collect.Lists;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.stream.Collectors;
26 import javafx.collections.FXCollections;
27 import javafx.collections.ObservableList;
28 import org.sleuthkit.datamodel.TimelineFilter;
29 import org.sleuthkit.datamodel.TimelineFilter.CompoundFilter;
30 
39 public class CompoundFilterState<SubFilterType extends TimelineFilter, FilterType extends CompoundFilter<SubFilterType>> extends SqlFilterState<FilterType> {
40 
41  private final ObservableList< FilterState<? extends SubFilterType>> subFilterStates = FXCollections.observableArrayList();
42 
49  CompoundFilterState(FilterType filter) {
50  super(filter);
51  filter.getSubFilters().forEach(newSubFilter -> {
52  //add the appropriate filter type: default or compound
53  if (newSubFilter instanceof CompoundFilter<?>) {
54  @SuppressWarnings(value = "unchecked")
55  FilterState<SubFilterType> compoundFilterState = (FilterState<SubFilterType>) new CompoundFilterState<>((CompoundFilter<?>) newSubFilter);
56  addSubFilterStateInternal(compoundFilterState);
57  } else {
59  }
60  });
61 
63  }
64 
74  CompoundFilterState(FilterType filter, Collection< FilterState<? extends SubFilterType>> subFilterStates) {
75  super(filter);
76  subFilterStates.forEach(this::addSubFilterStateInternal);
77 
79  }
80 
81  private void configureListeners() {
82  activeProperty().addListener(activeProperty -> disableSubFiltersIfNotActive());
84 
89  selectedProperty().addListener(selectedProperty -> {
90  if (isSelected() && getSubFilterStates().stream().noneMatch(FilterState::isSelected)) {
91  subFilterStates.forEach(subFilterState -> subFilterState.setSelected(true));
92  }
93  });
94  }
95 
100  boolean inactive = isActive() == false;
101 
102  subFilterStates.forEach(subFilterState -> subFilterState.setDisabled(inactive));
103  }
104 
114  SubFilterType filter = newSubFilterState.getFilter();
115  if (getSubFilterStates().stream().map(FilterState::getFilter).noneMatch(filter::equals)) {
116 
117  //add the state first, and then the actual filter which will check for an existing state before adding another one.
118  addSubFilterStateInternal(newSubFilterState);
119  getFilter().getSubFilters().add(filter);
120  }
121  }
122 
124  if (subFilterStates.contains(newSubFilterState) == false) {
125  subFilterStates.add(newSubFilterState);
126  newSubFilterState.selectedProperty().addListener(selectedProperty -> {
127  //set this compound filter state selected if any of the subfilters are selected.
128  setSelected(subFilterStates.stream().anyMatch(FilterState::isSelected));
129  });
130  newSubFilterState.setDisabled(isActive() == false);
131  }
132  }
133 
134  public ObservableList< FilterState< ? extends SubFilterType>> getSubFilterStates() {
135  return subFilterStates;
136  }
137 
138  @Override
140  @SuppressWarnings("unchecked")
142  = new CompoundFilterState<>((FilterType) getFilter().copyOf(),
143  Lists.transform(subFilterStates, FilterState::copyOf));
144 
145  copy.setSelected(isSelected());
146  copy.setDisabled(isDisabled());
147  return copy;
148  }
149 
150  @Override
151  @SuppressWarnings("unchecked")
152  public FilterType getActiveFilter() {
153  if (isActive() == false) {
154  return null;
155  }
156 
157  List<SubFilterType> activeSubFilters = subFilterStates.stream()
158  .filter(filterState -> filterState.isActive())
159  .map(filterState -> filterState.getActiveFilter())
160  .collect(Collectors.toList());
161  FilterType copy = (FilterType) getFilter().copyOf();
162  copy.getSubFilters().clear();
163  copy.getSubFilters().addAll(activeSubFilters);
164 
165  return copy;
166  }
167 
168  @Override
169  public int hashCode() {
170  int hash = super.hashCode();
171  hash = 41 * hash + Objects.hashCode(this.subFilterStates);
172  return hash;
173  }
174 
175 
176 
177  @Override
178  public boolean equals(Object obj) {
179  if (this == obj) {
180  return true;
181  }
182  if (obj == null) {
183  return false;
184  }
185  if (getClass() != obj.getClass()) {
186  return false;
187  }
188 
190  if (!Objects.equals(this.getFilter(), other.getFilter())) {
191  return false;
192  }
193  if (!Objects.equals(this.isSelected(), other.isSelected())) {
194  return false;
195  }
196  if (!Objects.equals(this.isDisabled(), other.isDisabled())) {
197  return false;
198  }
199  return Objects.equals(this.subFilterStates, other.subFilterStates);
200  }
201 
202  @Override
203  public String toString() {
204  return "CompoundFilterState{ selected=" + isSelected() + ", disabled=" + isDisabled() + ", activeProp=" + isActive() + ",subFilterStates=" + subFilterStates + '}';
205  }
206 
207 }
void addSubFilterState(FilterState< ?extends SubFilterType > newSubFilterState)
void addSubFilterStateInternal(FilterState< ?extends SubFilterType > newSubFilterState)
final ObservableList< FilterState<?extends SubFilterType > > subFilterStates
ObservableList< FilterState< ?extends SubFilterType > > getSubFilterStates()

Copyright © 2012-2022 Basis Technology. Generated on: Sun Dec 4 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.