19 package org.sleuthkit.autopsy.discovery.ui;
21 import java.awt.Dimension;
22 import java.awt.Point;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JPopupMenu;
27 import javax.swing.event.ListSelectionListener;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableCellRenderer;
30 import org.apache.commons.io.FilenameUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.openide.util.NbBundle;
46 final class ArtifactsListPanel
extends AbstractArtifactListPanel {
48 private static final long serialVersionUID = 1L;
49 private static final Logger logger = Logger.getLogger(ArtifactsListPanel.class.getName());
50 private final DomainArtifactTableModel tableModel;
57 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
58 ArtifactsListPanel(BlackboardArtifact.ARTIFACT_TYPE artifactType) {
59 tableModel =
new DomainArtifactTableModel(artifactType);
62 TableCellRenderer renderer =
new SimpleTableCellRenderer();
63 for (
int i = 0; i < tableModel.getColumnCount(); ++i) {
64 artifactsTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
66 setMinimumSize(
new Dimension(125, 20));
67 artifactsTable.getRowSorter().toggleSortOrder(0);
68 artifactsTable.getRowSorter().toggleSortOrder(0);
72 void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
73 artifactsTable.addMouseListener(mouseListener);
77 void showPopupMenu(JPopupMenu popupMenu, Point point) {
78 popupMenu.show(artifactsTable, point.x, point.y);
82 void addSelectionListener(ListSelectionListener listener) {
83 artifactsTable.getSelectionModel().addListSelectionListener(listener);
89 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
91 artifactsTable.grabFocus();
95 void removeSelectionListener(ListSelectionListener listener) {
96 artifactsTable.getSelectionModel().removeListSelectionListener(listener);
100 boolean selectAtPoint(Point point) {
101 boolean pointSelected =
false;
102 int row = artifactsTable.rowAtPoint(point);
103 if (row < artifactsTable.getRowCount() && row >= 0) {
104 artifactsTable.clearSelection();
105 artifactsTable.addRowSelectionInterval(row, row);
106 pointSelected =
true;
108 return pointSelected;
112 BlackboardArtifact getSelectedArtifact() {
113 if (artifactsTable.getModel() instanceof DomainArtifactTableModel) {
114 int selectedIndex = artifactsTable.getSelectionModel().getLeadSelectionIndex();
115 if (selectedIndex < artifactsTable.getSelectionModel().getMinSelectionIndex() || artifactsTable.getSelectionModel().getMaxSelectionIndex() < 0 || selectedIndex > artifactsTable.getSelectionModel().getMaxSelectionIndex()) {
118 return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
126 return tableModel.getRowCount() <= 0;
132 artifactsTable.setRowSelectionInterval(0, 0);
134 artifactsTable.clearSelection();
144 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
146 void addArtifacts(List<BlackboardArtifact> artifactList) {
147 if (!artifactList.isEmpty()) {
148 artifactsTable.setModel(tableModel);
149 tableModel.setContents(artifactList);
151 artifactsTable.setModel(
new EmptyTableModel());
153 artifactsTable.validate();
154 artifactsTable.repaint();
155 tableModel.fireTableDataChanged();
161 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
164 addArtifacts(
new ArrayList<>());
173 private void initComponents() {
175 javax.swing.JScrollPane jScrollPane1 =
new javax.swing.JScrollPane();
176 artifactsTable =
new javax.swing.JTable();
179 setPreferredSize(
new java.awt.Dimension(350, 10));
181 jScrollPane1.setBorder(null);
182 jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
183 jScrollPane1.setMinimumSize(
new java.awt.Dimension(0, 0));
184 jScrollPane1.setPreferredSize(
new java.awt.Dimension(350, 10));
186 artifactsTable.setAutoCreateRowSorter(
true);
187 artifactsTable.setModel(tableModel);
188 artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
189 jScrollPane1.setViewportView(artifactsTable);
191 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
192 this.setLayout(layout);
193 layout.setHorizontalGroup(
194 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
197 layout.setVerticalGroup(
198 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
209 private static final long serialVersionUID = 1L;
210 private final List<BlackboardArtifact> artifactList =
new ArrayList<>();
230 void setContents(List<BlackboardArtifact> artifacts) {
231 artifactsTable.clearSelection();
232 artifactList.clear();
233 artifactList.addAll(artifacts);
239 return artifactList.size();
245 if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
260 BlackboardArtifact getArtifactByRow(
int rowIndex) {
261 return artifactList.get(rowIndex);
265 @NbBundle.Messages({
"ArtifactsListPanel.value.noValue=No value available."})
268 if (columnIndex < 2 || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
269 final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
271 for (BlackboardAttribute bba : artifact.getAttributes()) {
272 if (!StringUtils.isBlank(bba.getDisplayString())) {
274 if (!StringUtils.isBlank(stringFromAttribute)) {
275 return stringFromAttribute;
280 }
catch (TskCoreException ex) {
281 logger.log(Level.WARNING,
"Error getting attributes for artifact " + artifact.getArtifactID(), ex);
284 return Bundle.ArtifactsListPanel_value_noValue();
303 private String
getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba,
int columnIndex) throws TskCoreException {
304 if (columnIndex == 0 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
306 }
else if (columnIndex == 1) {
307 if (artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD || artifactType == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE) {
308 if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
310 }
else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID()) {
311 return FilenameUtils.getName(bba.getDisplayString());
313 }
else if (bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE.getTypeID()) {
314 return bba.getDisplayString();
316 }
else if (columnIndex == 2 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
338 final BlackboardArtifact artifact = getArtifactByRow(rowIndex);
339 for (BlackboardAttribute bba : artifact.getAttributes()) {
340 if (columnIndex == 0 && bba.getAttributeType().getTypeName().startsWith(
"TSK_DATETIME") && !StringUtils.isBlank(bba.getDisplayString())) {
342 }
else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
343 return bba.getDisplayString();
344 }
else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
345 return bba.getDisplayString();
346 }
else if (columnIndex == 1 && bba.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID() && !StringUtils.isBlank(bba.getDisplayString())) {
347 return bba.getDisplayString();
350 return Bundle.ArtifactsListPanel_value_noValue();
354 @NbBundle.Messages({
"ArtifactsListPanel.titleColumn.name=Title",
355 "ArtifactsListPanel.fileNameColumn.name=Name",
356 "ArtifactsListPanel.dateColumn.name=Date/Time",
357 "ArtifactsListPanel.urlColumn.name=URL",
358 "ArtifactsListPanel.termColumn.name=Term",
359 "ArtifactsListPanel.mimeTypeColumn.name=MIME Type"})
364 return Bundle.ArtifactsListPanel_dateColumn_name();
366 if (artifactType != null) {
367 switch (artifactType) {
369 case TSK_WEB_DOWNLOAD:
370 return Bundle.ArtifactsListPanel_fileNameColumn_name();
372 return Bundle.ArtifactsListPanel_urlColumn_name();
373 case TSK_WEB_SEARCH_QUERY:
374 return Bundle.ArtifactsListPanel_termColumn_name();
378 return Bundle.ArtifactsListPanel_titleColumn_name();
380 return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
392 private static final long serialVersionUID = 1L;
404 @NbBundle.Messages({
"ArtifactsListPanel.noResultsFound.text=No results found"})
407 return Bundle.ArtifactsListPanel_noResultsFound_text();
414 return Bundle.ArtifactsListPanel_dateColumn_name();
416 return Bundle.ArtifactsListPanel_titleColumn_name();
418 return Bundle.ArtifactsListPanel_mimeTypeColumn_name();
427 private javax.swing.JTable artifactsTable;
Object getValueAt(int rowIndex, int columnIndex)
String getFallbackValue(int rowIndex, int columnIndex)
static String getFormattedTime(long epochTime)
Object getValueAt(int rowIndex, int columnIndex)
SleuthkitCase getSleuthkitCase()
String getStringForColumn(BlackboardArtifact artifact, BlackboardAttribute bba, int columnIndex)
static Case getCurrentCase()
String getColumnName(int column)
final BlackboardArtifact.ARTIFACT_TYPE artifactType
String getColumnName(int column)