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;
53 "DeleteFileContentTagAction.deleteTag=Remove File Tag"
59 private static final long serialVersionUID = 1L;
61 "DeleteFileContentTagAction.deleteTag");
69 if (null == instance) {
94 return new TagMenu(selectedFiles);
107 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
108 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
109 new SwingWorker<Void, Void>() {
112 protected Void doInBackground()
throws Exception {
117 logger.log(Level.SEVERE,
"Error untagging file. No open case found.", ex);
119 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
125 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), contentTag.getContent().getName()});
127 }
catch (TskCoreException tskCoreException) {
128 logger.log(Level.SEVERE,
"Error untagging file", tskCoreException);
130 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
137 protected void done() {
141 }
catch (InterruptedException | ExecutionException ex) {
142 logger.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
155 private static final long serialVersionUID = 1L;
162 this(
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class)));
169 TagMenu(Collection<AbstractFile> selectedFiles) {
170 super(getActionDisplayName());
172 if (!selectedFiles.isEmpty()) {
173 AbstractFile file = selectedFiles.iterator().next();
175 Map<String, TagName> tagNamesMap = null;
177 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
190 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
192 List<ContentTag> existingTagsList
193 = Case.getCurrentCaseThrows().getServices().getTagsManager()
194 .getContentTagsByContent(file);
196 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
197 String tagDisplayName = entry.getKey();
199 TagName tagName = entry.getValue();
200 for (ContentTag contentTag : existingTagsList) {
201 if (tagDisplayName.equals(contentTag.getName().getDisplayName())) {
202 String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
203 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
204 tagNameItem.addActionListener((ActionEvent e) -> {
205 deleteTag(tagName, contentTag, file.getId());
209 if (standardTagNames.contains(tagDisplayName)) {
210 standardTagMenuitems.add(tagNameItem);
217 }
catch (TskCoreException | NoCurrentCaseException ex) {
218 Logger.getLogger(TagMenu.class.getName())
219 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
223 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty()) {
226 standardTagMenuitems.forEach((menuItem) -> {
230 if (getItemCount() == 0) {
DeleteFileContentTagAction()
String getActionDisplayName()
JMenuItem getPopupPresenter()
void actionPerformed(ActionEvent e)
static synchronized DeleteFileContentTagAction getInstance()
TagsManager getTagsManager()
void deleteTag(TagName tagName, ContentTag contentTag, long fileId)
static DeleteFileContentTagAction instance
synchronized static Logger getLogger(String name)
JMenuItem getMenuForFiles(Collection< AbstractFile > selectedFiles)
static Case getCurrentCaseThrows()