19 package org.sleuthkit.autopsy.actions;
21 import java.awt.event.ActionEvent;
23 import java.util.TreeMap;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.JMenu;
27 import javax.swing.JMenuItem;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.Presenter;
40 abstract class AddTagAction
extends AbstractAction implements Presenter.Popup {
42 private static final long serialVersionUID = 1L;
43 private static final String NO_COMMENT =
"";
45 AddTagAction(String menuText) {
50 public JMenuItem getPopupPresenter() {
61 @SuppressWarnings(
"NoopMethodInAbstractClass")
62 public
void actionPerformed(ActionEvent event) {
69 abstract protected String getActionDisplayName();
75 abstract protected void addTag(TagName tagName, String comment);
86 private static final long serialVersionUID = 1L;
89 super(getActionDisplayName());
93 Map<String, TagName> tagNamesMap = null;
101 JMenu quickTagMenu =
new JMenu(NbBundle.getMessage(
this.getClass(),
"AddTagAction.quickTag"));
107 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
108 for (Map.Entry<String,
TagName> entry : tagNamesMap.entrySet()) {
109 String tagDisplayName = entry.getKey();
110 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName);
112 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
116 tagNameItem.addActionListener((ActionEvent e) -> {
117 getAndAddTag(entry.getKey(), entry.getValue(), NO_COMMENT);
119 quickTagMenu.add(tagNameItem);
122 JMenuItem empty =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.noTags"));
123 empty.setEnabled(
false);
124 quickTagMenu.add(empty);
127 quickTagMenu.addSeparator();
132 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
133 newTagMenuItem.addActionListener((ActionEvent e) -> {
135 if (null != tagName) {
136 addTag(tagName, NO_COMMENT);
139 quickTagMenu.add(newTagMenuItem);
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);
168 if (tagName == null) {
175 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" already exists in database but an error occurred in retrieving it.", ex1);
178 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
181 addTag(tagName, comment);
static final KeyStroke BOOKMARK_SHORTCUT
TagsManager getTagsManager()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static TagName doDialog()