Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractFXCellFactory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015-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;
20 
21 import java.util.function.Supplier;
22 import javafx.scene.control.IndexedCell;
23 import javafx.scene.control.ListCell;
24 import javafx.scene.control.TableCell;
25 import javafx.scene.control.TableColumn;
26 import javafx.scene.control.TreeTableCell;
27 import javafx.scene.control.TreeTableColumn;
28 import javafx.scene.control.TreeTableView;
29 
37 public abstract class AbstractFXCellFactory<X, Y> {
38 
39  public TreeTableCell< X, Y> forTreeTable(TreeTableColumn< X, Y> column) {
40  return new AbstractTreeTableCell();
41  }
42 
43  public TableCell<X, Y> forTable(TableColumn<X, Y> column) {
44  return new AbstractTableCell();
45  }
46 
47  public ListCell< Y> forList() {
48  return new AbstractListCell();
49  }
50 
51  protected abstract void configureCell(IndexedCell<? extends Y> cell, Y item, boolean empty, Supplier<X> supplier);
52 
53  private class AbstractTableCell extends TableCell<X, Y> {
54 
55  @Override
56  @SuppressWarnings({"unchecked"}) //we know it will be X but there is a flaw in getTableRow return type
57  protected void updateItem(Y item, boolean empty) {
58  super.updateItem(item, empty);
59  configureCell(this, item, empty, (() -> (X) this.getTableRow().getItem()));
60  }
61  }
62 
63  private class AbstractTreeTableCell extends TreeTableCell<X, Y> {
64 
65  @Override
66  protected void updateItem(Y item, boolean empty) {
67  super.updateItem(item, empty);
68  // Due to a JavaFX issue in Java 10+,
69  // https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8231644
70  // the arrows to expand the tree were removed (FilterTable.css)
71  // and the following code was added to indent the subnodes.
72  TreeTableView<X> treeTableView = this.treeTableViewProperty().get();
73  this.setTranslateX(treeTableView.getTreeItemLevel(treeTableView.getTreeItem(getIndex())) << 4);
74  configureCell(this, item, empty, (() -> this.getTreeTableRow().getItem()));
75  }
76  }
77 
78  private class AbstractListCell extends ListCell< Y> {
79 
80  @Override
81  @SuppressWarnings("unchecked") //for a list X should always equal Y
82  protected void updateItem(Y item, boolean empty) {
83  super.updateItem(item, empty);
84  configureCell(this, item, empty, () -> (X) this.getItem());
85  }
86  }
87 }
TableCell< X, Y > forTable(TableColumn< X, Y > column)
abstract void configureCell(IndexedCell<?extends Y > cell, Y item, boolean empty, Supplier< X > supplier)
TreeTableCell< X, Y > forTreeTable(TreeTableColumn< X, Y > column)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.