Class Context
- All Implemented Interfaces:
Iterable<Object>
,Collection<Object>
The Context is the center of the context model. It holds context objects which serve as arguments
for Command
s.
The Context has just one owner, a IsWidget
. A reference to this owner is held inside the
context. The Context is stored as ClientProperty of the owner.
The context contains references on its own child contexts on which is registered as
ContextListener
.
The context contains the collection of the components from the child contexts as cachedActiveChildsContextObjects. The context objects contains information for the commands. (For example: items, session, viewer...).
The contexts form a hierarchy reflecting the IsWidget
hierarchy of the application's UI.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum used to determine whether the aggregated view includes elements of ancestor (parent, grand-parent etc.) contexts.static enum
Enum used to determine whether the aggregated view includes elements of child contexts. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Ensures that this collection contains the specified element (optional operation).void
addChildContext
(Context child) Adds the context as child context and registers itself asContextListener
.void
addContextChangeListener
(ContextListener contextListener) Adds aContextListener
to the collection of the listeners.static boolean
changed
(com.google.gwt.user.client.ui.IsWidget c) Propagate a context change for the Context associated with the given component.void
clear()
Removes all of the elements from this collection (optional operation).void
Propagate context changes to all parent contexts and actions that are registered asContextListener
.static void
Deprecated.static Context
get
(com.google.gwt.user.client.ui.IsWidget component) Get the context for a given component by looking at the client properties.protected Collection
<Context> Returns the child contexts.com.google.gwt.user.client.ui.IsWidget
getOwner()
Returns the GUI component this context is associated with - the owner.Return the parent context of this context.static Context
getPrivateContext
(com.google.gwt.user.client.ui.IsWidget component) Get the context for a given component by looking at the client properties.protected Collection
<ContextListener> Returns the registeredContextListener
sstatic Context
install
(com.google.gwt.user.client.ui.IsWidget owner, Context.Children ca, Context.Ancestors aa) Install a context with the given aggregation mode on the given owner.boolean
isActive()
Returns the info if the context is active.iterator()
Returns an iterator over the elements in this context.boolean
Removes a single instance of the specified element from this collection, if it is present (optional operation).void
removeChildContext
(Context child) Removes the context from the collection of child contexts and unregisters itself asContextListener
.void
removeContextChangeListener
(ContextListener contextListener) Removes aContextListener
from the collection of listeners so that it doesn't receive notifications any longer.void
setActive
(boolean active) Sets the Sets the active.void
setAutoHierarchyManagement
(boolean autoHierarchyManagement) int
size()
Returns the number of elements in this collection.toString()
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Method Details
-
get
Get the context for a given component by looking at the client properties. If the component does have a context, it is returned. Otherwise the component hierarchy is searched upwards until a context is found or the root is reached.- Parameters:
component
- TheIsWidget
which presumably has an attachedContext
.- Returns:
- the context or
null
if no component in the hierarchy had a context.
-
changed
public static boolean changed(com.google.gwt.user.client.ui.IsWidget c) Propagate a context change for the Context associated with the given component. Don't propagate a change, if the component doesn't have a context.- Parameters:
c
- The element to be evaluated.- Returns:
true
if there was a context to which the change could be propagated,false
otherwise.
-
getPrivateContext
Get the context for a given component by looking at the client properties. Return the context ornull
if it doesn't have one. In contrast toget(IsWidget)
,this method doesn't look at ancestors in the component hierarchy.- Parameters:
component
- TheIsWidget
which is searched for an attachedContext
- Returns:
- the context or
null
if no component in the hierarchy had a context.
-
install
public static Context install(com.google.gwt.user.client.ui.IsWidget owner, Context.Children ca, Context.Ancestors aa) Install a context with the given aggregation mode on the given owner. Wire it to its parent, if the owner already has one, otherwise postpone the wiring until the owner is added to one.- Parameters:
owner
- Theobject
where theContext
is installed toca
- The childrenaa
- The ancestors- Returns:
- The newly installed context.
-
destroy
Deprecated.This method was deprecated on the moment when it was created, as it is only intended to be a temporary workaround. Especially when working with tabs,where each tab has its own viewer, this method is needed. See more in the reference handbook, section "known issues", available e.g. on the public available web site- Parameters:
context
- the context holding the to be removed items like thePageView
-
setAutoHierarchyManagement
public void setAutoHierarchyManagement(boolean autoHierarchyManagement) -
iterator
Returns an iterator over the elements in this context. There are no guarantees concerning the order in which the elements are returned.depending on the
Returns an iterator over the elements in this context as well as all of the parent contexts up to the root context. The Elements are returned by context with the local (this) context's first, then the parent's Objects etc.
- Specified by:
iterator
in interfaceCollection<Object>
- Specified by:
iterator
in interfaceIterable<Object>
- Specified by:
iterator
in classAbstractCollection<Object>
- Returns:
- an
Iterator
over the elements in this context
-
addChildContext
Adds the context as child context and registers itself asContextListener
.- Parameters:
child
- theContext
which should be registered in the context
-
removeChildContext
Removes the context from the collection of child contexts and unregisters itself asContextListener
.- Parameters:
child
- which should be removed from the list of the context
-
addContextChangeListener
Adds aContextListener
to the collection of the listeners. Information about context changes is sent to listeners registered here.- Parameters:
contextListener
- theContextListener
to be added to the collection of listeners.
-
removeContextChangeListener
Removes aContextListener
from the collection of listeners so that it doesn't receive notifications any longer.- Parameters:
contextListener
- theContextListener
to remove from the collection of listeners.
-
contextChanged
public void contextChanged()Propagate context changes to all parent contexts and actions that are registered asContextListener
. -
add
Ensures that this collection contains the specified element (optional operation). Returns
true
if this collection changed as a result of the call. (Returnsfalse
if this collection does not permit duplicates and already contains the specified element.)Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add
null
elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning
false
). This preserves the invariant that a collection always contains the specified element after this call returns.- Specified by:
add
in interfaceCollection<Object>
- Overrides:
add
in classAbstractCollection<Object>
- Parameters:
o
- element whose presence in this collection is to be ensured.- Returns:
true
if this collection changed as a result of the call- Throws:
UnsupportedOperationException
-add
is not supported by this collection.ClassCastException
- class of the specified element prevents it from being added to this collection.NullPointerException
- if the specified element is null and this collection does not support null elements.IllegalArgumentException
- some aspect of this element prevents it from being added to this collection.
-
clear
public void clear()Removes all of the elements from this collection (optional operation). This collection will be empty after this method returns unless it throws an exception.- Specified by:
clear
in interfaceCollection<Object>
- Overrides:
clear
in classAbstractCollection<Object>
- Throws:
UnsupportedOperationException
- if theclear
method is not supported by this collection.
-
remove
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elemente
such that(o==null ? e==null : o.equals(e))
, if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
remove
in interfaceCollection<Object>
- Overrides:
remove
in classAbstractCollection<Object>
- Parameters:
o
- the element to be removed from this collection, if present.- Returns:
true
if this collection changed as a result of the call.false
otherwise.- Throws:
ClassCastException
- if the type of the specified element is incompatible with this collection (optional).NullPointerException
- if the specified element is null and this collection does not support null elements (optional).UnsupportedOperationException
- remove is not supported by this collection.
-
size
public int size()Returns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUE
elements this method will returnInteger.MAX_VALUE
.- Specified by:
size
in interfaceCollection<Object>
- Specified by:
size
in classAbstractCollection<Object>
- Returns:
- the number of elements in this collection
-
isActive
public boolean isActive()Returns the info if the context is active.- Returns:
true
if this context is active.false
otherwise.
-
setActive
public void setActive(boolean active) Sets the Sets the active. This property is important to read the context objects just from the active child context.- Parameters:
active
- the stat
-
getChildren
Returns the child contexts.- Returns:
- a collection of the child contexts
-
getRegisteredListeners
Returns the registeredContextListener
s- Returns:
- a collection of the ContextListeners
-
getOwner
public com.google.gwt.user.client.ui.IsWidget getOwner()Returns the GUI component this context is associated with - the owner.- Returns:
- the GUI component this context is associated with.
-
toString
- Overrides:
toString
in classAbstractCollection<Object>
-
getParent
Return the parent context of this context.- Returns:
- the parent context of this context.
-