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;
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;
50 "ReplaceTagAction.replaceTag=Replace Selected Tag(s) With"
52 abstract class ReplaceTagAction<T extends Tag> extends AbstractAction implements Presenter.Popup {
54 private static final long serialVersionUID = 1L;
55 protected static final String MENU_TEXT = NbBundle.getMessage(ReplaceTagAction.class,
56 "ReplaceTagAction.replaceTag");
58 ReplaceTagAction(String menuText) {
69 @SuppressWarnings(
"NoopMethodInAbstractClass")
70 public
void actionPerformed(ActionEvent event) {
73 protected String getActionDisplayName() {
84 abstract protected void replaceTag(T oldTag, TagName newTagName, String comment);
91 abstract Collection<? extends T> getTagsToReplace();
95 public JMenuItem getPopupPresenter() {
96 return new ReplaceTagMenu();
105 private static final long serialVersionUID = 1L;
108 super(getActionDisplayName());
110 final Collection<? extends T> selectedTags = getTagsToReplace();
113 Map<String, TagName> tagNamesMap = null;
122 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
125 Set<String> existingTagNames =
new HashSet<>();
126 if (!selectedTags.isEmpty()) {
127 T firstTag = selectedTags.iterator().next();
128 existingTagNames.add(firstTag.getName().getDisplayName());
131 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
132 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
133 String tagDisplayName = entry.getKey();
135 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
137 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
142 tagNameItem.addActionListener((ActionEvent event) -> {
143 selectedTags.forEach((oldtag) -> {
144 replaceTag(oldtag, entry.getValue(), oldtag.getComment());
149 if (existingTagNames.contains(tagDisplayName)) {
150 tagNameItem.setEnabled(
false);
155 if (standardTagNames.contains(tagDisplayName)) {
156 standardTagMenuitems.add(tagNameItem);
162 JMenuItem empty =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.noTags"));
163 empty.setEnabled(
false);
168 if (this.getItemCount() > 0) {
171 standardTagMenuitems.forEach((menuItem) -> {
176 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
177 newTagMenuItem.addActionListener((ActionEvent event) -> {
179 if (null != newTagName) {
180 selectedTags.forEach((oldtag) -> {
181 replaceTag(oldtag, newTagName, oldtag.getComment());
189 JMenuItem tagAndCommentItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.tagAndComment"));
190 tagAndCommentItem.addActionListener((ActionEvent event) -> {
192 if (null != tagNameAndComment) {
193 selectedTags.forEach((oldtag) -> {
194 replaceTag(oldtag, tagNameAndComment.getTagName(), tagNameAndComment.getComment());
198 add(tagAndCommentItem);
static final KeyStroke BOOKMARK_SHORTCUT
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()