Class ContextUtils

java.lang.Object
com.levigo.jadice.web.client.util.context.ContextUtils

public class ContextUtils extends Object
A collection of static utility methods used to deal with Contexts.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    add(com.google.gwt.user.client.ui.IsWidget owner, Object element)
    Add the given element to the appropriate context for the given owner.
    static void
    addNonHirarchyChild(com.google.gwt.user.client.ui.IsWidget parentWidget, com.google.gwt.user.client.ui.IsWidget childRoot, Context.Children children, Context.Ancestors ancestors)
    Adds a child IsWidget to the context of a parent widget (if it has a context).
    static void
    clear(com.google.gwt.user.client.ui.IsWidget owner)
    Clear the context for the given owner.
    static int
    count(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<?> isAssignable)
    Count the elements matching the given class in the context for the given owner.
    static int
    count(com.google.gwt.user.client.ui.IsWidget owner, Class<?> clazz)
    Count the elements matching the given class in the context for the given owner.
    static <T> Collection<T>
    findAll(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
    Find all elements matching the given class in the context for the given owner.
    static <T> Collection<T>
    findAll(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
    Find all elements matching the given class in the context for the given owner.
    static <T> Collection<T>
    findAll(Collection<? extends Object> collection, ContextUtils.IsAssignable<T> isAssignable)
    Find all objects in the given collection which are assignable to the given ContextUtils.IsAssignable.
    static <T> Collection<T>
    findAll(Collection<? extends Object> collection, Class<T> clazz)
    Find all elements matching the given class in the given collection.
    static <T> T
    findFirst(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
    Find the first element matching the given class in the context for the given owner.
    static <T> T
    findFirst(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
    Find the first element matching the given class in the context for the given owner.
    static <T> T
    findFirst(Collection<? extends Object> collection, ContextUtils.IsAssignable<T> isAssignable)
    Find the first element matching the given class in the given collection.
    static <T> T
    findFirst(Collection<? extends Object> collection, Class<T> clazz)
    Find the first element matching the given class in the given collection.
    static void
    remove(com.google.gwt.user.client.ui.IsWidget owner, Object element)
    Remove the given element from the appropriate context for the given owner.
    static <T> void
    removeByClass(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
    Remove all elements matching the given class from the context for the given owner.
    static <T> void
    removeByClass(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
    Remove all elements matching the given class from the context for the given owner.
    static boolean
    removeByClass(Context context, ContextUtils.IsAssignable<? extends Object> isAssignable)
    Remove all non-context elements matching the given class.
    static boolean
    removeByClass(Context context, Class<? extends Object> clazz)
    Remove all non-context elements matching the given class.
    static <T> void
    replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<? extends T> elements, ContextUtils.IsAssignable<T> isAssignable)
    Replace all current elements matching the given ContextUtils.IsAssignable in the context for the given owner with the given collection of elements.
    static <T> void
    replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<? extends T> elements, Class<T> clazz)
    Replace all current elements matching the given class in the context for the given owner with the given collection of elements.
    static void
    replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<Object> elements)
    Replace the contents of the context for the given owner with the given collection of elements.
    static <T> void
    replace(com.google.gwt.user.client.ui.IsWidget owner, T element, ContextUtils.IsAssignable<? super T> isAssignable)
    Replace all current elements matching the given ContextUtils.IsAssignable in the context for the given owner with the given element.
    static <T> void
    replace(com.google.gwt.user.client.ui.IsWidget owner, T element, Class<? super T> clazz)
    Replace all current elements matching the given class in the context for the given owner with the given element.
    static void
    replace(Context context, Collection<? extends Object> collection)
    Replaces all non-Context entries in the current context objects collection with the elements of the given collection.
    static <T> void
    replace(Context context, Collection<? extends T> collection, ContextUtils.IsAssignable<T> isAssignable)
    Replaces all non-Context entries in the current context objects collection that match the given ContextUtils.IsAssignable with the elements found in the given collection.
    static <T> void
    replace(Context context, Collection<? extends T> collection, Class<T> clazz)
    Replaces all non-Context entries in the current context objects collection that match the given class with the elements found in the given collection.
    static <T> void
    replace(Context context, T element, ContextUtils.IsAssignable<? super T> isAssignable)
    Replaces all non-Context entries in the current context objects collection that match the given ContextUtils.IsAssignable with the elements found in the given collection.
    static <T> void
    replace(Context context, T element, Class<? super T> clazz)
    Replaces all non-Context entries in the current context objects collection that match the given class with the elements found in the given collection.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • addNonHirarchyChild

      public static void addNonHirarchyChild(com.google.gwt.user.client.ui.IsWidget parentWidget, com.google.gwt.user.client.ui.IsWidget childRoot, Context.Children children, Context.Ancestors ancestors)
      Adds a child IsWidget to the context of a parent widget (if it has a context).
      Parameters:
      parentWidget - the widget to which context the childRoot should be added to
      childRoot - the IsWidget which should be added to the context
      children - enum value of Context.Children defining which children of the childRoot should be included
      ancestors - enum value of Context.Ancestors defining which ancestor contexts should be included
    • add

      public static void add(com.google.gwt.user.client.ui.IsWidget owner, Object element)
      Add the given element to the appropriate context for the given owner.
      Parameters:
      owner - the owner of the context to which the element should be added to
      element - the element which should be added
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • remove

      public static void remove(com.google.gwt.user.client.ui.IsWidget owner, Object element)
      Remove the given element from the appropriate context for the given owner.
      Parameters:
      owner - the IsWidget holding the Context.
      element - the element to be removed from the owner Context.
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner.
    • clear

      public static void clear(com.google.gwt.user.client.ui.IsWidget owner)
      Clear the context for the given owner.
      Parameters:
      owner - the IsWidget linked to a Context.
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • replace

      public static void replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<Object> elements)
      Replace the contents of the context for the given owner with the given collection of elements.
      Parameters:
      owner - the owner of the context in which the elements should be replaced
      elements - the elements which should replace the old elements
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • replace

      public static <T> void replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<? extends T> elements, Class<T> clazz)
      Replace all current elements matching the given class in the context for the given owner with the given collection of elements.
      Parameters:
      owner - the owner of the context in which the elements should be replaced
      elements - the elements which should replace the old elements
      clazz - the class of the elements to be replaced
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • replace

      public static <T> void replace(com.google.gwt.user.client.ui.IsWidget owner, Collection<? extends T> elements, ContextUtils.IsAssignable<T> isAssignable)
      Replace all current elements matching the given ContextUtils.IsAssignable in the context for the given owner with the given collection of elements.
      Parameters:
      owner - the owner of the context in which the elements should be replaced
      elements - the elements which should replace the old elements
      isAssignable - the ContextUtils.IsAssignable of the elements to be replaced
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • replace

      public static <T> void replace(com.google.gwt.user.client.ui.IsWidget owner, T element, Class<? super T> clazz)
      Replace all current elements matching the given class in the context for the given owner with the given element.
      Parameters:
      owner - the owner of the context in which the elements should be replaced
      element - the element which should replace the old elements
      clazz - the class of the elements to be replaced
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • replace

      public static <T> void replace(com.google.gwt.user.client.ui.IsWidget owner, T element, ContextUtils.IsAssignable<? super T> isAssignable)
      Replace all current elements matching the given ContextUtils.IsAssignable in the context for the given owner with the given element.
      Parameters:
      owner - the owner of the context in which the elements should be replaced
      element - the element which should replace the old elements
      isAssignable - the ContextUtils.IsAssignable of the elements to be replaced
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • removeByClass

      public static <T> void removeByClass(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
      Remove all elements matching the given class from the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be removed
      clazz - the class of the elements to be removed
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • removeByClass

      public static <T> void removeByClass(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
      Remove all elements matching the given class from the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be removed
      isAssignable - the ContextUtils.IsAssignable of the elements to be removed
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • findFirst

      public static <T> T findFirst(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
      Find the first element matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the element should be found
      clazz - the class of the element which should be found
      Returns:
      the element which was found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • findFirst

      public static <T> T findFirst(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
      Find the first element matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the element should be found
      isAssignable - an ContextUtils.IsAssignable of the element which should be found
      Returns:
      the element which was found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • findAll

      public static <T> Collection<T> findAll(com.google.gwt.user.client.ui.IsWidget owner, Class<T> clazz)
      Find all elements matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be found
      clazz - the class of the element which should be found
      Returns:
      a collection containing all elements which were found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • findAll

      public static <T> Collection<T> findAll(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<T> isAssignable)
      Find all elements matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be found
      isAssignable - the class of the element which should be found
      Returns:
      a collection containing all elements which were found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • count

      public static int count(com.google.gwt.user.client.ui.IsWidget owner, Class<?> clazz)
      Count the elements matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be counted
      clazz - the class of the element which should be found
      Returns:
      the number of elements found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • count

      public static int count(com.google.gwt.user.client.ui.IsWidget owner, ContextUtils.IsAssignable<?> isAssignable)
      Count the elements matching the given class in the context for the given owner.
      Parameters:
      owner - the owner of the context in which the elements should be counted
      isAssignable - the class of the element which should be found
      Returns:
      the number of elements found
      Throws:
      IllegalArgumentException - if no Context can be found for the given owner
    • findFirst

      public static <T> T findFirst(Collection<? extends Object> collection, Class<T> clazz)
      Find the first element matching the given class in the given collection.
      Parameters:
      collection - the collection in which should be searched for the given class
      clazz - the class which should be searched in the collection
      Returns:
      the first object matching the given clazz or null if none was found
    • findFirst

      public static <T> T findFirst(Collection<? extends Object> collection, ContextUtils.IsAssignable<T> isAssignable)
      Find the first element matching the given class in the given collection.
      Parameters:
      collection - the collection in which to search for the given ContextUtils.IsAssignable
      isAssignable - the ContextUtils.IsAssignable which should be searched in the collection
      Returns:
      the first object found matching the given assignable or null if none was found
    • findAll

      public static <T> Collection<T> findAll(Collection<? extends Object> collection, Class<T> clazz)
      Find all elements matching the given class in the given collection.
      Parameters:
      collection - the collection in which to search for the given class
      clazz - the class which should be searched in the collection
      Returns:
      the collection of objects found matching the given clazz
    • findAll

      public static <T> Collection<T> findAll(Collection<? extends Object> collection, ContextUtils.IsAssignable<T> isAssignable)
      Find all objects in the given collection which are assignable to the given ContextUtils.IsAssignable.
      Parameters:
      collection - the collection in which to search for the given class
      isAssignable - the ContextUtils.IsAssignable which should be searched in the collection
      Returns:
      the collection of objects found matching the given isAssignable
    • removeByClass

      public static boolean removeByClass(Context context, Class<? extends Object> clazz)
      Remove all non-context elements matching the given class.
      Parameters:
      context - the Context from which the elements should be removed
      clazz - the class of the objects to be removed from the context
      Returns:
      whether something was actually removed
    • removeByClass

      public static boolean removeByClass(Context context, ContextUtils.IsAssignable<? extends Object> isAssignable)
      Remove all non-context elements matching the given class.
      Parameters:
      context - the Context from which the elements should be removed
      isAssignable - the ContextUtils.IsAssignable of the objects to be removed from the context
      Returns:
      whether something was actually removed
    • replace

      public static void replace(Context context, Collection<? extends Object> collection)
      Replaces all non-Context entries in the current context objects collection with the elements of the given collection.
      Parameters:
      context - the context to replace the elements in
      collection - the new collection of context objects
    • replace

      public static <T> void replace(Context context, Collection<? extends T> collection, Class<T> clazz)
      Replaces all non-Context entries in the current context objects collection that match the given class with the elements found in the given collection. Class matching is performed on the current context objects and in the given collection.
      Parameters:
      context - the context to replace the elements in
      collection - the new collection (ideally containing only objects of the given class, since only these objects will be replaced. Elements belonging to other classes will be ignored.)
      clazz - only elements of this class will be replaced
    • replace

      public static <T> void replace(Context context, Collection<? extends T> collection, ContextUtils.IsAssignable<T> isAssignable)
      Replaces all non-Context entries in the current context objects collection that match the given ContextUtils.IsAssignable with the elements found in the given collection. Class matching is performed on the current context objects and in the given collection.
      Parameters:
      context - the context to replace the elements in
      collection - the new collection (ideally containing only objects of the given class, since only these objects will be replaced. Elements belonging to other classes will be ignored.)
      isAssignable - only elements matching this ContextUtils.IsAssignable will be replaced
    • replace

      public static <T> void replace(Context context, T element, Class<? super T> clazz)
      Replaces all non-Context entries in the current context objects collection that match the given class with the elements found in the given collection. Class matching is performed on the current context objects and in the given collection.
      Parameters:
      context - the context to replace the elements in
      clazz - only elements of this class will be replaced
    • replace

      public static <T> void replace(Context context, T element, ContextUtils.IsAssignable<? super T> isAssignable)
      Replaces all non-Context entries in the current context objects collection that match the given ContextUtils.IsAssignable with the elements found in the given collection. Class matching is performed on the current context objects and in the given collection.
      Parameters:
      context - the context to replace the elements in
      isAssignable - only elements matching this ContextUtils.IsAssignable will be replaced