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;
51 "DeleteFileContentTagAction.deleteTag=Remove File Tag"
57 private static final long serialVersionUID = 1L;
59 "DeleteFileContentTagAction.deleteTag");
67 if (null == instance) {
92 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
93 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
94 new SwingWorker<Void, Void>() {
97 protected Void doInBackground()
throws Exception {
101 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), contentTag.getContent().getName()});
103 }
catch (TskCoreException tskCoreException) {
104 logger.log(Level.SEVERE,
"Error untagging file", tskCoreException);
105 Platform.runLater(() ->
106 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
113 protected void done() {
117 }
catch (InterruptedException | ExecutionException ex) {
118 logger.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
131 private static final long serialVersionUID = 1L;
134 super(getActionDisplayName());
136 final Collection<AbstractFile> selectedAbstractFilesList =
137 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
139 if(!selectedAbstractFilesList.isEmpty()) {
140 AbstractFile file = selectedAbstractFilesList.iterator().next();
145 Map<String, TagName> tagNamesMap = null;
148 }
catch (TskCoreException ex) {
155 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
157 List<ContentTag> existingTagsList =
161 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
162 String tagDisplayName = entry.getKey();
164 TagName tagName = entry.getValue();
165 for(ContentTag contentTag : existingTagsList) {
166 if(tagDisplayName.equals(contentTag.getName().getDisplayName())) {
168 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
169 tagNameItem.addActionListener((ActionEvent e) -> {
170 deleteTag(tagName, contentTag, file.getId());
176 }
catch (TskCoreException ex) {
178 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
182 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)