19 package org.sleuthkit.autopsy.actions;
21 import java.awt.event.ActionEvent;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.List;
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;
53 "DeleteFileBlackboardArtifactTagAction.deleteTag=Remove Result Tag"
59 private static final long serialVersionUID = 1L;
61 "DeleteFileBlackboardArtifactTagAction.deleteTag");
69 if (null == instance) {
92 @NbBundle.Messages({
"# {0} - artifactID",
93 "DeleteFileBlackboardArtifactTagAction.deleteTag.alert=Unable to untag artifact {0}."})
94 protected void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag,
long artifactId) {
95 new SwingWorker<Void, Void>() {
98 protected Void doInBackground()
throws Exception {
103 logger.log(Level.SEVERE,
"Error untagging artifact. No open case found.", ex);
105 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
111 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()});
113 }
catch (TskCoreException tskCoreException) {
114 logger.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
116 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
123 protected void done() {
127 }
catch (InterruptedException | ExecutionException ex) {
128 logger.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
139 @NbBundle.Messages({
"# {0} - artifactID",
140 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
143 private static final long serialVersionUID = 1L;
146 super(getActionDisplayName());
148 final Collection<BlackboardArtifact> selectedBlackboardArtifactsList
149 =
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
151 if (!selectedBlackboardArtifactsList.isEmpty()) {
152 BlackboardArtifact artifact
153 = selectedBlackboardArtifactsList.iterator().next();
155 Map<String, TagName> tagNamesMap = null;
168 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
170 List<BlackboardArtifactTag> existingTagsList
174 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
175 String tagDisplayName = entry.getKey();
177 TagName tagName = entry.getValue();
178 for (BlackboardArtifactTag artifactTag : existingTagsList) {
179 if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
181 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
182 tagNameItem.addActionListener((ActionEvent e) -> {
183 deleteTag(tagName, artifactTag, artifact.getArtifactID());
191 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
195 if (getItemCount() == 0) {
static synchronized DeleteFileBlackboardArtifactTagAction getInstance()
TagsManager getTagsManager()
static DeleteFileBlackboardArtifactTagAction instance
void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag, long artifactId)
DeleteFileBlackboardArtifactTagAction()
String getActionDisplayName()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
void actionPerformed(ActionEvent event)
JMenuItem getPopupPresenter()