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() {
83 abstract protected void replaceTag(T oldTag, TagName newTagName);
90 abstract Collection<? extends T> getTagsToReplace();
94 public JMenuItem getPopupPresenter() {
95 return new ReplaceTagMenu();
104 private static final long serialVersionUID = 1L;
107 super(getActionDisplayName());
109 final Collection<? extends T> selectedTags = getTagsToReplace();
112 Map<String, TagName> tagNamesMap = null;
121 List<JMenuItem> standardTagMenuitems =
new ArrayList<>();
124 Set<String> existingTagNames =
new HashSet<>();
125 if (!selectedTags.isEmpty()) {
126 T firstTag = selectedTags.iterator().next();
127 existingTagNames.add(firstTag.getName().getDisplayName());
130 if (null != tagNamesMap && !tagNamesMap.isEmpty()) {
131 for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
132 String tagDisplayName = entry.getKey();
134 JMenuItem tagNameItem =
new JMenuItem(tagDisplayName + notableString);
136 if (tagDisplayName.equals(NbBundle.getMessage(AddTagAction.class,
"AddBookmarkTagAction.bookmark.text"))) {
141 tagNameItem.addActionListener((ActionEvent event) -> {
142 selectedTags.forEach((oldtag) -> {
143 replaceTag(oldtag, entry.getValue());
148 if (existingTagNames.contains(tagDisplayName)) {
149 tagNameItem.setEnabled(
false);
154 if (standardTagNames.contains(tagDisplayName)) {
155 standardTagMenuitems.add(tagNameItem);
161 JMenuItem empty =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.noTags"));
162 empty.setEnabled(
false);
167 if (this.getItemCount() > 0) {
170 standardTagMenuitems.forEach((menuItem) -> {
175 JMenuItem newTagMenuItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
"AddTagAction.newTag"));
176 newTagMenuItem.addActionListener((ActionEvent event) -> {
178 if (null != newTagName) {
179 selectedTags.forEach((oldtag) -> {
180 replaceTag(oldtag, newTagName);
static final KeyStroke BOOKMARK_SHORTCUT
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()