Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DefaultListTableModel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.uiutils;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.function.Function;
25 import javax.swing.table.AbstractTableModel;
26 
31 public class DefaultListTableModel<T> extends AbstractTableModel implements ListTableModel<T> {
32 
33  private static final long serialVersionUID = 1L;
34  private final List<Function<T, ? extends Object>> columns;
35  private List<T> dataRows = Collections.emptyList();
36 
45  public DefaultListTableModel(List<Function<T, ? extends Object>> columns) {
46  this.columns = columns;
47  }
48 
49  @Override
50  public List<T> getDataRows() {
51  return dataRows;
52  }
53 
54  @Override
55  public void setDataRows(List<T> dataRows) {
56  this.dataRows = dataRows == null ? Collections.emptyList() : new ArrayList<>(dataRows);
57  super.fireTableDataChanged();
58  }
59 
60  @Override
61  public int getRowCount() {
62  return dataRows.size();
63  }
64 
65  @Override
66  public int getColumnCount() {
67  return columns.size();
68  }
69 
70  @Override
71  public Object getValueAt(int rowIndex, int columnIndex) {
72  // if index requested is null, return null
73  if (rowIndex < 0 || rowIndex >= dataRows.size() || columnIndex < 0 || columnIndex >= columns.size()) {
74  return null;
75  }
76 
77  // otherwise, get the corresponding row and use the corresponding
78  // column function to get the value
79  return columns.get(columnIndex).apply(dataRows.get(rowIndex));
80  }
81 }

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