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.List;
26 import java.util.TreeMap;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import java.util.stream.Collectors;
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;
55 "DeleteFileBlackboardArtifactTagAction.deleteTag=Remove Result Tag"
61 private static final long serialVersionUID = 1L;
63 "DeleteFileBlackboardArtifactTagAction.deleteTag");
71 if (null == instance) {
97 return new TagMenu(selectedArtifacts);
108 @NbBundle.Messages({
"# {0} - artifactID",
109 "DeleteFileBlackboardArtifactTagAction.deleteTag.alert=Unable to untag artifact {0}."})
110 protected void deleteTag(TagName tagName, BlackboardArtifactTag artifactTag,
long artifactId) {
111 new SwingWorker<Void, Void>() {
114 protected Void doInBackground()
throws Exception {
119 logger.log(Level.SEVERE,
"Error untagging artifact. No open case found.", ex);
121 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
127 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), artifactTag.getContent().getName()});
129 }
catch (TskCoreException tskCoreException) {
130 logger.log(Level.SEVERE,
"Error untagging artifact", tskCoreException);
132 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileBlackboardArtifactTagAction_deleteTag_alert(artifactId)).show()
139 protected void done() {
143 }
catch (InterruptedException | ExecutionException ex) {
144 logger.log(Level.SEVERE,
"Unexpected exception while untagging artifact", ex);
155 @NbBundle.Messages({
"# {0} - artifactID",
156 "DeleteFileBlackboardArtifactTagAction.deleteTags.alert=Unable to untag artifact {0}."})
159 private static final long serialVersionUID = 1L;
162 this(Utilities.actionsGlobalContext()
165 .map((bai) -> (BlackboardArtifact) bai.getTskContent())
166 .collect(Collectors.toSet()));
169 TagMenu(Collection<BlackboardArtifact> selectedBlackboardArtifactsList) {
170 super(getActionDisplayName());
171 if (!selectedBlackboardArtifactsList.isEmpty()) {
172 BlackboardArtifact artifact
173 = selectedBlackboardArtifactsList.iterator().next();
175 Map<String, TagName> tagNamesMap = null;
177 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
190 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
192 List<BlackboardArtifactTag> existingTagsList
193 = Case.getCurrentCaseThrows().getServices().getTagsManager()
194 .getBlackboardArtifactTagsByArtifact(artifact);
196 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
197 String tagDisplayName = entry.getKey();
199 TagName tagName = entry.getValue();
200 for (BlackboardArtifactTag artifactTag : existingTagsList) {
201 if (tagDisplayName.equals(artifactTag.getName().getDisplayName())) {
202 JMenuItem tagNameItem =
new JMenuItem(TagUtils.getDecoratedTagDisplayName(tagName));
203 tagNameItem.addActionListener((ActionEvent e) -> {
204 deleteTag(tagName, artifactTag, artifact.getArtifactID());
207 if (standardTagNames.contains(tagDisplayName)) {
208 standardTagMenuitems.add(tagNameItem);
215 }
catch (TskCoreException | NoCurrentCaseException ex) {
216 Logger.getLogger(TagMenu.class.getName())
217 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
221 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty()) {
224 standardTagMenuitems.forEach((menuItem) -> {
227 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()