Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactMenuMouseAdapter.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.discovery.ui;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import javax.swing.Action;
28 import javax.swing.JMenuItem;
29 import javax.swing.JPopupMenu;
30 import javax.swing.JSeparator;
31 import javax.swing.SwingUtilities;
32 import org.openide.util.NbBundle;
46 import org.sleuthkit.datamodel.AbstractFile;
47 import org.sleuthkit.datamodel.BlackboardArtifact;
48 import org.sleuthkit.datamodel.BlackboardAttribute;
49 import org.sleuthkit.datamodel.Content;
50 import org.sleuthkit.datamodel.TskCoreException;
51 
56 class ArtifactMenuMouseAdapter extends java.awt.event.MouseAdapter {
57 
58  private final AbstractArtifactListPanel listPanel;
59  private static final Logger logger = Logger.getLogger(ArtifactMenuMouseAdapter.class.getName());
60 
66  ArtifactMenuMouseAdapter(AbstractArtifactListPanel listPanel) {
67  this.listPanel = listPanel;
68  }
69 
70  @Override
71  public void mouseClicked(java.awt.event.MouseEvent evt) {
72  if (!evt.isPopupTrigger() && SwingUtilities.isRightMouseButton(evt) && listPanel != null && !listPanel.isEmpty()) {
73  if (listPanel.selectAtPoint(evt.getPoint())) {
74  showPopupMenu(evt);
75  }
76  }
77  }
78 
85  private void showPopupMenu(java.awt.event.MouseEvent event) {
86  BlackboardArtifact artifact = listPanel.getSelectedArtifact();
87  if (artifact == null) {
88  return;
89  }
90  try {
91  JMenuItem[] items = getMenuItems(artifact);
92  JPopupMenu popupMenu = new JPopupMenu();
93  for (JMenuItem menu : items) {
94  if (menu != null) {
95  popupMenu.add(menu);
96  } else {
97  popupMenu.add(new JSeparator());
98  }
99  }
100  listPanel.showPopupMenu(popupMenu, event.getPoint());
101  } catch (TskCoreException ex) {
102  logger.log(Level.WARNING, "Unable to get source content of artifact with ID: " + artifact.getArtifactID(), ex);
103  }
104  }
105 
116  private JMenuItem[] getMenuItems(BlackboardArtifact artifact) throws TskCoreException {
117  List<JMenuItem> menuItems = new ArrayList<>();
118  BlackboardAttribute pathIdAttr = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID));
119  long contentId;
120  if (pathIdAttr != null) {
121  contentId = pathIdAttr.getValueLong();
122  } else {
123  contentId = artifact.getObjectID();
124  }
125  Content content = artifact.getSleuthkitCase().getContentById(contentId);
126  menuItems.addAll(getTimelineMenuItems(artifact));
127  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
128  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
129  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
130  return menuItems.toArray(new JMenuItem[0]);
131  }
132 
140  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
141  List<JMenuItem> menuItems = new ArrayList<>();
142  //if this artifact has a time stamp add the action to view it in the timeline
143  try {
144  if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
145  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
146  }
147  } catch (TskCoreException ex) {
148  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
149  }
150 
151  return menuItems;
152  }
153 
164  @NbBundle.Messages({
165  "ArtifactMenuMouseAdapter_ExternalViewer_label=Open in external viewer"
166  })
167  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
168  List<JMenuItem> menuItems = new ArrayList<>();
169  List<Action> actions = DataModelActionsFactory.getActions(content, true);
170  for (Action action : actions) {
171  if (action == null) {
172  menuItems.add(null);
173  } else if (action instanceof ExportCSVAction) {
174  // Do nothing we don't need this menu item.
175  } else if (action instanceof AddContentTagAction) {
176  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
177  } else if (action instanceof AddBlackboardArtifactTagAction) {
178  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
179  } else if (action instanceof ExternalViewerShortcutAction) {
180  // Replace with an ExternalViewerAction
181  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.ArtifactMenuMouseAdapter_ExternalViewer_label(), new FileNode((AbstractFile) content));
182  menuItems.add(new JMenuItem(newAction));
183  } else if (action instanceof ExtractAction) {
184  menuItems.add(new JMenuItem(new ExtractFileAction((AbstractFile) content)));
185  } else {
186  menuItems.add(new JMenuItem(action));
187  }
188  }
189  return menuItems;
190  }
191 
195  @NbBundle.Messages({
196  "ArtifactMenuMouseAdapter_label=Extract Files"
197  })
198  private final class ExtractFileAction extends AbstractAction {
199 
200  private static final long serialVersionUID = 1L;
201  final private AbstractFile file;
202 
208  private ExtractFileAction(AbstractFile file) {
209  super(Bundle.ArtifactMenuMouseAdapter_label());
210  this.file = file;
211  }
212 
213  @Override
214  public void actionPerformed(ActionEvent e) {
216  helper.extract(e, Arrays.asList(file));
217  }
218  }
219 }
void extract(ActionEvent event, Collection<?extends AbstractFile > selectedFiles)

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.