Re: Re: How to set the category programmatically in the suggestions window?

Tor Norbye <[email protected]> Wed, 13 Aug 2003 10:12:26 -0700
Newsgroups gmane.comp.java.netbeans.modules.tasklist.devel
Organization Sun Microsystems, Inc
Message-ID <[email protected]>
Julian Sinai wrote:
> I forgot to add that I'd like to do this without creating a private build of
> the suggestions module. I think I know how to do this by copying the code
> from org.netbeans.modules.tasklist.suggestions.ShowCategoryAction, but I
> will need to make several methods public, unless I patch the module.
> 
> Also, I forgot to add that I am using NB 3.5 FCS.

Let me know what methods you need made public.

BUT, if you're willing to hack..................

Take a look at ShowCategoryAction. 

First, obtain a reference to the ShowCategoryAction
singleton (SystemAction.get(ShowCategoryActon.class)).

Then call getMenuPresenter on it - this will return
a JMenu.  Notice how getMenuPresenter has added a
MainListener (a private inner class) as a listener
on the menu.

So call the JMenu's getMenuListeners method.

You now have a reference to the MainListener object
in ShowCategoryAction.

This menu listener should also implement ActionListener,
so do a dynamic instanceof check (via the Class class)
and cast.

Now you can call the actionPerformed method in
MainListener. You'll need to synthesize an appropriate
event to pass it.

Create a new JMenuItem - its name etc. doesn't matter,
but attach a client property with the SuggestionType
you want to filter to:

 curMenuItem.putClientProperty("type", type); // NOI18N

Then, create an ActionEvent whose source attribute
references the above JMenuItem.  Call actionPerformed
with this action event.

As you can see, actionPerformed will look up the JMenuItem
via the source, then it will look up the "type" client
property, and it will then filter to that type.


Hope this works - I haven't tried it, I just quickly looked
at the sources. Let me know if you run into any problems
or need help with additional stuff, like looking up
the SuggestionType for your provider's type string etc.

-- Tor