Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourcesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2018 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.centralrepository.optionspanel;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import javax.swing.table.AbstractTableModel;
24 import org.openide.util.NbBundle.Messages;
26 
30 class DataSourcesTableModel extends AbstractTableModel {
31 
32  private static final long serialVersionUID = 1L;
33 
37  private final List<CorrelationDataSource> dataSources;
38 
43  DataSourcesTableModel() {
44  dataSources = new ArrayList<>();
45  }
46 
47  @Override
48  public int getColumnCount() {
49  return DataSourcesTableColumns.values().length;
50  }
51 
52  @Override
53  public int getRowCount() {
54  return dataSources.size();
55  }
56 
57  @Override
58  public String getColumnName(int colIdx) {
59  return DataSourcesTableColumns.values()[colIdx].columnName();
60  }
61 
62  @Override
63  public Object getValueAt(int rowIdx, int colIdx) {
64  if (dataSources.isEmpty()) {
65  return Bundle.DataSourcesTableModel_noData();
66  }
67 
68  return mapValueById(rowIdx, DataSourcesTableColumns.values()[colIdx]);
69  }
70 
79  @Messages({"DataSourcesTableModel.noData=No Data Sources"})
80  private Object mapValueById(int rowIdx, DataSourcesTableColumns colId) {
81  CorrelationDataSource dataSource = dataSources.get(rowIdx);
82  String value = Bundle.DataSourcesTableModel_noData();
83 
84  switch (colId) {
85  case DATA_SOURCE:
86  value = dataSource.getName();
87  break;
88  case DEVICE_ID:
89  value = dataSource.getDeviceID();
90  break;
91  default:
92  break;
93  }
94  return value;
95  }
96 
97  @Override
98  public Class<String> getColumnClass(int colIdx) {
99  return String.class;
100  }
101 
107  void addDataSources(List<CorrelationDataSource> dataSourceList) {
108  dataSources.addAll(dataSourceList);
109  fireTableDataChanged();
110  }
111 
115  void clearTable() {
116  dataSources.clear();
117  fireTableDataChanged();
118  }
119 
120  @Messages({"DataSourcesTableModel.dataSource=Data Source Name",
121  "DataSourcesTableModel.deviceId=Device ID"})
125  private enum DataSourcesTableColumns {
126  // Ordering here determines displayed column order in Content Viewer.
127  // If order is changed, update the CellRenderer to ensure correct row coloring.
128  DATA_SOURCE(Bundle.DataSourcesTableModel_dataSource()),
129  DEVICE_ID(Bundle.DataSourcesTableModel_deviceId());
130 
131  private final String columnName;
132 
138  DataSourcesTableColumns(String columnName) {
139  this.columnName = columnName;
140  }
141 
147  String columnName() {
148  return columnName;
149  }
150  }
151 
152 }

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