Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilterTreeTableRow.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-18 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 java.util.Arrays;
22 import java.util.function.BiPredicate;
23 import javafx.scene.control.TreeItem;
24 import javafx.scene.control.TreeTableRow;
25 import org.controlsfx.control.action.Action;
26 import org.controlsfx.control.action.ActionGroup;
27 import org.controlsfx.control.action.ActionUtils;
28 import org.openide.util.NbBundle;
30 
34 class FilterTreeTableRow extends TreeTableRow<FilterState<?>> {
35 
36  @Override
37  protected void updateItem(FilterState<?> item, boolean empty) {
38  super.updateItem(item, empty);
39  if (item == null || empty) {
40  setContextMenu(null);
41  } else {
42  setContextMenu(ActionUtils.createContextMenu(Arrays.asList(new SelectActionsGroup(this))));
43  }
44  }
45 
46  @NbBundle.Messages(value = {
47  "Timeline.ui.filtering.menuItem.select=select",
48  "Timeline.ui.filtering.menuItem.all=all",
49  "Timeline.ui.filtering.menuItem.none=none",
50  "Timeline.ui.filtering.menuItem.only=only",
51  "Timeline.ui.filtering.menuItem.others=others"})
52  private static enum SelectionAction {
53  ALL(Bundle.Timeline_ui_filtering_menuItem_all(),
54  (treeItem, row) -> true),
55  NONE(Bundle.Timeline_ui_filtering_menuItem_none(),
56  (treeItem, row) -> false),
57  ONLY(Bundle.Timeline_ui_filtering_menuItem_only(),
58  (treeItem, row) -> treeItem == row.getItem()),
59  OTHER(Bundle.Timeline_ui_filtering_menuItem_others(),
60  (treeItem, row) -> treeItem != row.getItem()),
61  SELECT(Bundle.Timeline_ui_filtering_menuItem_select(),
62  (treeItem, row) -> false == row.isSelected());
63 
64  private final BiPredicate<FilterState<?>, TreeTableRow<FilterState<?>>> selectionPredicate;
65 
66  private final String displayName;
67 
68  private SelectionAction(String displayName, BiPredicate<FilterState<?>, TreeTableRow<FilterState<?>>> predicate) {
69  this.selectionPredicate = predicate;
70  this.displayName = displayName;
71  }
72 
73  public void doSelection(FilterState<?> treeItem, TreeTableRow<FilterState<?>> row) {
74  treeItem.setSelected(selectionPredicate.test(treeItem, row));
75  }
76 
77  public String getDisplayName() {
78  return displayName;
79  }
80  }
81 
82  private static final class SelectActionsGroup extends ActionGroup {
83 
84  SelectActionsGroup(TreeTableRow<FilterState<?>> row) {
85  super(Bundle.Timeline_ui_filtering_menuItem_select(),
86  new Select(SelectionAction.ALL, row),
87  new Select(SelectionAction.NONE, row),
88  new Select(SelectionAction.ONLY, row),
89  new Select(SelectionAction.OTHER, row));
90  setEventHandler(new Select(SelectionAction.SELECT, row)::handle);
91  }
92  }
93 
94  private static final class Select extends Action {
95 
96  public TreeTableRow<FilterState<?>> getRow() {
97  return row;
98  }
99  private final TreeTableRow<FilterState<?>> row;
101 
102  Select(SelectionAction strategy, TreeTableRow<FilterState<?>> row) {
103  super(strategy.getDisplayName());
104  this.row = row;
105  this.selectionAction = strategy;
106  setEventHandler(actionEvent -> row.getTreeItem().getParent().getChildren().stream()
107  .map(TreeItem::getValue)
108  .forEach(this::doSelection));
109  }
110 
111  private void doSelection(FilterState<?> treeItem) {
112  selectionAction.doSelection(treeItem, getRow());
113  }
114  }
115 }
final BiPredicate< FilterState<?>, TreeTableRow< FilterState<?> > > selectionPredicate
void doSelection(FilterState<?> treeItem, TreeTableRow< FilterState<?>> row)
SelectionAction(String displayName, BiPredicate< FilterState<?>, TreeTableRow< FilterState<?>>> predicate)

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.