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 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
95 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
96 new SwingWorker<Void, Void>() {
99 protected Void doInBackground()
throws Exception {
104 logger.log(Level.SEVERE,
"Error untagging file. No open case found.", ex);
105 Platform.runLater(() ->
106 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
112 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), contentTag.getContent().getName()});
114 }
catch (TskCoreException tskCoreException) {
115 logger.log(Level.SEVERE,
"Error untagging file", tskCoreException);
116 Platform.runLater(() ->
117 new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
124 protected void done() {
128 }
catch (InterruptedException | ExecutionException ex) {
129 logger.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
142 private static final long serialVersionUID = 1L;
145 super(getActionDisplayName());
147 final Collection<AbstractFile> selectedAbstractFilesList =
148 new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
150 if(!selectedAbstractFilesList.isEmpty()) {
151 AbstractFile file = selectedAbstractFilesList.iterator().next();
153 Map<String, TagName> tagNamesMap = null;
155 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
168 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
170 List<ContentTag> existingTagsList =
174 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
175 String tagDisplayName = entry.getKey();
177 TagName tagName = entry.getValue();
178 for(ContentTag contentTag : existingTagsList) {
179 if(tagDisplayName.equals(contentTag.getName().getDisplayName())) {
181 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
182 tagNameItem.addActionListener((ActionEvent e) -> {
183 deleteTag(tagName, contentTag, file.getId());
187 if (standardTagNames.contains(tagDisplayName)) {
188 standardTagMenuitems.add(tagNameItem);
197 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
201 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty() ){
204 standardTagMenuitems.forEach((menuItem) -> {
208 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()