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;
50 "DeleteFileContentTagAction.deleteTag=Remove File Tag"
56 private static final long serialVersionUID = 1L;
58 "DeleteFileContentTagAction.deleteTag");
66 if (null == instance) {
91 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
92 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
93 new SwingWorker<Void, Void>() {
96 protected Void doInBackground()
throws Exception {
101 final Collection<AbstractFile> selectedFilesList =
102 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
103 AbstractFile file = selectedFilesList.iterator().next();
106 LOGGER.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), file.getName()});
108 }
catch (TskCoreException tskCoreException) {
109 LOGGER.log(Level.SEVERE,
"Error untagging file", tskCoreException);
110 Platform.runLater(() ->
111 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
118 protected void done() {
122 }
catch (InterruptedException | ExecutionException ex) {
123 LOGGER.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
136 private static final long serialVersionUID = 1L;
139 super(getActionDisplayName());
141 final Collection<AbstractFile> selectedAbstractFilesList =
142 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
144 if(!selectedAbstractFilesList.isEmpty()) {
145 AbstractFile file = selectedAbstractFilesList.iterator().next();
150 Map<String, TagName> tagNamesMap = null;
153 }
catch (TskCoreException ex) {
160 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
162 List<ContentTag> existingTagsList =
166 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
167 String tagDisplayName = entry.getKey();
169 TagName tagName = entry.getValue();
170 for(ContentTag contentTag : existingTagsList) {
171 if(tagDisplayName.equals(contentTag.getName().getDisplayName())) {
172 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName);
173 tagNameItem.addActionListener((ActionEvent e) -> {
174 deleteTag(tagName, contentTag, file.getId());
180 }
catch (TskCoreException ex) {
182 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
186 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
static Case getCurrentCase()
synchronized static Logger getLogger(String name)