19 package org.sleuthkit.autopsy.discovery.ui;
21 import java.awt.Point;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.JPopupMenu;
26 import javax.swing.event.ListSelectionListener;
27 import javax.swing.table.AbstractTableModel;
28 import javax.swing.table.TableCellRenderer;
29 import org.apache.commons.lang.StringUtils;
30 import org.openide.util.NbBundle;
42 class MiniTimelineArtifactListPanel
extends AbstractArtifactListPanel {
44 private static final long serialVersionUID = 1L;
45 private final TypeDescriptionTableModel tableModel;
46 private static final Logger logger = Logger.getLogger(MiniTimelineArtifactListPanel.class.getName());
48 private static final BlackboardAttribute.ATTRIBUTE_TYPE[] DESCRIPTION_TYPES = {BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE,
49 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
50 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL};
55 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
56 MiniTimelineArtifactListPanel() {
57 tableModel =
new TypeDescriptionTableModel();
60 TableCellRenderer renderer =
new SimpleTableCellRenderer();
61 for (
int i = 0; i < tableModel.getColumnCount(); ++i) {
62 artifactsTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
64 artifactsTable.getRowSorter().toggleSortOrder(0);
65 artifactsTable.getRowSorter().toggleSortOrder(0);
69 void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
70 artifactsTable.addMouseListener(mouseListener);
74 void showPopupMenu(JPopupMenu popupMenu, Point point) {
75 popupMenu.show(artifactsTable, point.x, point.y);
79 void addSelectionListener(ListSelectionListener listener) {
80 artifactsTable.getSelectionModel().addListSelectionListener(listener);
84 void removeSelectionListener(ListSelectionListener listener) {
85 artifactsTable.getSelectionModel().removeListSelectionListener(listener);
90 return tableModel.getRowCount() <= 0;
96 artifactsTable.setRowSelectionInterval(0, 0);
98 artifactsTable.clearSelection();
103 boolean selectAtPoint(Point point) {
104 boolean pointSelected =
false;
105 int row = artifactsTable.rowAtPoint(point);
106 artifactsTable.clearSelection();
107 if (row < artifactsTable.getRowCount() && row >= 0) {
108 artifactsTable.addRowSelectionInterval(row, row);
109 pointSelected =
true;
111 return pointSelected;
115 BlackboardArtifact getSelectedArtifact() {
116 int selectedIndex = artifactsTable.getSelectionModel().getLeadSelectionIndex();
117 if (selectedIndex < artifactsTable.getSelectionModel().getMinSelectionIndex()
118 || artifactsTable.getSelectionModel().getMaxSelectionIndex() < 0
119 || selectedIndex > artifactsTable.getSelectionModel().getMaxSelectionIndex()) {
122 return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
126 void addArtifacts(List<BlackboardArtifact> artifactList) {
127 tableModel.setContents(artifactList);
128 artifactsTable.validate();
129 artifactsTable.repaint();
130 tableModel.fireTableDataChanged();
135 tableModel.setContents(
new ArrayList<>());
136 tableModel.fireTableDataChanged();
142 private void initComponents() {
144 javax.swing.JScrollPane jScrollPane1 =
new javax.swing.JScrollPane();
145 artifactsTable =
new javax.swing.JTable();
148 setPreferredSize(
new java.awt.Dimension(200, 10));
149 jScrollPane1.setPreferredSize(
new java.awt.Dimension(200, 10));
150 jScrollPane1.setBorder(null);
151 jScrollPane1.setMinimumSize(
new java.awt.Dimension(0, 0));
153 artifactsTable.setAutoCreateRowSorter(
true);
154 artifactsTable.setModel(tableModel);
155 artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
156 jScrollPane1.setViewportView(artifactsTable);
158 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
159 this.setLayout(layout);
160 layout.setHorizontalGroup(
161 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
164 layout.setVerticalGroup(
165 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
176 private static final long serialVersionUID = 1L;
177 private final List<BlackboardArtifact> artifactList =
new ArrayList<>();
186 void setContents(List<BlackboardArtifact> artifactList) {
187 artifactsTable.clearSelection();
188 this.artifactList.clear();
189 this.artifactList.addAll(artifactList);
195 return artifactList.size();
212 BlackboardArtifact getArtifactByRow(
int rowIndex) {
213 return artifactList.get(rowIndex);
217 @NbBundle.Messages({
"MiniTimelineArtifactListPanel.value.noValue=No value available."})
220 switch (columnIndex) {
222 return artifactList.get(rowIndex).getDisplayName();
226 return Bundle.MiniTimelineArtifactListPanel_value_noValue();
232 for (BlackboardAttribute.ATTRIBUTE_TYPE attributeType : DESCRIPTION_TYPES) {
233 BlackboardAttribute attribute = artifact.getAttribute(
new Type(attributeType));
234 if (attribute != null && !StringUtils.isBlank(attribute.getDisplayString())) {
235 return attribute.getDisplayString();
238 }
catch (TskCoreException ex) {
239 logger.log(Level.WARNING,
"Unable to get description attribute for artifact id {0}", artifact.getArtifactID());
241 return Bundle.MiniTimelineArtifactListPanel_value_noValue();
246 "MiniTimelineArtifactListPanel.typeColumn.name=Result Type",
247 "MiniTimelineArtifactListPanel.descriptionColumn.name= Description"})
252 return Bundle.MiniTimelineArtifactListPanel_typeColumn_name();
254 return Bundle.MiniTimelineArtifactListPanel_descriptionColumn_name();
262 private javax.swing.JTable artifactsTable;
String getColumnName(int column)
Object getValueAt(int rowIndex, int columnIndex)
String getDescription(BlackboardArtifact artifact)