com.levigo.util.swing.action
Class ContextUtils

java.lang.Object
  extended by com.levigo.util.swing.action.ContextUtils

public class ContextUtils
extends Object

A collection of static utility methods used to deal with Contexts.


Method Summary
static void add(JComponent owner, Object element)
          Add the given element to the appropriate context for the given UI component.
static
<B extends JComponent,V>
Disposable
bindBeanProperty(B bean, String propertyName)
           
static
<B,V> Disposable
bindBeanProperty(Context ctx, B bean, String propertyName)
           
static void clear(JComponent owner)
          Clear the context for the given UI component.
static int count(JComponent owner, Class<?> match)
          Count the elements matching the given class in the context for the given UI component.
static
<T> Collection<T>
findAll(Collection<? extends Object> args, Class<T> clazz)
          Find all elements matching the given class in the given collection.
static
<T> Collection<T>
findAll(JComponent owner, Class<T> match)
          Find all elements matching the given class in the context for the given UI component.
static
<T> T
findFirst(Collection<? extends Object> args, Class<T> clazz)
          Find the first element matching the given class in the given collection.
static
<T> T
findFirst(JComponent owner, Class<T> match)
          Find the first element matching the given class in the context for the given UI component.
static void remove(JComponent owner, Object element)
          Remove the given element from the appropriate context for the given UI component.
static boolean removeByClass(Context ctx, Class<? extends Object> matchClass)
          Remove all non-context elements matching the given class.
static
<T> void
removeByClass(JComponent owner, Class<T> match)
          Remove all elements matching the given class from the context for the given UI component.
static void replace(Context ctx, Collection<? extends Object> c)
          Replaces all non-Context entries in the current context objects collection with the elements of the given collection.
static
<T> void
replace(Context ctx, Collection<? extends T> c, Class<T> matchClass)
          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 ctx, T o, Class<? super T> matchClass)
          Replaces all non-Context entries in the current context objects collection that match the given class with the given item.
static
<T> void
replace(JComponent owner, Collection<? extends T> elements, Class<T> match)
          Replace all current elements matching the given class of the context for the given UI component with the given collection of elements.
static void replace(JComponent owner, Collection<Object> elements)
          Replace the contents of context for the given UI component with the given collection of elements.
static
<T> void
replace(JComponent owner, T element, Class<? super T> match)
          Replace all current elements matching the given class of the context for the given UI component with the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public static void add(JComponent owner,
                       Object element)
Add the given element to the appropriate context for the given UI component.

Parameters:
owner -
element -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

remove

public static void remove(JComponent owner,
                          Object element)
Remove the given element from the appropriate context for the given UI component.

Parameters:
owner -
element -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

clear

public static void clear(JComponent owner)
Clear the context for the given UI component.

Parameters:
owner -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

replace

public static void replace(JComponent owner,
                           Collection<Object> elements)
Replace the contents of context for the given UI component with the given collection of elements.

Parameters:
owner -
elements -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

replace

public static <T> void replace(JComponent owner,
                               Collection<? extends T> elements,
                               Class<T> match)
Replace all current elements matching the given class of the context for the given UI component with the given collection of elements.

Parameters:
owner -
elements -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

replace

public static <T> void replace(JComponent owner,
                               T element,
                               Class<? super T> match)
Replace all current elements matching the given class of the context for the given UI component with the given object.

Parameters:
owner -
element -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

removeByClass

public static <T> void removeByClass(JComponent owner,
                                     Class<T> match)
Remove all elements matching the given class from the context for the given UI component.

Parameters:
owner -
match -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

findFirst

public static <T> T findFirst(JComponent owner,
                              Class<T> match)
Find the first element matching the given class in the context for the given UI component.

Parameters:
owner -
match -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

findAll

public static <T> Collection<T> findAll(JComponent owner,
                                        Class<T> match)
Find all elements matching the given class in the context for the given UI component.

Parameters:
owner -
match -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

count

public static int count(JComponent owner,
                        Class<?> match)
Count the elements matching the given class in the context for the given UI component.

Parameters:
owner -
match -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

findFirst

public static <T> T findFirst(Collection<? extends Object> args,
                              Class<T> clazz)
Find the first element matching the given class in the given collection.

Parameters:
args -
clazz -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

findAll

public static <T> Collection<T> findAll(Collection<? extends Object> args,
                                        Class<T> clazz)
Find all elements matching the given class in the given collection.

Parameters:
args -
clazz -
Throws:
IllegalArgumentException - if no Context can be found for the given owner.

removeByClass

public static boolean removeByClass(Context ctx,
                                    Class<? extends Object> matchClass)
Remove all non-context elements matching the given class.

Parameters:
matchClass - Only elements of this class will be replaced
Returns:
whether something was actually removed

replace

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

Parameters:
c - The new collection of context objects.

replace

public static <T> void replace(Context ctx,
                               Collection<? extends T> c,
                               Class<T> matchClass)
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:
c - 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.)
matchClass - Only elements of this class will be replaced

replace

public static <T> void replace(Context ctx,
                               T o,
                               Class<? super T> matchClass)
Replaces all non-Context entries in the current context objects collection that match the given class with the given item. Class matching is performed on the current context objects and in the given collection.

Parameters:
o - The new item (ideally being derived from the given class, since only these objects will be replaced. Elements belonging to other classes will be ignored.)
matchClass - Only elements of this class will be replaced

bindBeanProperty

public static <B extends JComponent,V> Disposable bindBeanProperty(B bean,
                                                                   String propertyName)

bindBeanProperty

public static <B,V> Disposable bindBeanProperty(Context ctx,
                                                B bean,
                                                String propertyName)


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.