Class CookieSet

java.lang.Object
org.openide.nodes.CookieSet
All Implemented Interfaces:
org.openide.util.Lookup.Provider

public final class CookieSet extends Object implements org.openide.util.Lookup.Provider
Support class for storing cookies and retriving them by representation class. Provides simple notifications about changes in cookies.
  • Constructor Details

    • CookieSet

      public CookieSet()
      Default constructor.
  • Method Details

    • createGeneric

      public static CookieSet createGeneric(CookieSet.Before before)
      Factory method to create new, general purpose cookie set. The general purpose means that it is possible to store any object, into the cookie set and then obtain it using getLookup() and queries on the returned Lookup. The before object can be passed in if one wants to do a lazy initialization of the CookieSet content.
      Parameters:
      before - the interface to support lazy initialization
      Returns:
      new cookie set that can contain not only Node.Cookie but also any plain old java object
      Since:
      7.0
      See Also:
    • getLookup

      public org.openide.util.Lookup getLookup()
      The lookup associated with this cookie set. Keeps track of the same things that are in the cookie set, but presents them as being inside the lookup.
      Specified by:
      getLookup in interface org.openide.util.Lookup.Provider
      Returns:
      the lookup representing this cookie set
      Since:
      7.0
    • add

      public void add(Node.Cookie cookie)
      Add a new cookie to the set. If a cookie of the same actual (not representation!) class is already there, it is replaced.

      Cookies inserted earlier are given preference during lookup, in case a supplied representation class matches more than one cookie in the set.

      Parameters:
      cookie - cookie to add
    • remove

      public void remove(Node.Cookie cookie)
      Remove a cookie from the set.
      Parameters:
      cookie - the cookie to remove
    • getCookie

      public <T extends Node.Cookie> T getCookie(Class<T> clazz)
      Get a cookie.
      Parameters:
      clazz - the representation class
      Returns:
      a cookie assignable to the representation class, or null if there is none
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Add a listener to changes in the cookie set.
      Parameters:
      l - the listener to add
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Remove a listener to changes in the cookie set.
      Parameters:
      l - the listener to remove
    • add

      public void add(Class<? extends Node.Cookie> cookieClass, CookieSet.Factory factory)
      Registers a Factory for given cookie class
    • add

      public void add(Class<? extends Node.Cookie>[] cookieClass, CookieSet.Factory factory)
      Registers a Factory for given cookie classes
    • remove

      public void remove(Class<? extends Node.Cookie> cookieClass, CookieSet.Factory factory)
      Unregisters a Factory for given cookie class
      Since:
      2.6
    • remove

      public void remove(Class<? extends Node.Cookie>[] cookieClass, CookieSet.Factory factory)
      Unregisters a Factory for given cookie classes
      Since:
      2.6
    • assign

      public <T> void assign(Class<? extends T> clazz, T... instances)
      Removes all instances of clazz from the set and replaces them with newly provided instance(s).
      Parameters:
      clazz - the root clazz for cookies to remove
      instances - the one or more instances to put into the lookup
      Since:
      7.0