# Tag browser context menu new feature

**URL:** <https://forum.inductiveautomation.com/t/tag-browser-context-menu-new-feature/87438>\
**Category:** Module Development\
**Created:** [March 17, 2024, 12:37am UTC](https://forum.inductiveautomation.com/t/tag-browser-context-menu-new-feature/87438 "2024-03-17T00:37:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Foster](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@Nathan\_Foster](https://forum.inductiveautomation.com/u/Nathan_Foster)\
**Post date:** [March 17, 2024, 12:37am UTC](https://forum.inductiveautomation.com/t/tag-browser-context-menu-new-feature/87438/1 "2024-03-17T00:37:35Z")

</div>

I'm a newbie to module development and trying to add a new feature to the tag browser context menu. I was able to add a new menu item to the tag browser context menu, but how do I get which tag(s) was selected when the action event is invoked? The ActionEvent does not contain this info and I'm having a hard time finding anything in the API that would give me this info. Below is the code from my designer hook.

```auto
    private DesignerContext context;
    private String projectName;

    @Override
    public void startup(DesignerContext context, LicenseState activationState) throws Exception {
        // implelement functionality as required
        this.context = context;
        this.projectName = context.getProjectName();
        addMenuItemToTagBrowser();

    }

    private void addMenuItemToTagBrowser() {

        JMenuItem menuItem = new JMenuItem("Add to View");
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                menuItem.setText("Pressed!");
            }
        });

        TagBrowserFrame tagBrowserFrame = context.getTagBrowser();
        tagBrowserFrame.addTagPopupMenuComponent(menuItem, 0);
    }

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 3:23pm UTC](https://forum.inductiveautomation.com/t/tag-browser-context-menu-new-feature/87438/2 "2024-03-20T15:23:28Z")

</div>

So, in theory, the 'right' way to do this would be to subclass [`TagTreeAction`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.37/com/inductiveautomation/ignition/designer/tags/tree/action/TagTreeAction.html) - that's what all of our internal actions use. However, it requires you to pass the tree you want to listen to to the action, and I don't see any way to actually get a reference to that tree via public SDK methods.

So, there's the other method, which is actually what the EAM module uses to get around this same problem; in your hook, at the same time as you add your new action, add a listener to the tag browser frame:  
`context.getTagBrowser().addOnTagSelectedListener(yourListener);`.  
This listener should probably be your action class - subclass `BaseAction` or `AbstractAction` directly. Your listener will be called _every time_ the end user changes their selection, so make a _performant_ filter function that derives your action's enabled state and updates a field with the user's selection.  
Then in your action's `actionPerformed`, just read the value of the field to drive whatever final logic you want.

---

<div class="post-metadata">

**Author:** ![Nathan\_Foster](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@Nathan\_Foster](https://forum.inductiveautomation.com/u/Nathan_Foster)\
**Post date:** [March 20, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/tag-browser-context-menu-new-feature/87438/3 "2024-03-20T15:39:58Z")

</div>

Thanks!
