Class ContextUtils
java.lang.Object
com.levigo.jadice.web.client.util.context.ContextUtils
A collection of static utility methods used to deal with
Contexts.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd the given element to the appropriate context for the given owner.static voidaddNonHirarchyChild(com.google.gwt.user.client.ui.IsWidget parentWidget, com.google.gwt.user.client.ui.IsWidget childRoot, Context.Children children, Context.Ancestors ancestors) Adds a childIsWidgetto the context of a parent widget (if it has a context).static voidclear(com.google.gwt.user.client.ui.IsWidget owner) Clear the context for the given owner.static intcount(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 intCount 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> TfindFirst(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> TFind the first element matching the given class in the context for the given owner.static <T> TfindFirst(Collection<? extends Object> collection, ContextUtils.IsAssignable<T> isAssignable) Find the first element matching the given class in the given collection.static <T> TfindFirst(Collection<? extends Object> collection, Class<T> clazz) Find the first element matching the given class in the given collection.static voidRemove the given element from the appropriate context for the given owner.static <T> voidremoveByClass(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> voidremoveByClass(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 booleanremoveByClass(Context context, ContextUtils.IsAssignable<? extends Object> isAssignable) Remove all non-context elements matching the given class.static booleanremoveByClass(Context context, Class<? extends Object> clazz) Remove all non-context elements matching the given class.static <T> voidreplace(com.google.gwt.user.client.ui.IsWidget owner, Collection<? extends T> elements, ContextUtils.IsAssignable<T> isAssignable) Replace all current elements matching the givenContextUtils.IsAssignablein the context for the given owner with the given collection of elements.static <T> voidreplace(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 voidreplace(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> voidreplace(com.google.gwt.user.client.ui.IsWidget owner, T element, ContextUtils.IsAssignable<? super T> isAssignable) Replace all current elements matching the givenContextUtils.IsAssignablein the context for the given owner with the given element.static <T> voidReplace all current elements matching the given class in the context for the given owner with the given element.static voidreplace(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> voidreplace(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.IsAssignablewith the elements found in the given collection.static <T> voidreplace(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> voidreplace(Context context, T element, ContextUtils.IsAssignable<? super T> isAssignable) Replaces all non-Context entries in the current context objects collection that match the givenContextUtils.IsAssignablewith the elements found in the given collection.static <T> voidReplaces 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 childIsWidgetto the context of a parent widget (if it has a context).- Parameters:
parentWidget- the widget to which context the childRoot should be added tochildRoot- theIsWidgetwhich should be added to the contextchildren- enum value ofContext.Childrendefining which children of the childRoot should be includedancestors- enum value ofContext.Ancestorsdefining 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 noContextcan be found for the given owner
-
remove
Remove the given element from the appropriate context for the given owner.- Parameters:
owner- theIsWidgetholding theContext.element- the element to be removed from the owner Context.- Throws:
IllegalArgumentException- if noContextcan 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- theIsWidgetlinked to aContext.- Throws:
IllegalArgumentException- if noContextcan 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 noContextcan 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 noContextcan 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.IsAssignablein 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.IsAssignableof the elements to be replaced- Throws:
IllegalArgumentException- if noContextcan 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 noContextcan 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.IsAssignablein 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.IsAssignableof the elements to be replaced- Throws:
IllegalArgumentException- if noContextcan 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 noContextcan 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.IsAssignableof the elements to be removed- Throws:
IllegalArgumentException- if noContextcan 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 noContextcan 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.IsAssignableof the element which should be found- Returns:
- the element which was found
- Throws:
IllegalArgumentException- if noContextcan 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 noContextcan 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 noContextcan 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 noContextcan 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 noContextcan 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.IsAssignableisAssignable- theContextUtils.IsAssignablewhich 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.IsAssignablewhich 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- theContextfrom 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- theContextfrom which the elements should be removedisAssignable- theContextUtils.IsAssignableof 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.IsAssignablewith 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.IsAssignablewill 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.IsAssignablewith 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.IsAssignablewill be replaced
-