Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentViewerArtifact.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.corecomponents;
20 
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import javax.swing.SwingWorker;
29 import org.openide.nodes.Node;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
32 import org.openide.util.lookup.ServiceProvider;
35 import org.sleuthkit.datamodel.BlackboardArtifact;
36 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
37 import org.sleuthkit.datamodel.BlackboardAttribute;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.TskException;
41 import java.util.Collections;
42 import java.util.HashSet;
45 
53 @ServiceProvider(service = DataContentViewer.class, position = 7)
54 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
55 public class DataContentViewerArtifact extends javax.swing.JPanel implements DataContentViewer {
56 
57  private static final long serialVersionUID = 1L;
58 
59  @NbBundle.Messages({
60  "DataContentViewerArtifact.failedToGetSourcePath.message=Failed to get source file path from case database",
61  "DataContentViewerArtifact.failedToGetAttributes.message=Failed to get some or all attributes from case database"
62  })
63  private final static Logger logger = Logger.getLogger(DataContentViewerArtifact.class.getName());
64  private final static String WAIT_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.waitText");
65  private final static String ERROR_TEXT = NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.errorText");
66 
67  private Node currentNode; // @@@ Remove this when the redundant setNode() calls problem is fixed.
68  private int currentPage = 1;
69  private final Object lock = new Object();
70  private List<BlackboardArtifact> artifactTableContents; // Accessed by multiple threads, use getArtifactContents() and setArtifactContents()
71  private SwingWorker<ViewUpdate, Void> currentTask; // Accessed by multiple threads, use startNewTask()
72 
73  private final Collection<ArtifactContentViewer> knowArtifactViewers = new HashSet<>(Lookup.getDefault().lookupAll(ArtifactContentViewer.class));
74 
76 
77  initComponents();
78 
79  resetComponents();
80  }
81 
87  @SuppressWarnings("unchecked")
88  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
89  private void initComponents() {
90  java.awt.GridBagConstraints gridBagConstraints;
91 
92  jScrollPane1 = new javax.swing.JScrollPane();
93  jPanel1 = new javax.swing.JPanel();
94  totalPageLabel = new javax.swing.JLabel();
95  ofLabel = new javax.swing.JLabel();
96  currentPageLabel = new javax.swing.JLabel();
97  pageLabel = new javax.swing.JLabel();
98  nextPageButton = new javax.swing.JButton();
99  pageLabel2 = new javax.swing.JLabel();
100  prevPageButton = new javax.swing.JButton();
101  artifactLabel = new javax.swing.JLabel();
102  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
103  artifactContentPanel = new javax.swing.JPanel();
104 
105  setPreferredSize(new java.awt.Dimension(100, 58));
106 
107  jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
108  jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
109 
110  jPanel1.setPreferredSize(new java.awt.Dimension(620, 58));
111  jPanel1.setLayout(new java.awt.GridBagLayout());
112 
113  totalPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.totalPageLabel.text")); // NOI18N
114  totalPageLabel.setMaximumSize(new java.awt.Dimension(40, 16));
115  totalPageLabel.setPreferredSize(new java.awt.Dimension(25, 16));
116  gridBagConstraints = new java.awt.GridBagConstraints();
117  gridBagConstraints.gridx = 3;
118  gridBagConstraints.gridy = 0;
119  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
120  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
121  gridBagConstraints.insets = new java.awt.Insets(3, 12, 0, 0);
122  jPanel1.add(totalPageLabel, gridBagConstraints);
123 
124  ofLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.ofLabel.text")); // NOI18N
125  gridBagConstraints = new java.awt.GridBagConstraints();
126  gridBagConstraints.gridx = 2;
127  gridBagConstraints.gridy = 0;
128  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
130  gridBagConstraints.insets = new java.awt.Insets(3, 12, 0, 0);
131  jPanel1.add(ofLabel, gridBagConstraints);
132 
133  currentPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.currentPageLabel.text")); // NOI18N
134  currentPageLabel.setMaximumSize(new java.awt.Dimension(38, 14));
135  currentPageLabel.setMinimumSize(new java.awt.Dimension(18, 14));
136  currentPageLabel.setPreferredSize(new java.awt.Dimension(20, 14));
137  gridBagConstraints = new java.awt.GridBagConstraints();
138  gridBagConstraints.gridx = 1;
139  gridBagConstraints.gridy = 0;
140  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
141  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
142  gridBagConstraints.insets = new java.awt.Insets(4, 7, 0, 0);
143  jPanel1.add(currentPageLabel, gridBagConstraints);
144 
145  pageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.pageLabel.text")); // NOI18N
146  gridBagConstraints = new java.awt.GridBagConstraints();
147  gridBagConstraints.gridx = 0;
148  gridBagConstraints.gridy = 0;
149  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151  gridBagConstraints.insets = new java.awt.Insets(3, 12, 0, 0);
152  jPanel1.add(pageLabel, gridBagConstraints);
153 
154  nextPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png"))); // NOI18N
155  nextPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.nextPageButton.text")); // NOI18N
156  nextPageButton.setBorderPainted(false);
157  nextPageButton.setContentAreaFilled(false);
158  nextPageButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png"))); // NOI18N
159  nextPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
160  nextPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
161  nextPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png"))); // NOI18N
162  nextPageButton.addActionListener(new java.awt.event.ActionListener() {
163  public void actionPerformed(java.awt.event.ActionEvent evt) {
164  nextPageButtonActionPerformed(evt);
165  }
166  });
167  gridBagConstraints = new java.awt.GridBagConstraints();
168  gridBagConstraints.gridx = 6;
169  gridBagConstraints.gridy = 0;
170  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
171  gridBagConstraints.insets = new java.awt.Insets(0, 0, 35, 0);
172  jPanel1.add(nextPageButton, gridBagConstraints);
173 
174  pageLabel2.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.pageLabel2.text")); // NOI18N
175  pageLabel2.setMaximumSize(new java.awt.Dimension(29, 14));
176  pageLabel2.setMinimumSize(new java.awt.Dimension(29, 14));
177  gridBagConstraints = new java.awt.GridBagConstraints();
178  gridBagConstraints.gridx = 4;
179  gridBagConstraints.gridy = 0;
180  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
181  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
182  gridBagConstraints.insets = new java.awt.Insets(3, 41, 0, 0);
183  jPanel1.add(pageLabel2, gridBagConstraints);
184 
185  prevPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back.png"))); // NOI18N
186  prevPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerArtifact.class, "DataContentViewerArtifact.prevPageButton.text")); // NOI18N
187  prevPageButton.setBorderPainted(false);
188  prevPageButton.setContentAreaFilled(false);
189  prevPageButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png"))); // NOI18N
190  prevPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
191  prevPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
192  prevPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png"))); // NOI18N
193  prevPageButton.addActionListener(new java.awt.event.ActionListener() {
194  public void actionPerformed(java.awt.event.ActionEvent evt) {
195  prevPageButtonActionPerformed(evt);
196  }
197  });
198  gridBagConstraints = new java.awt.GridBagConstraints();
199  gridBagConstraints.gridx = 5;
200  gridBagConstraints.gridy = 0;
201  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
202  gridBagConstraints.insets = new java.awt.Insets(0, 5, 35, 0);
203  jPanel1.add(prevPageButton, gridBagConstraints);
204  gridBagConstraints = new java.awt.GridBagConstraints();
205  gridBagConstraints.gridx = 8;
206  gridBagConstraints.gridy = 0;
207  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
208  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
209  gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 8);
210  jPanel1.add(artifactLabel, gridBagConstraints);
211  gridBagConstraints = new java.awt.GridBagConstraints();
212  gridBagConstraints.gridx = 7;
213  gridBagConstraints.gridy = 0;
214  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215  gridBagConstraints.weightx = 0.1;
216  jPanel1.add(filler1, gridBagConstraints);
217 
218  jScrollPane1.setViewportView(jPanel1);
219 
220  artifactContentPanel.setLayout(new javax.swing.OverlayLayout(artifactContentPanel));
221 
222  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
223  this.setLayout(layout);
224  layout.setHorizontalGroup(
225  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
227  .addComponent(artifactContentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
228  );
229  layout.setVerticalGroup(
230  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231  .addGroup(layout.createSequentialGroup()
232  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
233  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
234  .addComponent(artifactContentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE))
235  );
236  }// </editor-fold>//GEN-END:initComponents
237 
238  private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed
239  currentPage += 1;
240  currentPageLabel.setText(Integer.toString(currentPage));
241  artifactLabel.setText(artifactTableContents.get(currentPage - 1).getDisplayName());
242  startNewTask(new SelectedArtifactChangedTask(currentPage));
243  }//GEN-LAST:event_nextPageButtonActionPerformed
244 
245  private void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevPageButtonActionPerformed
246  currentPage -= 1;
247  currentPageLabel.setText(Integer.toString(currentPage));
248  artifactLabel.setText(artifactTableContents.get(currentPage - 1).getDisplayName());
249  startNewTask(new SelectedArtifactChangedTask(currentPage));
250  }//GEN-LAST:event_prevPageButtonActionPerformed
251 
252  // Variables declaration - do not modify//GEN-BEGIN:variables
253  private javax.swing.JPanel artifactContentPanel;
254  private javax.swing.JLabel artifactLabel;
255  private javax.swing.JLabel currentPageLabel;
256  private javax.swing.Box.Filler filler1;
257  private javax.swing.JPanel jPanel1;
258  private javax.swing.JScrollPane jScrollPane1;
259  private javax.swing.JButton nextPageButton;
260  private javax.swing.JLabel ofLabel;
261  private javax.swing.JLabel pageLabel;
262  private javax.swing.JLabel pageLabel2;
263  private javax.swing.JButton prevPageButton;
264  private javax.swing.JLabel totalPageLabel;
265  // End of variables declaration//GEN-END:variables
266 
270  private void resetComponents() {
271  currentPage = 1;
272  currentPageLabel.setText("");
273  artifactLabel.setText("");
274  totalPageLabel.setText("");
275 
276  prevPageButton.setEnabled(false);
277  nextPageButton.setEnabled(false);
278  currentNode = null;
279 
280  artifactContentPanel.removeAll();
281  }
282 
283  @Override
284  public void setNode(Node selectedNode) {
285  if (currentNode == selectedNode) {
286  return;
287  }
288  currentNode = selectedNode;
289 
290  // Make sure there is a node. Null might be passed to reset the viewer.
291  if (selectedNode == null) {
292  return;
293  }
294 
295  // Make sure the node is of the correct type.
296  Lookup lookup = selectedNode.getLookup();
297  Content content = lookup.lookup(Content.class);
298  if (content == null) {
299  return;
300  }
301 
302  startNewTask(new SelectedNodeChangedTask(selectedNode));
303  }
304 
305  @Override
306  public String getTitle() {
307  return NbBundle.getMessage(this.getClass(), "DataContentViewerArtifact.title");
308  }
309 
310  @Override
311  public String getToolTip() {
312  return NbBundle.getMessage(this.getClass(), "DataContentViewerArtifact.toolTip");
313  }
314 
315  @Override
316  public DataContentViewer createInstance() {
317  return new DataContentViewerArtifact();
318  }
319 
320  @Override
321  public Component getComponent() {
322  return this;
323  }
324 
325  @Override
326  public void resetComponent() {
327  resetComponents();
328  }
329 
330  @Override
331  public boolean isSupported(Node node) {
332  if (node == null) {
333  return false;
334  }
335 
336  for (Content content : node.getLookup().lookupAll(Content.class)) {
337  if ((content != null) && (!(content instanceof BlackboardArtifact))) {
338  try {
339  return content.getAllArtifactsCount() > 0;
340  } catch (TskException ex) {
341  logger.log(Level.SEVERE, "Couldn't get count of BlackboardArtifacts for content", ex); //NON-NLS
342  }
343  }
344  }
345  return false;
346  }
347 
348  @Override
349  public int isPreferred(Node node) {
350  BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
351  // low priority if node doesn't have an artifact (meaning it was found from normal directory
352  // browsing, or if the artifact is something that means the user really wants to see the original
353  // file and not more details about the artifact
354  if ((artifact == null)
355  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID())
356  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID())
357  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID())
358  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_OBJECT_DETECTED.getTypeID())
359  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_METADATA_EXIF.getTypeID())
360  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID())
361  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID())
362  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID())) {
363  return 3;
364  } else {
365  return 6;
366  }
367  }
368 
369  private ArtifactContentViewer getSupportingViewer(BlackboardArtifact artifact) {
370  for (ArtifactContentViewer viewer : knowArtifactViewers) {
371  if (viewer.isSupported(artifact)) {
372  return viewer;
373  }
374  }
376  }
377 
382  private class ViewUpdate {
383 
384  int numberOfPages;
385  int currentPage;
386  BlackboardArtifact artifact;
387  String errorMsg;
388 
389  ViewUpdate(int numberOfPages, int currentPage, BlackboardArtifact artifact) {
390  this.currentPage = currentPage;
391  this.numberOfPages = numberOfPages;
392  this.artifact = artifact;
393  this.errorMsg = null;
394  }
395 
396  ViewUpdate(int numberOfPages, int currentPage, String errorMsg) {
397  this.currentPage = currentPage;
398  this.numberOfPages = numberOfPages;
399  this.errorMsg = errorMsg;
400  this.artifact = null;
401  }
402  }
403 
411  private void updateView(ViewUpdate viewUpdate) {
412  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
413 
414  nextPageButton.setEnabled(viewUpdate.currentPage < viewUpdate.numberOfPages);
415  prevPageButton.setEnabled(viewUpdate.currentPage > 1);
416  currentPage = viewUpdate.currentPage;
417  totalPageLabel.setText(Integer.toString(viewUpdate.numberOfPages));
418  currentPageLabel.setText(Integer.toString(currentPage));
419 
420  artifactContentPanel.removeAll();
421 
422  if (viewUpdate.artifact != null) {
423  artifactLabel.setText(viewUpdate.artifact.getDisplayName());
424 
425  BlackboardArtifact artifact = viewUpdate.artifact;
426  ArtifactContentViewer viewer = this.getSupportingViewer(artifact);
427  viewer.setArtifact(artifact);
428 
429  artifactContentPanel.add(viewer.getComponent());
430  } else {
431  artifactLabel.setText(viewUpdate.errorMsg);
432  }
433 
434  artifactContentPanel.repaint();
435  artifactContentPanel.revalidate();
436  this.setCursor(null);
437 
438  this.revalidate();
439  }
440 
447  private synchronized void startNewTask(SwingWorker<ViewUpdate, Void> task) {
448 
449  // The output of the previous task is no longer relevant.
450  if (currentTask != null) {
451  // This call sets a cancellation flag. It does not terminate the background thread running the task.
452  // The task must check the cancellation flag and react appropriately.
453  currentTask.cancel(false);
454  }
455 
456  // Start the new task.
457  currentTask = task;
458  currentTask.execute();
459  }
460 
467  private void setArtifactContents(List<BlackboardArtifact> artifactList) {
468  synchronized (lock) {
469  this.artifactTableContents = artifactList;
470  }
471  }
472 
478  private List<BlackboardArtifact> getArtifactContents() {
479  synchronized (lock) {
480  return Collections.unmodifiableList(artifactTableContents);
481  }
482  }
483 
489  private class SelectedNodeChangedTask extends SwingWorker<ViewUpdate, Void> {
490 
491  private final Node selectedNode;
492 
493  SelectedNodeChangedTask(Node selectedNode) {
494  this.selectedNode = selectedNode;
495  }
496 
497  @Override
499  // Get the lookup for the node for access to its underlying content and
500  // blackboard artifact, if any.
501  Lookup lookup = selectedNode.getLookup();
502 
503  // Get the content. We may get BlackboardArtifacts, ignore those here.
504  ArrayList<BlackboardArtifact> artifacts = new ArrayList<>();
505  Collection<? extends Content> contents = lookup.lookupAll(Content.class);
506  if (contents.isEmpty()) {
507  return new ViewUpdate(getArtifactContents().size(), currentPage, ERROR_TEXT);
508  }
509  Content underlyingContent = null;
510  for (Content content : contents) {
511  if ((content != null) && (!(content instanceof BlackboardArtifact))) {
512  // Get all of the blackboard artifacts associated with the content. These are what this
513  // viewer displays.
514  try {
515  artifacts = content.getAllArtifacts();
516  underlyingContent = content;
517  break;
518  } catch (TskException ex) {
519  logger.log(Level.SEVERE, "Couldn't get artifacts", ex); //NON-NLS
520  return new ViewUpdate(getArtifactContents().size(), currentPage, ERROR_TEXT);
521  }
522  }
523  }
524 
525  if (isCancelled()) {
526  return null;
527  }
528 
529  // Build the new artifact contents cache.
530  ArrayList<BlackboardArtifact> artifactContents = new ArrayList<>();
531  for (BlackboardArtifact artifact : artifacts) {
532  artifactContents.add(artifact);
533  }
534 
535  // If the node has an underlying blackboard artifact, show it. If not,
536  // show the first artifact.
537  int index = 0;
538  BlackboardArtifact artifact = lookup.lookup(BlackboardArtifact.class);
539  if (artifact != null) {
540  index = artifacts.indexOf(artifact);
541  if (index == -1) {
542  index = 0;
543  } else {
544  // if the artifact has an ASSOCIATED ARTIFACT, then we display the associated artifact instead
545  try {
546  for (BlackboardAttribute attr : artifact.getAttributes()) {
547  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
548  long assocArtifactId = attr.getValueLong();
549  int assocArtifactIndex = -1;
550  for (BlackboardArtifact art : artifacts) {
551  if (assocArtifactId == art.getArtifactID()) {
552  assocArtifactIndex = artifacts.indexOf(art);
553  break;
554  }
555  }
556  if (assocArtifactIndex >= 0) {
557  index = assocArtifactIndex;
558  }
559  break;
560  }
561  }
562  } catch (TskCoreException ex) {
563  logger.log(Level.WARNING, "Couldn't get associated artifact to display in Content Viewer.", ex); //NON-NLS
564  }
565  }
566 
567  }
568 
569  if (isCancelled()) {
570  return null;
571  }
572 
573  // Add one to the index of the artifact content for the corresponding page index.
574  ViewUpdate viewUpdate = new ViewUpdate(artifactContents.size(), index + 1, artifactContents.get(index));
575 
576  // It may take a considerable amount of time to fetch the attributes of the selected artifact
577  if (isCancelled()) {
578  return null;
579  }
580 
581  // Update the artifact contents cache.
582  setArtifactContents(artifactContents);
583 
584  return viewUpdate;
585  }
586 
587  @Override
588  protected void done() {
589  if (!isCancelled()) {
590  try {
591  ViewUpdate viewUpdate = get();
592  if (viewUpdate != null) {
593  updateView(viewUpdate);
594  }
595  } catch (InterruptedException | ExecutionException ex) {
596  logger.log(Level.WARNING, "Artifact display task unexpectedly interrupted or failed", ex); //NON-NLS
597  }
598  }
599  }
600  }
601 
607  private class SelectedArtifactChangedTask extends SwingWorker<ViewUpdate, Void> {
608 
609  private final int pageIndex;
610 
611  SelectedArtifactChangedTask(final int pageIndex) {
612  this.pageIndex = pageIndex;
613  }
614 
615  @Override
617  // Get the artifact content to display from the cache. Note that one must be subtracted from the
618  // page index to get the corresponding artifact content index.
619  List<BlackboardArtifact> artifactContents = getArtifactContents();
620 
621  // It may take a considerable amount of time to fetch the attributes of the selected artifact so check for cancellation.
622  if (isCancelled()) {
623  return null;
624  }
625 
626  BlackboardArtifact artifactContent = artifactContents.get(pageIndex - 1);
627  return new ViewUpdate(artifactContents.size(), pageIndex, artifactContent);
628  }
629 
630  @Override
631  protected void done() {
632  if (!isCancelled()) {
633  try {
634  ViewUpdate viewUpdate = get();
635  if (viewUpdate != null) {
636  updateView(viewUpdate);
637  }
638  } catch (InterruptedException | ExecutionException ex) {
639  logger.log(Level.WARNING, "Artifact display task unexpectedly interrupted or failed", ex); //NON-NLS
640  }
641  }
642  }
643  }
644 }
synchronized void startNewTask(SwingWorker< ViewUpdate, Void > task)
ArtifactContentViewer getSupportingViewer(BlackboardArtifact artifact)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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