19 package org.sleuthkit.autopsy.contentviewers.annotations;
21 import com.google.common.collect.ImmutableSet;
22 import java.awt.Component;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.EnumSet;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import javax.swing.SwingWorker;
30 import org.apache.commons.lang3.tuple.Pair;
32 import static org.openide.util.NbBundle.Messages;
33 import org.openide.nodes.Node;
34 import org.openide.util.lookup.ServiceProvider;
37 import org.jsoup.nodes.Document;
38 import org.openide.util.WeakListeners;
55 @SuppressWarnings(
"PMD.SingularField")
58 "AnnotationsContentViewer.title=Annotations",
59 "AnnotationsContentViewer.toolTip=Displays tags and comments associated with the selected content.",
60 "AnnotationsContentViewer.onEmpty=No annotations were found for this particular item."
64 private static final long serialVersionUID = 1L;
67 private static final Set<
Case.
Events> CASE_EVENTS_OF_INTEREST = EnumSet.of(
80 @SuppressWarnings(
"deprecation")
81 private static final Set<BlackboardArtifact.Type> ARTIFACT_TYPES_OF_INTEREST = ImmutableSet.of(
82 BlackboardArtifact.Type.TSK_HASHSET_HIT,
83 BlackboardArtifact.Type.TSK_INTERESTING_FILE_HIT,
84 BlackboardArtifact.Type.TSK_INTERESTING_ITEM
87 private final PropertyChangeListener ingestEventListener = (evt) -> {
91 if (curArtifactId == null && curContentId == null) {
103 for (BlackboardArtifact artifact : moduleDataEvent.
getArtifacts()) {
104 if ((curArtifactId != null && artifact.getArtifactID() == curArtifactId)
105 || (curContentId != null && artifact.getObjectID() == curContentId)) {
114 private final PropertyChangeListener weakIngestEventListener = WeakListeners.propertyChange(ingestEventListener, null);
116 private final PropertyChangeListener caseEventListener = (evt) -> {
120 if (curArtifactId == null && curContentId == null) {
124 Pair<Long, Long> artifactContentId = getIdsFromEvent(evt);
125 Long artifactId = artifactContentId.getLeft();
126 Long contentId = artifactContentId.getRight();
129 if ((curArtifactId != null && curArtifactId.equals(artifactId)) || (curContentId != null && curContentId.equals(contentId))) {
134 private final PropertyChangeListener weakCaseEventListener = WeakListeners.propertyChange(caseEventListener, null);
136 private final Object updateLock =
new Object();
162 unregisterListeners();
176 DisplayTskItems displayItems =
AnnotationUtils.getDisplayContent(node);
177 this.curArtifactId = displayItems.getArtifact() == null ? null : displayItems.getArtifact().getArtifactID();
178 this.curContentId = displayItems.getContent() == null ? null : displayItems.getContent().getId();
179 updateData(this.node,
true);
194 eventType =
Case.
Events.valueOf(evt.getPropertyName());
195 }
catch (IllegalArgumentException ex) {
196 logger.log(Level.SEVERE,
"Unknown event type: " + evt.getPropertyName(), ex);
197 return Pair.of(null, null);
200 Long artifactId = null;
201 Long contentId = null;
204 case BLACKBOARD_ARTIFACT_TAG_ADDED:
206 BlackboardArtifact art = ((BlackBoardArtifactTagAddedEvent) evt).getAddedTag().getArtifact();
207 artifactId = art.getArtifactID();
208 contentId = art.getObjectID();
211 case BLACKBOARD_ARTIFACT_TAG_DELETED:
213 artifactId = ((BlackBoardArtifactTagDeletedEvent) evt).getDeletedTagInfo().getArtifactID();
214 contentId = ((BlackBoardArtifactTagDeletedEvent) evt).getDeletedTagInfo().getContentID();
217 case CONTENT_TAG_ADDED:
219 contentId = ((ContentTagAddedEvent) evt).getAddedTag().getContent().getId();
222 case CONTENT_TAG_DELETED:
224 contentId = ((ContentTagDeletedEvent) evt).getDeletedTagInfo().getContentID();
227 case CR_COMMENT_CHANGED:
229 long commentObjId = ((CommentChangedEvent) evt).getContentID();
230 artifactId = commentObjId;
231 contentId = commentObjId;
238 return Pair.of(artifactId, contentId);
245 if (this.isVisible()) {
246 updateData(this.node,
false);
268 synchronized (updateLock) {
269 if (worker != null) {
288 @SuppressWarnings(
"unchecked")
290 private
void initComponents() {
292 javax.swing.JScrollPane scrollPane =
new javax.swing.JScrollPane();
293 textPanel =
new javax.swing.JTextPane();
295 setPreferredSize(
new java.awt.Dimension(100, 58));
297 textPanel.setEditable(
false);
298 textPanel.setName(
"");
299 textPanel.setPreferredSize(
new java.awt.Dimension(600, 52));
300 scrollPane.setViewportView(textPanel);
302 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
303 this.setLayout(layout);
304 layout.setHorizontalGroup(
305 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
308 layout.setVerticalGroup(
309 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310 .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
320 return Bundle.AnnotationsContentViewer_title();
325 return Bundle.AnnotationsContentViewer_toolTip();
350 textPanel.setText(
"");
372 this.resetCaretPosition = resetCaretPosition;
392 if (!isCancelled()) {
396 textPanel.setText(text);
398 if (resetCaretPosition) {
399 textPanel.setCaretPosition(0);
402 }
catch (InterruptedException | ExecutionException ex) {
403 logger.log(Level.SEVERE,
"Failed to get annotation information for node", ex);
407 synchronized (updateLock) {
408 if (worker ==
this) {
Collection< BlackboardArtifact > getArtifacts()
BlackboardArtifact.Type getBlackboardArtifactType()
static synchronized IngestManager getInstance()
boolean isSupported(Node node)
javax.swing.JTextPane textPanel
static void setStyles(JTextPane textPane)
final boolean resetCaretPosition
static boolean isSupported(Node node)
static Document buildDocument(Node node)
static void setupHtmlJTextPane(JTextPane textPane)
static String getMessageClassName()
BLACKBOARD_ARTIFACT_TAG_ADDED
static Pair< Long, Long > getIdsFromEvent(PropertyChangeEvent evt)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
AnnotationsContentViewer()
int isPreferred(Node node)
void updateData(Node node, boolean forceReset)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
void unregisterListeners()
BLACKBOARD_ARTIFACT_TAG_DELETED
DataContentViewer createInstance()