Tag browser context menu new feature

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.

    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);
    }

So, in theory, the 'right' way to do this would be to subclass TagTreeAction - 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.

5 Likes

Thanks!