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;
52 "DeleteFileBlackboardArtifactTagAction.deleteTag=Remove Result Tag"
58 private static final long serialVersionUID = 1L;
60 "DeleteFileBlackboardArtifactTagAction.deleteTag");
68 if (null == instance) {
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>() {
97 protected Void doInBackground()
throws Exception {
101 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()});
103 }
catch (TskCoreException tskCoreException) {
104 logger.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
106 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
113 protected void done() {
117 }
catch (InterruptedException | ExecutionException ex) {
118 logger.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
129 @NbBundle.Messages({
"# {0} - artifactID",
130 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
133 private static final long serialVersionUID = 1L;
136 super(getActionDisplayName());
138 final Collection<BlackboardArtifact> selectedBlackboardArtifactsList
139 =
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
141 if (!selectedBlackboardArtifactsList.isEmpty()) {
142 BlackboardArtifact artifact
143 = selectedBlackboardArtifactsList.iterator().next();
148 Map<String, TagName> tagNamesMap = null;
151 }
catch (TskCoreException ex) {
158 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
160 List<BlackboardArtifactTag> existingTagsList
164 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
165 String tagDisplayName = entry.getKey();
167 TagName tagName = entry.getValue();
168 for (BlackboardArtifactTag artifactTag : existingTagsList) {
169 if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
171 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
172 tagNameItem.addActionListener((ActionEvent e) -> {
173 deleteTag(tagName, artifactTag, artifact.getArtifactID());
179 }
catch (TskCoreException ex) {
181 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
185 if (getItemCount() == 0) {
static synchronized DeleteFileBlackboardArtifactTagAction getInstance()
TagsManager getTagsManager()
static DeleteFileBlackboardArtifactTagAction instance
void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag, long artifactId)
DeleteFileBlackboardArtifactTagAction()
String getActionDisplayName()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
void actionPerformed(ActionEvent event)
JMenuItem getPopupPresenter()