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;
56 "DeleteFileContentTagAction.deleteTag=Remove File Tag"
62 private static final long serialVersionUID = 1L;
64 "DeleteFileContentTagAction.deleteTag");
72 if (null == instance) {
97 return new TagMenu(selectedFiles);
110 "DeleteFileContentTagAction.deleteTag.alert=Unable to untag file {0}."})
111 protected void deleteTag(TagName tagName, ContentTag contentTag,
long fileId) {
112 new SwingWorker<Void, Void>() {
115 protected Void doInBackground()
throws Exception {
120 logger.log(Level.SEVERE,
"Error untagging file. No open case found.", ex);
122 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
128 logger.log(Level.INFO,
"Removing tag {0} from {1}",
new Object[]{tagName.getDisplayName(), contentTag.getContent().getName()});
132 if(imageTag != null) {
137 }
catch (TskCoreException tskCoreException) {
138 logger.log(Level.SEVERE,
"Error untagging file", tskCoreException);
140 ->
new Alert(Alert.AlertType.ERROR, Bundle.DeleteFileContentTagAction_deleteTag_alert(fileId)).show()
147 protected void done() {
151 }
catch (InterruptedException | ExecutionException ex) {
152 logger.log(Level.SEVERE,
"Unexpected exception while untagging file", ex);
165 private static final long serialVersionUID = 1L;
172 this(
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class)));
179 TagMenu(Collection<AbstractFile> selectedFiles) {
180 super(getActionDisplayName());
182 if (!selectedFiles.isEmpty()) {
183 AbstractFile file = selectedFiles.iterator().next();
185 Map<String, TagName> tagNamesMap = null;
187 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
200 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
202 List<ContentTag> existingTagsList
203 = Case.getCurrentCaseThrows().getServices().getTagsManager()
204 .getContentTagsByContent(file);
206 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
207 String tagDisplayName = entry.getKey();
209 TagName tagName = entry.getValue();
210 for (ContentTag contentTag : existingTagsList) {
211 if (tagDisplayName.equals(contentTag.getName().getDisplayName())) {
212 JMenuItem tagNameItem =
new JMenuItem(TagUtils.getDecoratedTagDisplayName(tagName));
213 tagNameItem.addActionListener((ActionEvent e) -> {
214 deleteTag(tagName, contentTag, file.getId());
218 if (standardTagNames.contains(tagDisplayName)) {
219 standardTagMenuitems.add(tagNameItem);
226 }
catch (TskCoreException | NoCurrentCaseException ex) {
227 Logger.getLogger(TagMenu.class.getName())
228 .log(Level.SEVERE,
"Error retrieving tags for TagMenu", ex);
232 if ((getItemCount() > 0) && !standardTagMenuitems.isEmpty()) {
235 standardTagMenuitems.forEach((menuItem) -> {
239 if (getItemCount() == 0) {
DeleteFileContentTagAction()
String getActionDisplayName()
JMenuItem getPopupPresenter()
static< T > void deleteTag(ContentViewerTag< T > contentViewerTag)
static< T > ContentViewerTag< T > getTag(ContentTag contentTag, Class< T > clazz)
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()