19 package org.sleuthkit.autopsy.actions;
21 import java.awt.event.ActionEvent;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.List;
27 import java.util.TreeMap;
28 import java.util.concurrent.ExecutionException;
29 import java.util.logging.Level;
30 import javafx.application.Platform;
31 import javafx.scene.control.Alert;
32 import javax.swing.AbstractAction;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuItem;
35 import javax.swing.SwingWorker;
36 import org.openide.util.NbBundle;
37 import org.openide.util.Utilities;
38 import org.openide.util.actions.Presenter;
54 "DeleteFileBlackboardArtifactTagAction.deleteTag=Remove Result Tag"
60 private static final long serialVersionUID = 1L;
62 "DeleteFileBlackboardArtifactTagAction.deleteTag");
70 if (null == instance) {
93 @NbBundle.Messages({
"# {0} - artifactID",
94 "DeleteFileBlackboardArtifactTagAction.deleteTag.alert=Unable to untag artifact {0}."})
95 protected void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag,
long artifactId) {
96 new SwingWorker<Void, Void>() {
99 protected Void doInBackground()
throws Exception {
104 logger.log(Level.SEVERE,
"Error untagging artifact. No open case found.", ex);
106 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
112 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()});
114 }
catch (TskCoreException tskCoreException) {
115 logger.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
117 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
124 protected void done() {
128 }
catch (InterruptedException | ExecutionException ex) {
129 logger.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
140 @NbBundle.Messages({
"# {0} - artifactID",
141 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
144 private static final long serialVersionUID = 1L;
147 super(getActionDisplayName());
149 final Collection<BlackboardArtifact> selectedBlackboardArtifactsList
150 =
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
152 if (!selectedBlackboardArtifactsList.isEmpty()) {
153 BlackboardArtifact artifact
154 = selectedBlackboardArtifactsList.iterator().next();
156 Map<String, TagName> tagNamesMap = null;
158 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
171 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
173 List<BlackboardArtifactTag> existingTagsList
177 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
178 String tagDisplayName = entry.getKey();
180 TagName tagName = entry.getValue();
181 for (BlackboardArtifactTag artifactTag : existingTagsList) {
182 if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
184 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
185 tagNameItem.addActionListener((ActionEvent e) -> {
186 deleteTag(tagName, artifactTag, artifact.getArtifactID());
189 if (standardTagNames.contains(tagDisplayName)) {
190 standardTagMenuitems.add(tagNameItem);
199 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
203 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty() ){
206 standardTagMenuitems.forEach((menuItem) -> {
209 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()