Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrencesDataSourcesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 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.centralrepository.contentviewer;
20 
21 import java.util.LinkedHashSet;
22 import java.util.Objects;
23 import java.util.Set;
24 import javax.swing.table.AbstractTableModel;
25 import org.openide.util.NbBundle;
26 
31 final class OtherOccurrencesDataSourcesTableModel extends AbstractTableModel {
32 
33  private static final long serialVersionUID = 1L;
34  private final Set<DataSourceColumnItem> dataSourceSet = new LinkedHashSet<>();
35 
39  OtherOccurrencesDataSourcesTableModel() {
40  // This constructor is intentionally empty.
41  }
42 
43  @Override
44  public int getColumnCount() {
45  return 1;
46  }
47 
48  @Override
49  public int getRowCount() {
50  return dataSourceSet.size();
51  }
52 
53  @NbBundle.Messages({"OtherOccurrencesDataSourcesTableModel.dataSourceName=Data Source Name",
54  "OtherOccurrencesDataSourcesTableModel.noData=No Data."})
55  @Override
56  public String getColumnName(int colIdx) {
57  return Bundle.OtherOccurrencesDataSourcesTableModel_dataSourceName();
58  }
59 
60  @Override
61  public Object getValueAt(int rowIdx, int colIdx) {
62  //if anything would prevent this from working we will consider it no data for the sake of simplicity
63  if (dataSourceSet.isEmpty() || rowIdx < 0
64  || rowIdx >= dataSourceSet.size()
65  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
66  return Bundle.OtherOccurrencesDataSourcesTableModel_noData();
67  }
68  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getDataSourceName();
69  }
70 
79  String getDeviceIdForRow(int rowIdx) {
80  //if anything would prevent this from working we will return an empty string
81  if (dataSourceSet.isEmpty() || rowIdx < 0
82  || rowIdx >= dataSourceSet.size()
83  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
84  return "";
85  }
86  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getDeviceId();
87  }
88 
97  String getCaseNameForRow(int rowIdx) {
98  //if anything would prevent this from working we will return an empty string
99  if (dataSourceSet.isEmpty() || rowIdx < 0
100  || rowIdx >= dataSourceSet.size()
101  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
102  return "";
103  }
104  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getCaseName();
105  }
106 
107  @Override
108  public Class<String> getColumnClass(int colIdx) {
109  return String.class;
110  }
111 
117  void addNodeData(OtherOccurrenceNodeData newNodeData) {
118  dataSourceSet.add(new DataSourceColumnItem((OtherOccurrenceNodeInstanceData) newNodeData));
119  fireTableDataChanged();
120  }
121 
125  void clearTable() {
126  dataSourceSet.clear();
127  fireTableDataChanged();
128  }
129 
134  private final class DataSourceColumnItem {
135 
136  private final String caseName;
137  private final String deviceId;
138  private final String dataSourceName;
139 
147  private DataSourceColumnItem(OtherOccurrenceNodeInstanceData nodeData) {
148  this(nodeData.getCaseName(), nodeData.getDeviceID(), nodeData.getDataSourceName());
149  }
150 
159  private DataSourceColumnItem(String caseName, String deviceId, String dataSourceName) {
160  this.caseName = caseName;
161  this.deviceId = deviceId;
162  this.dataSourceName = dataSourceName;
163  }
164 
170  private String getDeviceId() {
171  return deviceId;
172  }
173 
179  private String getDataSourceName() {
180  return dataSourceName;
181  }
182 
188  private String getCaseName() {
189  return caseName;
190  }
191 
192  @Override
193  public boolean equals(Object other) {
194  return other instanceof DataSourceColumnItem
195  && caseName.equals(((DataSourceColumnItem) other).getCaseName())
196  && dataSourceName.equals(((DataSourceColumnItem) other).getDataSourceName())
197  && deviceId.equals(((DataSourceColumnItem) other).getDeviceId());
198  }
199 
200  @Override
201  public int hashCode() {
202  return Objects.hash(caseName, deviceId, dataSourceName);
203  }
204  }
205 
206 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.