Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DeleteFileBlackboardArtifactTagAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 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.actions;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import javafx.application.Platform;
30 import javafx.scene.control.Alert;
31 import javax.swing.AbstractAction;
32 import javax.swing.JMenu;
33 import javax.swing.JMenuItem;
34 import javax.swing.SwingWorker;
35 import org.openide.util.NbBundle;
36 import org.openide.util.Utilities;
37 import org.openide.util.actions.Presenter;
41 import org.sleuthkit.datamodel.BlackboardArtifact;
42 import org.sleuthkit.datamodel.BlackboardArtifactTag;
43 import org.sleuthkit.datamodel.TagName;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.TskData;
46 
51 @NbBundle.Messages({
52  "DeleteFileBlackboardArtifactTagAction.deleteTag=Remove Result Tag"
53 })
54 public class DeleteFileBlackboardArtifactTagAction extends AbstractAction implements Presenter.Popup {
55 
56  private static final Logger logger = Logger.getLogger(DeleteFileBlackboardArtifactTagAction.class.getName());
57 
58  private static final long serialVersionUID = 1L;
59  private static final String MENU_TEXT = NbBundle.getMessage(DeleteFileBlackboardArtifactTagAction.class,
60  "DeleteFileBlackboardArtifactTagAction.deleteTag");
61 
62  // This class is a singleton to support multi-selection of nodes, since
63  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
64  // node in the array returns a reference to the same action object from Node.getActions(boolean).
66 
67  public static synchronized DeleteFileBlackboardArtifactTagAction getInstance() {
68  if (null == instance) {
70  }
71  return instance;
72  }
73 
75  super(MENU_TEXT);
76  }
77 
78  @Override
79  public JMenuItem getPopupPresenter() {
80  return new TagMenu();
81  }
82 
83  @Override
84  public void actionPerformed(ActionEvent event) {
85  }
86 
87  protected String getActionDisplayName() {
88  return MENU_TEXT;
89  }
90 
91  @NbBundle.Messages({"# {0} - artifactID",
92  "DeleteFileBlackboardArtifactTagAction.deleteTag.alert=Unable to untag artifact {0}."})
93  protected void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag, long artifactId) {
94  new SwingWorker<Void, Void>() {
95 
96  @Override
97  protected Void doInBackground() throws Exception {
99 
100  try {
101  logger.log(Level.INFO, "Removing tag {0} from {1}", new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()}); //NON-NLS
102  tagsManager.deleteBlackboardArtifactTag(artifactTag);
103  } catch (TskCoreException tskCoreException) {
104  logger.log(Level.SEVERE, "Error untagging artifact", tskCoreException); //NON-NLS
105  Platform.runLater(()
106  -> new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
107  );
108  }
109  return null;
110  }
111 
112  @Override
113  protected void done() {
114  super.done();
115  try {
116  get();
117  } catch (InterruptedException | ExecutionException ex) {
118  logger.log(Level.SEVERE, "Unexpected exception while untagging artifact", ex); //NON-NLS
119  }
120  }
121  }.execute();
122  }
123 
129  @NbBundle.Messages({"# {0} - artifactID",
130  "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
131  private class TagMenu extends JMenu {
132 
133  private static final long serialVersionUID = 1L;
134 
135  TagMenu() {
136  super(getActionDisplayName());
137 
138  final Collection<BlackboardArtifact> selectedBlackboardArtifactsList
139  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
140 
141  if (!selectedBlackboardArtifactsList.isEmpty()) {
142  BlackboardArtifact artifact
143  = selectedBlackboardArtifactsList.iterator().next();
144 
145  // Get the current set of tag names.
147 
148  Map<String, TagName> tagNamesMap = null;
149  try {
150  tagNamesMap = new TreeMap<>(tagsManager.getDisplayNamesToTagNamesMap());
151  } catch (TskCoreException ex) {
152  Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
153  }
154 
155  // Each tag name in the current set of tags gets its own menu item in
156  // the "Quick Tags" sub-menu. Selecting one of these menu items adds
157  // a tag with the associated tag name.
158  if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
159  try {
160  List<BlackboardArtifactTag> existingTagsList
163 
164  for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
165  String tagDisplayName = entry.getKey();
166 
167  TagName tagName = entry.getValue();
168  for (BlackboardArtifactTag artifactTag : existingTagsList) {
169  if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
170  String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() : "";
171  JMenuItem tagNameItem = new JMenuItem(tagDisplayName + notableString);
172  tagNameItem.addActionListener((ActionEvent e) -> {
173  deleteTag(tagName, artifactTag, artifact.getArtifactID());
174  });
175  add(tagNameItem);
176  }
177  }
178  }
179  } catch (TskCoreException ex) {
180  Logger.getLogger(TagMenu.class.getName())
181  .log(Level.SEVERE, "Error retrieving tags for TagMenu", ex); //NON-NLS
182  }
183  }
184 
185  if (getItemCount() == 0) {
186  setEnabled(false);
187  }
188  }
189  }
190  }
191 
192 }
static synchronized DeleteFileBlackboardArtifactTagAction getInstance()
void deleteBlackboardArtifactTag(BlackboardArtifactTag tag)
void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag, long artifactId)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
List< BlackboardArtifactTag > getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact)

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