Class ContextUtils
java.lang.Object
com.levigo.jadice.web.client.util.context.ContextUtils
A collection of static utility methods used to deal with
Context
s.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic void
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 childIsWidget
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 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> 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 givenContextUtils.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
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 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 givenContextUtils.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 givenContextUtils.IsAssignable
in the context for the given owner with the given element.static <T> void
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 givenContextUtils.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 givenContextUtils.IsAssignable
with the elements found in the given collection.static <T> void
Replaces all non-Context entries in the current context objects collection that match the given class with the elements found in the given collection.
-
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 childIsWidget
to the context of a parent widget (if it has a context).- Parameters:
parentWidget
- the widget to which context the childRoot should be added tochildRoot
- theIsWidget
which should be added to the contextchildren
- enum value ofContext.Children
defining which children of the childRoot should be includedancestors
- enum value ofContext.Ancestors
defining which ancestor contexts should be included
-
add
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 toelement
- the element which should be added- Throws:
IllegalArgumentException
- if noContext
can be found for the given owner
-
remove
Remove the given element from the appropriate context for the given owner.- Parameters:
owner
- theIsWidget
holding theContext
.element
- the element to be removed from the owner Context.- Throws:
IllegalArgumentException
- if noContext
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
- theIsWidget
linked to aContext
.- Throws:
IllegalArgumentException
- if noContext
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 replacedelements
- the elements which should replace the old elements- Throws:
IllegalArgumentException
- if noContext
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 replacedelements
- the elements which should replace the old elementsclazz
- the class of the elements to be replaced- Throws:
IllegalArgumentException
- if noContext
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 givenContextUtils.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 replacedelements
- the elements which should replace the old elementsisAssignable
- theContextUtils.IsAssignable
of the elements to be replaced- Throws:
IllegalArgumentException
- if noContext
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 replacedelement
- the element which should replace the old elementsclazz
- the class of the elements to be replaced- Throws:
IllegalArgumentException
- if noContext
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 givenContextUtils.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 replacedelement
- the element which should replace the old elementsisAssignable
- theContextUtils.IsAssignable
of the elements to be replaced- Throws:
IllegalArgumentException
- if noContext
can be found for the given owner
-
removeByClass
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 removedclazz
- the class of the elements to be removed- Throws:
IllegalArgumentException
- if noContext
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 removedisAssignable
- theContextUtils.IsAssignable
of the elements to be removed- Throws:
IllegalArgumentException
- if noContext
can be found for the given owner
-
findFirst
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 foundclazz
- the class of the element which should be found- Returns:
- the element which was found
- Throws:
IllegalArgumentException
- if noContext
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 foundisAssignable
- anContextUtils.IsAssignable
of the element which should be found- Returns:
- the element which was found
- Throws:
IllegalArgumentException
- if noContext
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 foundclazz
- the class of the element which should be found- Returns:
- a collection containing all elements which were found
- Throws:
IllegalArgumentException
- if noContext
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 foundisAssignable
- the class of the element which should be found- Returns:
- a collection containing all elements which were found
- Throws:
IllegalArgumentException
- if noContext
can be found for the given owner
-
count
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 countedclazz
- the class of the element which should be found- Returns:
- the number of elements found
- Throws:
IllegalArgumentException
- if noContext
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 countedisAssignable
- the class of the element which should be found- Returns:
- the number of elements found
- Throws:
IllegalArgumentException
- if noContext
can be found for the given owner
-
findFirst
Find the first element matching the given class in the given collection.- Parameters:
collection
- the collection in which should be searched for the given classclazz
- 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 givenContextUtils.IsAssignable
isAssignable
- theContextUtils.IsAssignable
which should be searched in the collection- Returns:
- the first object found matching the given assignable or null if none was found
-
findAll
Find all elements matching the given class in the given collection.- Parameters:
collection
- the collection in which to search for the given classclazz
- 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 givenContextUtils.IsAssignable
.- Parameters:
collection
- the collection in which to search for the given classisAssignable
- theContextUtils.IsAssignable
which should be searched in the collection- Returns:
- the collection of objects found matching the given isAssignable
-
removeByClass
Remove all non-context elements matching the given class.- Parameters:
context
- theContext
from which the elements should be removedclazz
- 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
- theContext
from which the elements should be removedisAssignable
- theContextUtils.IsAssignable
of the objects to be removed from the context- Returns:
- whether something was actually removed
-
replace
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 incollection
- the new collection of context objects
-
replace
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 incollection
- 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 givenContextUtils.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 incollection
- 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 thisContextUtils.IsAssignable
will be replaced
-
replace
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 inclazz
- 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 givenContextUtils.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 inisAssignable
- only elements matching thisContextUtils.IsAssignable
will be replaced
-