19 package org.sleuthkit.autopsy.actions;
21 import java.awt.event.ActionEvent;
22 import java.util.ArrayList;
23 import java.util.List;
25 import java.util.TreeMap;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.JMenu;
29 import javax.swing.JMenuItem;
30 import org.openide.util.NbBundle;
31 import org.openide.util.actions.Presenter;
44 abstract class AddTagAction
extends AbstractAction implements Presenter.Popup {
46 private static final long serialVersionUID = 1L;
47 private static final String NO_COMMENT =
"";
49 AddTagAction(String menuText) {
54 public JMenuItem getPopupPresenter() {
65 @SuppressWarnings(
"NoopMethodInAbstractClass")
66 public
void actionPerformed(ActionEvent event) {
73 abstract protected String getActionDisplayName();
79 abstract protected void addTag(TagName tagName, String comment);
88 private final class TagMenu extends JMenu {
90 private static final long serialVersionUID = 1L;
93 super(getActionDisplayName());
96 Map<String, TagName> tagNamesMap = null;
107 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
108 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
109 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
110 String tagDisplayName = entry.getKey();
112 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
114 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
118 tagNameItem.addActionListener((ActionEvent e) -> {
119 getAndAddTag(entry.getKey(), entry.getValue(), NO_COMMENT);
123 if (standardTagNames.contains(tagDisplayName)) {
124 standardTagMenuitems.add(tagNameItem);
131 if (getItemCount() > 0) {
135 standardTagMenuitems.forEach((menuItem) -> {
144 JMenuItem tagAndCommentItem =
new JMenuItem(
145 NbBundle.getMessage(
this.getClass(),
"AddTagAction.tagAndComment"));
146 tagAndCommentItem.addActionListener((ActionEvent e) -> {
148 if (null != tagNameAndComment) {
149 addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
152 add(tagAndCommentItem);
157 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
158 newTagMenuItem.addActionListener((ActionEvent e) -> {
160 if (null != tagName) {
161 addTag(tagName, NO_COMMENT);
180 private void getAndAddTag(String tagDisplayName, TagName tagName, String comment) {
185 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
189 if (tagName == null) {
195 }
catch (TskCoreException ex1) {
196 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" already exists in database but an error occurred in retrieving it.", ex1);
198 }
catch (TskCoreException ex) {
199 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
202 addTag(tagName, comment);
static final KeyStroke BOOKMARK_SHORTCUT
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()