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 {
102 final Collection<AbstractFile> selectedFilesList =
103 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
104 AbstractFile file = selectedFilesList.iterator().next();
107 LOGGER.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), file.getName()});
109 }
catch (TskCoreException tskCoreException) {
110 LOGGER.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
111 Platform.runLater(() ->
112 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
119 protected void done() {
123 }
catch (InterruptedException | ExecutionException ex) {
124 LOGGER.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
135 @NbBundle.Messages({
"# {0} - artifactID",
136 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
139 private static final long serialVersionUID = 1L;
142 super(getActionDisplayName());
144 final Collection<BlackboardArtifact> selectedBlackboardArtifactsList =
145 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
147 if(!selectedBlackboardArtifactsList.isEmpty()) {
148 BlackboardArtifact artifact =
149 selectedBlackboardArtifactsList.iterator().next();
154 Map<String, TagName> tagNamesMap = null;
157 }
catch (TskCoreException ex) {
164 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
166 List<BlackboardArtifactTag> existingTagsList =
170 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
171 String tagDisplayName = entry.getKey();
173 TagName tagName = entry.getValue();
174 for(BlackboardArtifactTag artifactTag : existingTagsList) {
175 if(tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
176 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName);
177 tagNameItem.addActionListener((ActionEvent e) -> {
178 deleteTag(tagName, artifactTag, artifact.getArtifactID());
184 }
catch (TskCoreException ex) {
186 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
190 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()