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) {
96 return new TagMenu(selectedArtifacts);
107 @NbBundle.Messages({
"# {0} - artifactID",
108 "DeleteFileBlackboardArtifactTagAction.deleteTag.alert=Unable to untag artifact {0}."})
109 protected void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag,
long artifactId) {
110 new SwingWorker<Void, Void>() {
113 protected Void doInBackground()
throws Exception {
118 logger.log(Level.SEVERE,
"Error untagging artifact. No open case found.", ex);
120 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
126 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()});
128 }
catch (TskCoreException tskCoreException) {
129 logger.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
131 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
138 protected void done() {
142 }
catch (InterruptedException | ExecutionException ex) {
143 logger.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
154 @NbBundle.Messages({
"# {0} - artifactID",
155 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
158 private static final long serialVersionUID = 1L;
161 this(
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class)));
164 TagMenu(Collection<BlackboardArtifact> selectedBlackboardArtifactsList) {
165 super(getActionDisplayName());
166 if (!selectedBlackboardArtifactsList.isEmpty()) {
167 BlackboardArtifact artifact
168 = selectedBlackboardArtifactsList.iterator().next();
170 Map<String, TagName> tagNamesMap = null;
172 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
185 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
187 List<BlackboardArtifactTag> existingTagsList
188 = Case.getCurrentCaseThrows().getServices().getTagsManager()
189 .getBlackboardArtifactTagsByArtifact(artifact);
191 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
192 String tagDisplayName = entry.getKey();
194 TagName tagName = entry.getValue();
195 for (BlackboardArtifactTag artifactTag : existingTagsList) {
196 if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
197 JMenuItem tagNameItem =
new JMenuItem(TagUtils.getDecoratedTagDisplayName(tagName));
198 tagNameItem.addActionListener((ActionEvent e) -> {
199 deleteTag(tagName, artifactTag, artifact.getArtifactID());
202 if (standardTagNames.contains(tagDisplayName)) {
203 standardTagMenuitems.add(tagNameItem);
210 }
catch (TskCoreException | NoCurrentCaseException ex) {
211 Logger.getLogger(TagMenu.class.getName())
212 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
216 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty()) {
219 standardTagMenuitems.forEach((menuItem) -> {
222 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 getMenuForArtifacts(Collection< BlackboardArtifact > selectedArtifacts)
JMenuItem getPopupPresenter()