org.openide.util.lookup
Class InstanceContent

java.lang.Object
  extended by org.openide.util.lookup.AbstractLookup.Content
      extended by org.openide.util.lookup.InstanceContent
All Implemented Interfaces:
java.io.Serializable

public final class InstanceContent
extends AbstractLookup.Content

A special content implementation that can be passed to AbstractLookup and provides methods for registration of instances and lazy instances.

      InstanceContent ic = new InstanceContent ();
      AbstractLookup al = new AbstractLookup (ic);

      ic.add (new Object ());
      ic.add (new Dimension (...));

      Dimension theDim = (Dimension)al.lookup (Dimension.class);
 

Since:
1.25
Author:
Jaroslav Tulach
See Also:
Serialized Form

Nested Class Summary
(package private) static class InstanceContent.ConvertingItem<T,R>
          Instance of one item registered in the map.
static interface InstanceContent.Convertor<T,R>
          Convertor postpones an instantiation of an object.
(package private) static class InstanceContent.SimpleItem<T>
          Instance of one item representing an object.
 
Constructor Summary
InstanceContent()
          Create a new, empty content.
 
Method Summary
 void add(java.lang.Object inst)
          The method to add instance to the lookup with.
<T,R> void
add(T inst, InstanceContent.Convertor<T,R> conv)
          The method to add instance to the lookup with.
 void remove(java.lang.Object inst)
          Remove instance.
<T,R> void
remove(T inst, InstanceContent.Convertor<T,R> conv)
          Remove instance added with a convertor.
<T,R> void
set(java.util.Collection<T> col, InstanceContent.Convertor<T,R> conv)
          Changes all pairs in the lookup to new values.
 
Methods inherited from class org.openide.util.lookup.AbstractLookup.Content
addPair, attach, removePair, setPairs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstanceContent

public InstanceContent()
Create a new, empty content.

Method Detail

add

public final void add(java.lang.Object inst)
The method to add instance to the lookup with.

Parameters:
inst - instance

add

public final <T,R> void add(T inst,
                            InstanceContent.Convertor<T,R> conv)
The method to add instance to the lookup with.

Parameters:
inst - instance
conv - convertor which postponing an instantiation, if conv==null then the instance is registered directly.

remove

public final void remove(java.lang.Object inst)
Remove instance.

Parameters:
inst - instance

remove

public final <T,R> void remove(T inst,
                               InstanceContent.Convertor<T,R> conv)
Remove instance added with a convertor.

Parameters:
inst - instance
conv - convertor, if conv==null it is same like remove(Object)

set

public final <T,R> void set(java.util.Collection<T> col,
                            InstanceContent.Convertor<T,R> conv)
Changes all pairs in the lookup to new values. Converts collection of instances to collection of pairs.

Parameters:
col - the collection of (Item) objects
conv - the convertor to use or null