Autopsy  4.15.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  return 3;
362  } else {
363  return 6;
364  }
365  }
366 
367  private ArtifactContentViewer getSupportingViewer(BlackboardArtifact artifact) {
368  for (ArtifactContentViewer viewer : knowArtifactViewers) {
369  if (viewer.isSupported(artifact)) {
370  return viewer;
371  }
372  }
373  return new DefaultArtifactContentViewer();
374  }
375 
380  private class ViewUpdate {
381 
382  int numberOfPages;
383  int currentPage;
384  BlackboardArtifact artifact;
385  String errorMsg;
386 
387  ViewUpdate(int numberOfPages, int currentPage, BlackboardArtifact artifact) {
388  this.currentPage = currentPage;
389  this.numberOfPages = numberOfPages;
390  this.artifact = artifact;
391  this.errorMsg = null;
392  }
393 
394  ViewUpdate(int numberOfPages, int currentPage, String errorMsg) {
395  this.currentPage = currentPage;
396  this.numberOfPages = numberOfPages;
397  this.errorMsg = errorMsg;
398  this.artifact = null;
399  }
400  }
401 
409  private void updateView(ViewUpdate viewUpdate) {
410  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
411 
412  nextPageButton.setEnabled(viewUpdate.currentPage < viewUpdate.numberOfPages);
413  prevPageButton.setEnabled(viewUpdate.currentPage > 1);
414  currentPage = viewUpdate.currentPage;
415  totalPageLabel.setText(Integer.toString(viewUpdate.numberOfPages));
416  currentPageLabel.setText(Integer.toString(currentPage));
417 
418  artifactContentPanel.removeAll();
419 
420  if (viewUpdate.artifact != null) {
421  artifactLabel.setText(viewUpdate.artifact.getDisplayName());
422 
423  BlackboardArtifact artifact = viewUpdate.artifact;
424  ArtifactContentViewer viewer = this.getSupportingViewer(artifact);
425  viewer.setArtifact(artifact);
426 
427  artifactContentPanel.add(viewer.getComponent());
428  } else {
429  artifactLabel.setText(viewUpdate.errorMsg);
430  }
431 
432  artifactContentPanel.repaint();
433  artifactContentPanel.revalidate();
434  this.setCursor(null);
435 
436  this.revalidate();
437  }
438 
445  private synchronized void startNewTask(SwingWorker<ViewUpdate, Void> task) {
446 
447  // The output of the previous task is no longer relevant.
448  if (currentTask != null) {
449  // This call sets a cancellation flag. It does not terminate the background thread running the task.
450  // The task must check the cancellation flag and react appropriately.
451  currentTask.cancel(false);
452  }
453 
454  // Start the new task.
455  currentTask = task;
456  currentTask.execute();
457  }
458 
465  private void setArtifactContents(List<BlackboardArtifact> artifactList) {
466  synchronized (lock) {
467  this.artifactTableContents = artifactList;
468  }
469  }
470 
476  private List<BlackboardArtifact> getArtifactContents() {
477  synchronized (lock) {
478  return Collections.unmodifiableList(artifactTableContents);
479  }
480  }
481 
487  private class SelectedNodeChangedTask extends SwingWorker<ViewUpdate, Void> {
488 
489  private final Node selectedNode;
490 
491  SelectedNodeChangedTask(Node selectedNode) {
492  this.selectedNode = selectedNode;
493  }
494 
495  @Override
497  // Get the lookup for the node for access to its underlying content and
498  // blackboard artifact, if any.
499  Lookup lookup = selectedNode.getLookup();
500 
501  // Get the content. We may get BlackboardArtifacts, ignore those here.
502  ArrayList<BlackboardArtifact> artifacts = new ArrayList<>();
503  Collection<? extends Content> contents = lookup.lookupAll(Content.class);
504  if (contents.isEmpty()) {
505  return new ViewUpdate(getArtifactContents().size(), currentPage, ERROR_TEXT);
506  }
507  Content underlyingContent = null;
508  for (Content content : contents) {
509  if ((content != null) && (!(content instanceof BlackboardArtifact))) {
510  // Get all of the blackboard artifacts associated with the content. These are what this
511  // viewer displays.
512  try {
513  artifacts = content.getAllArtifacts();
514  underlyingContent = content;
515  break;
516  } catch (TskException ex) {
517  logger.log(Level.SEVERE, "Couldn't get artifacts", ex); //NON-NLS
518  return new ViewUpdate(getArtifactContents().size(), currentPage, ERROR_TEXT);
519  }
520  }
521  }
522 
523  if (isCancelled()) {
524  return null;
525  }
526 
527  // Build the new artifact contents cache.
528  ArrayList<BlackboardArtifact> artifactContents = new ArrayList<>();
529  for (BlackboardArtifact artifact : artifacts) {
530  artifactContents.add(artifact);
531  }
532 
533  // If the node has an underlying blackboard artifact, show it. If not,
534  // show the first artifact.
535  int index = 0;
536  BlackboardArtifact artifact = lookup.lookup(BlackboardArtifact.class);
537  if (artifact != null) {
538  index = artifacts.indexOf(artifact);
539  if (index == -1) {
540  index = 0;
541  } else {
542  // if the artifact has an ASSOCIATED ARTIFACT, then we display the associated artifact instead
543  try {
544  for (BlackboardAttribute attr : artifact.getAttributes()) {
545  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
546  long assocArtifactId = attr.getValueLong();
547  int assocArtifactIndex = -1;
548  for (BlackboardArtifact art : artifacts) {
549  if (assocArtifactId == art.getArtifactID()) {
550  assocArtifactIndex = artifacts.indexOf(art);
551  break;
552  }
553  }
554  if (assocArtifactIndex >= 0) {
555  index = assocArtifactIndex;
556  }
557  break;
558  }
559  }
560  } catch (TskCoreException ex) {
561  logger.log(Level.WARNING, "Couldn't get associated artifact to display in Content Viewer.", ex); //NON-NLS
562  }
563  }
564 
565  }
566 
567  if (isCancelled()) {
568  return null;
569  }
570 
571  // Add one to the index of the artifact content for the corresponding page index.
572  ViewUpdate viewUpdate = new ViewUpdate(artifactContents.size(), index + 1, artifactContents.get(index));
573 
574  // It may take a considerable amount of time to fetch the attributes of the selected artifact
575  if (isCancelled()) {
576  return null;
577  }
578 
579  // Update the artifact contents cache.
580  setArtifactContents(artifactContents);
581 
582  return viewUpdate;
583  }
584 
585  @Override
586  protected void done() {
587  if (!isCancelled()) {
588  try {
589  ViewUpdate viewUpdate = get();
590  if (viewUpdate != null) {
591  updateView(viewUpdate);
592  }
593  } catch (InterruptedException | ExecutionException ex) {
594  logger.log(Level.WARNING, "Artifact display task unexpectedly interrupted or failed", ex); //NON-NLS
595  }
596  }
597  }
598  }
599 
605  private class SelectedArtifactChangedTask extends SwingWorker<ViewUpdate, Void> {
606 
607  private final int pageIndex;
608 
609  SelectedArtifactChangedTask(final int pageIndex) {
610  this.pageIndex = pageIndex;
611  }
612 
613  @Override
615  // Get the artifact content to display from the cache. Note that one must be subtracted from the
616  // page index to get the corresponding artifact content index.
617  List<BlackboardArtifact> artifactContents = getArtifactContents();
618 
619  // It may take a considerable amount of time to fetch the attributes of the selected artifact so check for cancellation.
620  if (isCancelled()) {
621  return null;
622  }
623 
624  BlackboardArtifact artifactContent = artifactContents.get(pageIndex - 1);
625  return new ViewUpdate(artifactContents.size(), pageIndex, artifactContent);
626  }
627 
628  @Override
629  protected void done() {
630  if (!isCancelled()) {
631  try {
632  ViewUpdate viewUpdate = get();
633  if (viewUpdate != null) {
634  updateView(viewUpdate);
635  }
636  } catch (InterruptedException | ExecutionException ex) {
637  logger.log(Level.WARNING, "Artifact display task unexpectedly interrupted or failed", ex); //NON-NLS
638  }
639  }
640  }
641  }
642 }
synchronized void startNewTask(SwingWorker< ViewUpdate, Void > task)
ArtifactContentViewer getSupportingViewer(BlackboardArtifact artifact)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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