How do I implement my own lookup or proxy another one?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

It is not uncommon to be subclassing a class, such as TopComponent or Node which has a method getLookup(), and to need to add to or filter the original Lookup’s contents. There are a number of convenience factories and classes which make it easy to do this:

  • ProxyLookup - a Lookup which takes an array of Lookups and merges them together. Typical use is taking an existing lookup and providing it plus a lookup created with one of the convenience methods below

  • Lookups.fixed(Object…​ arr) - a static method that creates a Lookup with an array of persistent objects as its contents

  • Lookups.singleton (Object single) - a static method that creates a Lookup with one object as its content

  • AbstractLookup - a Lookup which can have dynamic content - use it in conjunction with InstanceContent, which you can add/remove things from

If you need to customize a Node’s lookup, read the FAQ item on how to do that.