Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
RootFilterState.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.ImmutableMap;
22 import com.google.common.collect.Lists;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.Objects;
26 import java.util.Set;
27 import javafx.beans.property.BooleanProperty;
28 import javafx.beans.property.SimpleBooleanProperty;
29 import javafx.collections.ObservableList;
30 import org.openide.util.NbBundle;
31 import org.sleuthkit.datamodel.TimelineFilter;
32 import org.sleuthkit.datamodel.TimelineFilter.DataSourceFilter;
33 import org.sleuthkit.datamodel.TimelineFilter.DataSourcesFilter;
34 import org.sleuthkit.datamodel.TimelineFilter.EventTypeFilter;
35 import org.sleuthkit.datamodel.TimelineFilter.FileTypeFilter;
36 import org.sleuthkit.datamodel.TimelineFilter.FileTypesFilter;
37 import org.sleuthkit.datamodel.TimelineFilter.HashHitsFilter;
38 import org.sleuthkit.datamodel.TimelineFilter.HideKnownFilter;
39 import org.sleuthkit.datamodel.TimelineFilter.RootFilter;
40 import org.sleuthkit.datamodel.TimelineFilter.TextFilter;
41 import org.sleuthkit.datamodel.TimelineFilter.TagsFilter;
42 
50 public class RootFilterState extends CompoundFilterState<TimelineFilter, RootFilter> {
51 
52  private final static BooleanProperty ALWAYS_TRUE = new SimpleBooleanProperty(true);
53  private final static BooleanProperty ALWAYS_FALSE = new SimpleBooleanProperty(false);
60  private final CompoundFilterState<TimelineFilter.FileTypeFilter, TimelineFilter.FileTypesFilter> fileTypesFilterState;
61  private final Set<FilterState<? extends TimelineFilter>> namedFilterStates = new HashSet<>();
62 
72  public RootFilterState(RootFilter rootFilter) {
73  this(rootFilter,
74  new CompoundFilterState<>(rootFilter.getEventTypeFilter()),
75  new SqlFilterState<>(rootFilter.getKnownFilter()),
76  new TextFilterState(rootFilter.getTextFilter()),
77  new TagsFilterState(rootFilter.getTagsFilter()),
78  new HashHitsFilterState(rootFilter.getHashHitsFilter()),
79  new CompoundFilterState<>(rootFilter.getDataSourcesFilter()),
80  new CompoundFilterState<>(rootFilter.getFileTypesFilter())
81  );
82  }
83 
101  private RootFilterState(RootFilter rootFilter,
103  SqlFilterState<HideKnownFilter> knownFilterState,
104  TextFilterState textFilterState,
105  TagsFilterState tagsFilterState,
106  HashHitsFilterState hashHitsFilterState,
109  super(rootFilter, Arrays.asList(eventTypeFilterState, knownFilterState, textFilterState, tagsFilterState, hashHitsFilterState, dataSourcesFilterState, fileTypesFilterState));
110  this.eventTypeFilterState = eventTypeFilterState;
111  this.knownFilterState = knownFilterState;
112  this.textFilterState = textFilterState;
113  this.tagsFilterState = tagsFilterState;
114  this.hashHitsFilterState = hashHitsFilterState;
115  this.dataSourcesFilterState = dataSourcesFilterState;
116  this.fileTypesFilterState = fileTypesFilterState;
117  namedFilterStates.addAll(Arrays.asList(eventTypeFilterState, knownFilterState, textFilterState, tagsFilterState, hashHitsFilterState, dataSourcesFilterState, fileTypesFilterState));
118  }
119 
131  copyOf.addSubFilterState(other);
132  return copyOf;
133  }
134 
135  @Override
137  RootFilterState copy = new RootFilterState(getFilter().copyOf(),
140  new TextFilterState(this.textFilterState),
141  new TagsFilterState(this.tagsFilterState),
142  new HashHitsFilterState(this.hashHitsFilterState),
145  );
146  this.getSubFilterStates().stream()
147  .filter(filterState -> namedFilterStates.contains(filterState) == false)
148  .forEach(copy::addSubFilterState);
149  return copy;
150  }
151 
153  return eventTypeFilterState;
154  }
155 
157  return knownFilterState;
158  }
159 
161  return textFilterState;
162  }
163 
165  return tagsFilterState;
166  }
167 
169  return hashHitsFilterState;
170  }
171 
173  return dataSourcesFilterState;
174  }
175 
177  return fileTypesFilterState;
178  }
179 
180  @Override
181  public RootFilter getActiveFilter() {
182  return new RootFilter(knownFilterState.getActiveFilter(),
183  tagsFilterState.getActiveFilter(),
184  hashHitsFilterState.getActiveFilter(),
185  textFilterState.getActiveFilter(),
186  eventTypeFilterState.getActiveFilter(),
187  dataSourcesFilterState.getActiveFilter(),
190  }
191 
192  @Override
193  public ObservableList<FilterState<? extends TimelineFilter>> getSubFilterStates() {
194  ImmutableMap<FilterState<? extends TimelineFilter>, Integer> filterOrder
195  = ImmutableMap.<FilterState<? extends TimelineFilter>, Integer>builder()
196  .put(knownFilterState, 0)
197  .put(textFilterState, 1)
198  .put(tagsFilterState, 2)
199  .put(hashHitsFilterState, 3)
200  .put(dataSourcesFilterState, 4)
201  .put(fileTypesFilterState, 5)
202  .put(eventTypeFilterState, 6)
203  .build();
204 
205  return super.getSubFilterStates().sorted((state1, state2)
206  -> Integer.compare(filterOrder.getOrDefault(state1, Integer.MAX_VALUE), filterOrder.getOrDefault(state2, Integer.MAX_VALUE)));
207  }
208 
209  @Override
210  public boolean equals(Object obj) {
211  if (this == obj) {
212  return true;
213  }
214  if (obj == null) {
215  return false;
216  }
217  if (getClass() != obj.getClass()) {
218  return false;
219  }
220 
221  final RootFilterState other = (RootFilterState) obj;
222 
223  if (false == Objects.equals(this.getFilter(), other.getFilter())) {
224  return false;
225  }
226 
227  return Objects.equals(this.getSubFilterStates(), other.getSubFilterStates());
228  }
229 
230  @Override
231  public int hashCode() {
232  return 7;
233  }
234 
235  @Override
236  public BooleanProperty activeProperty() {
237  return ALWAYS_TRUE;
238  }
239 
240  @Override
241  public BooleanProperty disabledProperty() {
242  return ALWAYS_FALSE;
243  }
244 
245  @NbBundle.Messages("RootFilterState.displayName=Root")
246  @Override
247  public String getDisplayName() {
248  return Bundle.RootFilterState_displayName();
249  }
250 
251  @Override
252  public boolean isActive() {
253  return true;
254  }
255 
256  @Override
257  public boolean isDisabled() {
258  return false;
259  }
260 
261  @Override
262  public boolean isSelected() {
263  return true;
264  }
265 
266  @Override
267  public BooleanProperty selectedProperty() {
268  return ALWAYS_TRUE;
269  }
270 
271  @Override
272  public void setDisabled(Boolean act) {
273  /*
274  * A RootFitlerState is always enabled, so disabling it is overridden as
275  * a no-op.
276  */
277  }
278 
279  @Override
280  public void setSelected(Boolean act) {
281  /*
282  * A RootFitlerState is always enabled, so enabling it is overridden as
283  * a no-op.
284  */
285  }
286 
287  @Override
288  public String toString() {
289  return "RootFilterState{"
290  + "\neventTypeFilterState=" + eventTypeFilterState + ","
291  + "\nknownFilterState=" + knownFilterState + ","
292  + "\ntextFilterState=" + textFilterState + ","
293  + "\ntagsFilterState=" + tagsFilterState + ","
294  + "\nhashHitsFilterState=" + hashHitsFilterState + ","
295  + "\ndataSourcesFilterState=" + dataSourcesFilterState + ","
296  + "\nfileTypesFilterState=" + fileTypesFilterState + ","
297  + "\nsubFilterStates=" + getSubFilterStates() + ","
298  + "\nnamedFilterStates=" + namedFilterStates + ","
299  + "\ndelegate=" + getFilter() + '}'; //NON-NLS
300  }
301 }
final CompoundFilterState< EventTypeFilter, EventTypeFilter > eventTypeFilterState
void addSubFilterState(FilterState< ?extends SubFilterType > newSubFilterState)
CompoundFilterState< FileTypeFilter, FileTypesFilter > getFileTypesFilterState()
final CompoundFilterState< TimelineFilter.FileTypeFilter, TimelineFilter.FileTypesFilter > fileTypesFilterState
CompoundFilterState< EventTypeFilter, EventTypeFilter > getEventTypeFilterState()
RootFilterState(RootFilter rootFilter, CompoundFilterState< EventTypeFilter, EventTypeFilter > eventTypeFilterState, SqlFilterState< HideKnownFilter > knownFilterState, TextFilterState textFilterState, TagsFilterState tagsFilterState, HashHitsFilterState hashHitsFilterState, CompoundFilterState< DataSourceFilter, DataSourcesFilter > dataSourcesFilterState, CompoundFilterState< FileTypeFilter, FileTypesFilter > fileTypesFilterState)
ObservableList< FilterState<?extends TimelineFilter > > getSubFilterStates()
final CompoundFilterState< DataSourceFilter, DataSourcesFilter > dataSourcesFilterState
final Set< FilterState<?extends TimelineFilter > > namedFilterStates
RootFilterState intersect(FilterState< ?extends TimelineFilter > other)
CompoundFilterState< DataSourceFilter, DataSourcesFilter > getDataSourcesFilterState()

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