19 package org.sleuthkit.autopsy.discovery.ui;
 
   21 import java.awt.Color;
 
   22 import java.awt.event.ActionEvent;
 
   23 import java.util.ArrayList;
 
   24 import java.util.Arrays;
 
   25 import java.util.List;
 
   26 import java.util.logging.Level;
 
   27 import javax.swing.AbstractAction;
 
   28 import javax.swing.Action;
 
   29 import javax.swing.JMenuItem;
 
   30 import javax.swing.JPopupMenu;
 
   31 import javax.swing.JSeparator;
 
   32 import javax.swing.SwingUtilities;
 
   33 import org.openide.util.NbBundle;
 
   57 class ArtifactMenuMouseAdapter 
extends java.awt.event.MouseAdapter {
 
   59     private final AbstractArtifactListPanel listPanel;
 
   60     private static final Logger logger = Logger.getLogger(ArtifactMenuMouseAdapter.class.getName());
 
   67     ArtifactMenuMouseAdapter(AbstractArtifactListPanel listPanel) {
 
   68         this.listPanel = listPanel;
 
   72     public void mouseClicked(java.awt.event.MouseEvent evt) {
 
   73         if (!evt.isPopupTrigger() && SwingUtilities.isRightMouseButton(evt) && listPanel != null && !listPanel.isEmpty()) {
 
   74             if (listPanel.selectAtPoint(evt.getPoint())) {
 
   86     private void showPopupMenu(java.awt.event.MouseEvent event) {
 
   87         BlackboardArtifact artifact = listPanel.getSelectedArtifact();
 
   88         if (artifact == null) {
 
   92             JMenuItem[] items = getMenuItems(artifact);
 
   93             JPopupMenu popupMenu = 
new JPopupMenu();
 
   94             for (JMenuItem menu : items) {
 
   98                     popupMenu.add(
new JSeparator());
 
  101             listPanel.showPopupMenu(popupMenu, event.getPoint());
 
  102         } 
catch (TskCoreException ex) {
 
  103             logger.log(Level.WARNING, 
"Unable to get source content of artifact with ID: " + artifact.getArtifactID(), ex);
 
  117     @NbBundle.Messages({
"ArtifactMenuMouseAdapter.noFile.text=File does not exist."})
 
  118     private JMenuItem[] getMenuItems(BlackboardArtifact artifact) 
throws TskCoreException {
 
  119         List<JMenuItem> menuItems = 
new ArrayList<>();
 
  120         BlackboardAttribute pathIdAttr = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID));
 
  122         if (pathIdAttr != null) {
 
  123             contentId = pathIdAttr.getValueLong();
 
  124         } 
else if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() && artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()) {
 
  125             contentId = artifact.getObjectID();
 
  128             JMenuItem noFile = 
new JMenuItem();
 
  129             noFile.setText(Bundle.ArtifactMenuMouseAdapter_noFile_text());
 
  130             noFile.setEnabled(
false);
 
  131             noFile.setForeground(Color.RED);
 
  132             menuItems.add(noFile);
 
  134         menuItems.addAll(getTimelineMenuItems(artifact));
 
  135         if (contentId != null) {
 
  136             Content content = artifact.getSleuthkitCase().getContentById(contentId);
 
  137             menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
 
  138             menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
 
  140            menuItems.add(AddBlackboardArtifactTagAction.getInstance().getMenuForContent(Arrays.asList(artifact)));
 
  142         menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
 
  143         return menuItems.toArray(
new JMenuItem[0]);
 
  153     private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
 
  154         List<JMenuItem> menuItems = 
new ArrayList<>();
 
  157             if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
 
  158                 menuItems.add(
new JMenuItem(
new ViewArtifactInTimelineAction(artifact)));
 
  160         } 
catch (TskCoreException ex) {
 
  161             logger.log(Level.SEVERE, String.format(
"Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); 
 
  178         "ArtifactMenuMouseAdapter_ExternalViewer_label=Open in external viewer" 
  180     private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
 
  181         List<JMenuItem> menuItems = 
new ArrayList<>();
 
  182         List<Action> actions = DataModelActionsFactory.getActions(content, 
true);
 
  183         for (Action action : actions) {
 
  184             if (action == null) {
 
  186             } 
else if (action instanceof ExportCSVAction) {
 
  188             } 
else if (action instanceof AddContentTagAction) {
 
  189                 menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
 
  190             } 
else if (action instanceof AddBlackboardArtifactTagAction) {
 
  191                 menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
 
  192             } 
else if (action instanceof ExternalViewerShortcutAction) {
 
  194                 ExternalViewerAction newAction = 
new ExternalViewerAction(Bundle.ArtifactMenuMouseAdapter_ExternalViewer_label(), 
new FileNode((AbstractFile) content));
 
  195                 menuItems.add(
new JMenuItem(newAction));
 
  196             } 
else if (action instanceof ExtractAction) {
 
  197                 menuItems.add(
new JMenuItem(
new ExtractFileAction((AbstractFile) content)));
 
  199                 menuItems.add(
new JMenuItem(action));
 
  209         "ArtifactMenuMouseAdapter_label=Extract Files" 
  213         private static final long serialVersionUID = 1L;
 
  222             super(Bundle.ArtifactMenuMouseAdapter_label());
 
  229             helper.
extract(e, Arrays.asList(file));