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 "DeleteFileContentTagAction.deleteTag=Remove File Tag"
58 private static final long serialVersionUID = 1L;
60 "DeleteFileContentTagAction.deleteTag");
68 if (null == instance) {
93 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
94 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
95 new SwingWorker<Void, Void>() {
98 protected Void doInBackground()
throws Exception {
103 logger.log(Level.SEVERE,
"Error untagging file. No open case found.", ex);
104 Platform.runLater(() ->
105 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
111 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), contentTag.getContent().getName()});
113 }
catch (TskCoreException tskCoreException) {
114 logger.log(Level.SEVERE,
"Error untagging file", tskCoreException);
115 Platform.runLater(() ->
116 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
123 protected void done() {
127 }
catch (InterruptedException | ExecutionException ex) {
128 logger.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
141 private static final long serialVersionUID = 1L;
144 super(getActionDisplayName());
146 final Collection<AbstractFile> selectedAbstractFilesList =
147 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
149 if(!selectedAbstractFilesList.isEmpty()) {
150 AbstractFile file = selectedAbstractFilesList.iterator().next();
152 Map<String, TagName> tagNamesMap = null;
165 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
167 List<ContentTag> existingTagsList =
171 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
172 String tagDisplayName = entry.getKey();
174 TagName tagName = entry.getValue();
175 for(ContentTag contentTag : existingTagsList) {
176 if(tagDisplayName.equals(contentTag.getName().getDisplayName())) {
178 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
179 tagNameItem.addActionListener((ActionEvent e) -> {
180 deleteTag(tagName, contentTag, file.getId());
188 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
192 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)
static Case getCurrentCaseThrows()