Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AnalysisResultsContentViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.contentviewers.analysisresults;
20 
21 import java.awt.Component;
22 import java.util.Objects;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.swing.SwingWorker;
26 import org.openide.nodes.Node;
27 import org.openide.util.NbBundle;
28 import org.openide.util.lookup.ServiceProvider;
36 import org.sleuthkit.datamodel.Content;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 @ServiceProvider(service = DataContentViewer.class, position = 7)
45 
46  private static final Logger logger = Logger.getLogger(AnalysisResultsContentPanel.class.getName());
47 
48  // isPreferred value
49  private static final int PREFERRED_VALUE = ViewerPriority.viewerPriority.LevelThree.getFlag();
50  private final AnalysisResultsViewModel viewModel = new AnalysisResultsViewModel();
52 
53  private SwingWorker<?, ?> worker = null;
54 
55  @NbBundle.Messages({
56  "AnalysisResultsContentViewer_title=Analysis Results"
57  })
58  @Override
59  public String getTitle() {
60  return Bundle.AnalysisResultsContentViewer_title();
61  }
62 
63  @NbBundle.Messages({
64  "AnalysisResultsContentViewer_tooltip=Viewer for Analysis Results related to the selected node."
65  })
66  @Override
67  public String getToolTip() {
68  return Bundle.AnalysisResultsContentViewer_tooltip();
69  }
70 
71  @Override
72  public DataContentViewer createInstance() {
73  return new AnalysisResultsContentViewer();
74  }
75 
76  @Override
77  public Component getComponent() {
78  return panel;
79  }
80 
81  @Override
82  public void resetComponent() {
83  panel.reset();
84  }
85 
86  @Override
87  @NbBundle.Messages({
88  "AnalysisResultsContentViewer_setNode_loadingMessage=Loading...",
89  "AnalysisResultsContentViewer_setNode_errorMessage=There was an error loading results.",})
90  public synchronized void setNode(Node node) {
91  // reset the panel
92  panel.reset();
93 
94  // if there is a worker running, cancel it
95  if (worker != null) {
96  worker.cancel(true);
97  worker = null;
98  }
99 
100  // if no node, nothing to do
101  if (node == null) {
102  return;
103  }
104 
105  // show a loading message
106  panel.showMessage(Bundle.AnalysisResultsContentViewer_setNode_loadingMessage());
107 
108  // create the worker
109  worker = new DataFetchWorker<>(
110  // load a view model from the node
111  (selectedNode) -> viewModel.getAnalysisResults(selectedNode),
112  (nodeAnalysisResults) -> {
113  if (nodeAnalysisResults.getResultType() == DataFetchResult.ResultType.SUCCESS) {
114  // if successful, display the results
115  panel.displayResults(nodeAnalysisResults.getData());
116  } else {
117  // if there was an error, display an error message
118  panel.showMessage(Bundle.AnalysisResultsContentViewer_setNode_errorMessage());
119  }
120  },
121  node);
122 
123  // kick off the swing worker
124  worker.execute();
125  }
126 
127  @Override
128  public boolean isSupported(Node node) {
129  if (Objects.isNull(node)) {
130  return false;
131  }
132 
133  AnalysisResultItem analysisResultItem = node.getLookup().lookup(AnalysisResultItem.class);
134  if (Objects.nonNull(analysisResultItem)) {
135  return true;
136  }
137 
138  TskContentItem<?> contentItem = node.getLookup().lookup(TskContentItem.class);
139  if (!Objects.isNull(contentItem)) {
140  Content content = contentItem.getTskContent();
141  try {
142  if (Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard().hasAnalysisResults(content.getId())) {
143  return true;
144  }
145  } catch (NoCurrentCaseException | TskCoreException ex) {
146  logger.log(Level.SEVERE, String.format("Error getting analysis results for Content (object ID = %d)", content.getId()), ex);
147  }
148  }
149 
150  return false;
151  }
152 
153  @Override
154  public int isPreferred(Node node) {
155  return PREFERRED_VALUE;
156  }
157 
158 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.