Tuesday October 27, 2009
How to use getNewTypes?
Here is a very odd thing. Look at the explorer view in the left of this pic:
And now look at the explorer view in the RIGHT of this pic:
The same module installed twice. But... look at "Add System Property" in the left of the top window and then compare that to "Add" (which is greyed out and inactive) in the right of the second window. Those are the SAME menu items.
Why is getNewTypes rendered DIFFERENTLY when it is in the Services (a.k.a. Runtime) window compared to when it is rendered in my own custom explorer view?
And I am not alone with this question:
Solution: Hook the explorer manager of your own component to the component's action map and then add that to the context of your component:
Lookup lkp = ExplorerUtils.createLookup(em, getActionMap()); associateLookup(lkp);
Do the above in the constructor of the TopComponent. Now run the module again and when the node appears in your own component, its actions will behave correctly.
Oct 27 2009, 03:46:54 PM PDT Permalink
Geertjan,
According to Heiko's book, you should ALWAYS add the action map when you you override the default Looup with your own. I must agree that this it no written explicitely, but you can deduce this from his explanations. Somehow, this is one among a lot of other recipes that must be used when working with NetBeans.
Posted by jmborer on October 28, 2009 at 04:29 AM PDT #
Jean-Marc, but in this case I hadn't overriden the default Lookup with my own at all. I had to add it anyway though. I agree with you that this is one of many recipes that simply must be done -- hoping to have a long list of these in a new DZone refcard soon, watch this space about that!
Posted by Geertjan Wielenga on October 28, 2009 at 10:45 PM PDT #


