Class WindowBuilderData
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.window.WindowBuilderData
-
- All Implemented Interfaces:
SimpleBeanStoreImpl.BeanContributor
public class WindowBuilderData extends Object implements SimpleBeanStoreImpl.BeanContributor
A data class that stores important information needed during a window builder process.
An instance of this class lives in the Jelly context during execution of a Jelly script that makes use of the window builder library. It contains parameters required by tag handler classes, e.g. the window manager to use. It will also store the results of the builder operation.
In most cases a builder script will define only a single result window (if any). In this case the result window can be set using the
setResultWindow(Window)
method and queried usinggetResultWindow()
. However, scripts are allowed to define multiple windows (an example use case would be a simple message box window which is displayed by an action of the main window). This can be achieved by giving the windows unique names; i.e. thename
attribute of the window tag must be defined. Then, instead ofsetResultWindow(Window)
, theputWindow(String, Window)
method can be called to add the result window to this data object.putWindow(String, Window)
adds the window to an internal map so that it can be queried later by its name.Some objects managed by this class are available to the dependency injection framework (they can be obtained through the
BeanContext
of the active builder). These are the following:- The result window (provided that it already has been set) can be obtained using the key "CURRENT_WINDOW".
- Windows that have been assigned a name can be queried directly. The
prefix "window:" has to be used, e.g.
window:msgBox
returns the window with the name msgBox. - The parent window (if available) can be queried using the key "PARENT_WINDOW".
- If the current form bean is needed, it can be found in the context under the key "FORM_BEAN".
- Finally the active instance of this class can be obtained under the key "WINDOW_BUILDER_DATA".
- Version:
- $Id: WindowBuilderData.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Field Summary
Fields Modifier and Type Field Description static String
KEY_CURRENT_WINDOW
Constant for the key, under which the current result window can be obtained from the builder's bean context.static String
KEY_FORM_BEAN
Constant for the key, under which the current form bean can be obtained from the builder's bean context.static String
KEY_PARENT_WINDOW
Constant for the key, under which the parent window can be obtained from the builder's bean context.static String
KEY_WINDOW_BUILDER_DATA
Constant for the key, under which the instance of this class can be obtained from the builder's bean context.static String
WINDOW_PREFIX
Constant for the prefix for window beans.
-
Constructor Summary
Constructors Constructor Description WindowBuilderData()
Creates a new instance ofWindowBuilderData
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beanNames(Set<String> names)
Obtains the names of the supported beans.static WindowBuilderData
get(org.apache.commons.jelly.JellyContext context)
Returns the instance of this class stored in the specified Jelly context.Object
getBean(String name)
Returns the bean with the specified name.org.apache.commons.jelly.JellyContext
getContext()
Returns the currentJellyContext
.Object
getFormBean()
Returns the form bean.Window
getParentWindow()
Returns the parent window of the new window.Window
getResultWindow()
Returns the result window of the builder process.Window
getWindow(String name)
Returns the result window with the given name.WindowManager
getWindowManager()
Returns the window manager.void
initBeanStore(SimpleBeanStoreImpl store)
Initializes the specified bean store.void
put(org.apache.commons.jelly.JellyContext ctx)
Stores this instance in the specified Jelly context.void
putWindow(String name, Window window)
Adds a result window to this data object.void
setFormBean(Object formBean)
Sets the form bean.void
setParentWindow(Window parentWindow)
Sets the parent window.void
setResultWindow(Window resultWindow)
Sets the result window.void
setWindowManager(WindowManager windowManager)
Sets the window manager.
-
-
-
Field Detail
-
KEY_CURRENT_WINDOW
public static final String KEY_CURRENT_WINDOW
Constant for the key, under which the current result window can be obtained from the builder's bean context.- See Also:
- Constant Field Values
-
KEY_PARENT_WINDOW
public static final String KEY_PARENT_WINDOW
Constant for the key, under which the parent window can be obtained from the builder's bean context.- See Also:
- Constant Field Values
-
KEY_FORM_BEAN
public static final String KEY_FORM_BEAN
Constant for the key, under which the current form bean can be obtained from the builder's bean context.- See Also:
- Constant Field Values
-
KEY_WINDOW_BUILDER_DATA
public static final String KEY_WINDOW_BUILDER_DATA
Constant for the key, under which the instance of this class can be obtained from the builder's bean context.- See Also:
- Constant Field Values
-
WINDOW_PREFIX
public static final String WINDOW_PREFIX
Constant for the prefix for window beans. If a window is to be queried by its name, this prefix has to be used.- See Also:
- Constant Field Values
-
-
Method Detail
-
getFormBean
public Object getFormBean()
Returns the form bean.- Returns:
- the form bean
-
setFormBean
public void setFormBean(Object formBean)
Sets the form bean. This information will be processed by form controllers that can use it to initialize forms and store user input.- Parameters:
formBean
- the form bean
-
getParentWindow
public Window getParentWindow()
Returns the parent window of the new window.- Returns:
- the parent window
-
setParentWindow
public void setParentWindow(Window parentWindow)
Sets the parent window. The newly created window will be a child of this window. For top level windows this property should be null.- Parameters:
parentWindow
- the parent window
-
getResultWindow
public Window getResultWindow()
Returns the result window of the builder process.- Returns:
- the result window
-
setResultWindow
public void setResultWindow(Window resultWindow)
Sets the result window. Used by window creating tag handler classes to store their results.- Parameters:
resultWindow
- the result window
-
getWindow
public Window getWindow(String name)
Returns the result window with the given name. Windows can be assigned a name. Using this name they can be queried. This is especially useful for builder scripts that define multiple windows. Using this method a specific window can be queried.- Parameters:
name
- the name of the desired window- Returns:
- the window with this name or null if it cannot be resolved
-
getContext
public org.apache.commons.jelly.JellyContext getContext()
Returns the currentJellyContext
. This information can be useful when access to objects local to the current build operation is needed. Note that this property is only initialized after this object was stored in the context. (This is the case while a build operation is executing.) If this method is called before a context is available, anIllegalStateException
exception is thrown.- Returns:
- the current
JellyContext
- Throws:
IllegalStateException
- if the current context is not yet available- Since:
- 1.3
-
putWindow
public void putWindow(String name, Window window)
Adds a result window to this data object. This method can be called for each window created during the builder operation. If a name is specified, the window is stored in a map where it can be accessed later using this name (usinggetWindow(String)
). This method also invokessetResultWindow(Window)
, so that the passed in window becomes the result window. This means that if a script defines multiple windows, the last one becomes the official result window.- Parameters:
name
- the name of the window; can be null, then the window cannot be queried usinggetWindow(String)
window
- the window to be added
-
getWindowManager
public WindowManager getWindowManager()
Returns the window manager.- Returns:
- the window manager
-
setWindowManager
public void setWindowManager(WindowManager windowManager)
Sets the window manager. Here the platform specific window manager must be set, which will be used for creating windows.- Parameters:
windowManager
- the window manager to use
-
beanNames
public void beanNames(Set<String> names)
Obtains the names of the supported beans. This implementation adds the names of some static beans. If there are named windows, their names are added as well.- Specified by:
beanNames
in interfaceSimpleBeanStoreImpl.BeanContributor
- Parameters:
names
- a set in which to store the bean names
-
getBean
public Object getBean(String name)
Returns the bean with the specified name. This implementation supports a few objects that are managed by this object. Named windows can also be queried.- Specified by:
getBean
in interfaceSimpleBeanStoreImpl.BeanContributor
- Parameters:
name
- the name of the desired bean- Returns:
- the bean with this name or null if it cannot be found
-
initBeanStore
public void initBeanStore(SimpleBeanStoreImpl store)
Initializes the specified bean store. This implementation adds the static object references to the store and registers this object as bean contributor.- Parameters:
store
- the store to be initialized
-
put
public void put(org.apache.commons.jelly.JellyContext ctx)
Stores this instance in the specified Jelly context.- Parameters:
ctx
- the context (must not be null)- Throws:
IllegalArgumentException
- if the context is null
-
get
public static WindowBuilderData get(org.apache.commons.jelly.JellyContext context)
Returns the instance of this class stored in the specified Jelly context. If no instance can be found, null will be returned.- Parameters:
context
- the Jelly context- Returns:
- the instance found in this context
-
-