19 package org.sleuthkit.autopsy.discovery.ui;
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;
56 class ArtifactMenuMouseAdapter
extends java.awt.event.MouseAdapter {
58 private final AbstractArtifactListPanel listPanel;
59 private static final Logger logger = Logger.getLogger(ArtifactMenuMouseAdapter.class.getName());
66 ArtifactMenuMouseAdapter(AbstractArtifactListPanel listPanel) {
67 this.listPanel = listPanel;
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())) {
85 private void showPopupMenu(java.awt.event.MouseEvent event) {
86 BlackboardArtifact artifact = listPanel.getSelectedArtifact();
87 if (artifact == null) {
91 JMenuItem[] items = getMenuItems(artifact);
92 JPopupMenu popupMenu =
new JPopupMenu();
93 for (JMenuItem menu : items) {
97 popupMenu.add(
new JSeparator());
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);
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));
120 if (pathIdAttr != null) {
121 contentId = pathIdAttr.getValueLong();
123 contentId = artifact.getObjectID();
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]);
140 private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
141 List<JMenuItem> menuItems =
new ArrayList<>();
144 if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
145 menuItems.add(
new JMenuItem(
new ViewArtifactInTimelineAction(artifact)));
147 }
catch (TskCoreException ex) {
148 logger.log(Level.SEVERE, String.format(
"Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex);
165 "ArtifactMenuMouseAdapter_ExternalViewer_label=Open in external viewer"
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) {
173 }
else if (action instanceof ExportCSVAction) {
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) {
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)));
186 menuItems.add(
new JMenuItem(action));
196 "ArtifactMenuMouseAdapter_label=Extract Files"
200 private static final long serialVersionUID = 1L;
201 final private AbstractFile
file;
209 super(Bundle.ArtifactMenuMouseAdapter_label());
216 helper.
extract(e, Arrays.asList(file));