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.Collections;
25 import java.util.HashSet;
26 import java.util.List;
28 import java.util.TreeMap;
29 import java.util.logging.Level;
30 import javax.swing.AbstractAction;
31 import javax.swing.JMenu;
32 import javax.swing.JMenuItem;
33 import org.openide.util.NbBundle;
34 import org.openide.util.actions.Presenter;
48 abstract class AddTagAction
extends AbstractAction implements Presenter.Popup {
50 private static final long serialVersionUID = 1L;
51 private static final String NO_COMMENT =
"";
52 private final Collection<Content> content =
new HashSet<>();
54 AddTagAction(String menuText) {
59 public JMenuItem getPopupPresenter() {
70 Collection<Content> getContentToTag() {
71 return Collections.unmodifiableCollection(content);
83 public JMenuItem getMenuForContent(Collection<? extends Content> contentToTag) {
85 content.addAll(contentToTag);
96 @SuppressWarnings(
"NoopMethodInAbstractClass")
97 public
void actionPerformed(ActionEvent event) {
104 abstract protected String getActionDisplayName();
110 abstract protected void addTag(TagName tagName, String comment);
121 private static final long serialVersionUID = 1L;
124 super(getActionDisplayName());
127 Map<String, TagName> tagNamesMap = null;
138 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
139 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
140 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
141 String tagDisplayName = entry.getKey();
143 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
145 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
149 tagNameItem.addActionListener((ActionEvent e) -> {
150 getAndAddTag(entry.getKey(), entry.getValue(), NO_COMMENT);
154 if (standardTagNames.contains(tagDisplayName)) {
155 standardTagMenuitems.add(tagNameItem);
162 if (getItemCount() > 0) {
166 standardTagMenuitems.forEach((menuItem) -> {
175 JMenuItem tagAndCommentItem =
new JMenuItem(
176 NbBundle.getMessage(
this.getClass(),
"AddTagAction.tagAndComment"));
177 tagAndCommentItem.addActionListener((ActionEvent e) -> {
179 if (null != tagNameAndComment) {
180 addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
183 add(tagAndCommentItem);
188 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
189 newTagMenuItem.addActionListener((ActionEvent e) -> {
191 if (null != tagName) {
192 addTag(tagName, NO_COMMENT);
211 private void getAndAddTag(String tagDisplayName, TagName tagName, String comment) {
216 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
220 if (tagName == null) {
226 }
catch (TskCoreException ex1) {
227 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" already exists in database but an error occurred in retrieving it.", ex1);
229 }
catch (TskCoreException ex) {
230 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
233 addTag(tagName, comment);
static final KeyStroke BOOKMARK_SHORTCUT
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()