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;
42 abstract class AddTagAction
extends AbstractAction implements Presenter.Popup {
44 private static final long serialVersionUID = 1L;
45 private static final String NO_COMMENT =
"";
47 AddTagAction(String menuText) {
52 public JMenuItem getPopupPresenter() {
63 @SuppressWarnings(
"NoopMethodInAbstractClass")
64 public
void actionPerformed(ActionEvent event) {
71 abstract protected String getActionDisplayName();
77 abstract protected void addTag(TagName tagName, String comment);
88 private static final long serialVersionUID = 1L;
91 super(getActionDisplayName());
94 Map<String, TagName> tagNamesMap = null;
103 JMenu quickTagMenu =
new JMenu(NbBundle.getMessage(
this.getClass(),
"AddTagAction.quickTag"));
109 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
110 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
111 String tagDisplayName = entry.getKey();
113 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
115 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
119 tagNameItem.addActionListener((ActionEvent e) -> {
120 getAndAddTag(entry.getKey(), entry.getValue(), NO_COMMENT);
122 quickTagMenu.add(tagNameItem);
125 JMenuItem empty =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.noTags"));
126 empty.setEnabled(
false);
127 quickTagMenu.add(empty);
130 quickTagMenu.addSeparator();
135 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
136 newTagMenuItem.addActionListener((ActionEvent e) -> {
138 if (null != tagName) {
139 addTag(tagName, NO_COMMENT);
142 quickTagMenu.add(newTagMenuItem);
147 JMenuItem tagAndCommentItem =
new JMenuItem(
148 NbBundle.getMessage(
this.getClass(),
"AddTagAction.tagAndComment"));
149 tagAndCommentItem.addActionListener((ActionEvent e) -> {
151 if (null != tagNameAndComment) {
152 addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
155 add(tagAndCommentItem);
170 private void getAndAddTag(String tagDisplayName, TagName tagName, String comment) {
175 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
179 if (tagName == null) {
185 }
catch (TskCoreException ex1) {
186 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" already exists in database but an error occurred in retrieving it.", ex1);
188 }
catch (TskCoreException ex) {
189 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
192 addTag(tagName, comment);
static final KeyStroke BOOKMARK_SHORTCUT
static Case getOpenCase()
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static TagName doDialog()