Class WApplication
-
- All Implemented Interfaces:
AjaxTarget
,Container
,DropZone
,MutableContainer
,NamingContextable
,WComponent
,WebComponent
,Serializable
public class WApplication extends AbstractMutableContainer implements AjaxTarget, DropZone
This component must be used as the top level component for an application. It provides application-wide state information, such as unsaved changes. Applications cannot be nested but multiple applications can be present on a single screen.
- Since:
- 1.0.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WApplication.ApplicationResource
Holds the details of CSS and JS custom resources.static class
WApplication.WApplicationModel
Holds the extrinsic state information of a WApplication.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WApplication()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WApplication.ApplicationResource
addCssFile(String fileName)
Add custom CSS held as an internal resource to be used by the Application.void
addCssResource(WApplication.ApplicationResource resource)
Add a custom CSS resource that will be loaded and used by this application.WApplication.ApplicationResource
addCssUrl(String url)
Add custom CSS located at the specified URL to be used by the Application.WApplication.ApplicationResource
addJsFile(String fileName)
Add custom JavaScript held as an internal resource to be used by the application.void
addJsResource(WApplication.ApplicationResource resource)
Add a custom javaScript resource that is to be loaded and used by the application.WApplication.ApplicationResource
addJsUrl(String url)
Add custom javaScript located at the specified URL to be used by the Application.protected WApplication.WApplicationModel
getComponentModel()
Returns the effective component model for this component.List<WApplication.ApplicationResource>
getCssResources()
static String
getIcon()
String
getIdName()
List<WApplication.ApplicationResource>
getJsResources()
String
getNamingContextId()
Allow components that implementNamingContextable
to selectively disable prepending their ID to their descendent's IDs by breaking the prepending logic into a seperately callable method.protected WApplication.WApplicationModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.String
getTitle()
Returns the application's title.protected String
getUiVersionKey()
Projects can override this method if different versions of the same Application need to be registered byUIRegistry
.void
handleStepError()
This method is called when a wrong step error has occurred, for example as a result of the user using the browser's navigation controls.boolean
hasUnsavedChanges()
Indicates whether the application has unsaved changes.static WApplication
instance(WComponent base)
Returns the closest WApplication instance (ancestor component) from the given base component.boolean
isAppendID()
boolean
isNamingContext()
A naming context is only considered active if an Id name has been set.protected WApplication.WApplicationModel
newComponentModel()
Creates a new model appropriate for this component.void
removeAllCssResources()
Remove all custom CSS resources.void
removeAllJsResources()
Remove all custom JavaScript resources.void
removeCssResource(WApplication.ApplicationResource resource)
Remove a custom CSS resource.void
removeJsResource(WApplication.ApplicationResource resource)
Remove a custom JavaScript resource.void
setAppendID(boolean appendID)
Sets a flag to include the WApplication's ID as part of its descendant components' IDs.void
setTitle(String title)
Sets the application title.void
setUnsavedChanges(boolean unsavedChanges)
Sets the unsavedChanges flag.String
toString()
Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractMutableContainer
add, add, remove, removeAll
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractNamingContextContainer
setNamingContext
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractContainer
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, handleRequest, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.Container
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Method Detail
-
hasUnsavedChanges
public boolean hasUnsavedChanges()
Indicates whether the application has unsaved changes.- Returns:
- true if there are unsaved changes, otherwise false
-
setUnsavedChanges
public void setUnsavedChanges(boolean unsavedChanges)
Sets the unsavedChanges flag. The unsavedChanges flag is used by the Themes to display a warning message if the user invokes a cancel button and the flag is set to true.
- Parameters:
unsavedChanges
- true if there are unsavedChanges
-
getTitle
public String getTitle()
Returns the application's title.- Returns:
- the applications's title
-
setTitle
public void setTitle(String title)
Sets the application title. The title of the first application in a view is used as the content of the page's TITLE element- Parameters:
title
- The title to set.
-
isAppendID
public boolean isAppendID()
- Returns:
- true if append application ID to IDs, otherwise false
-
setAppendID
public void setAppendID(boolean appendID)
Sets a flag to include the WApplication's ID as part of its descendant components' IDs. This is used to determine if the application's components should include the application's ID in their own ID.
Examples of where this could be useful include:
- where there are multiple applications in a single view and there is a risk of IDs clashing; or
- where the application ID is useful for separating IDs for external purposes such as implementing web analytics.
- Parameters:
appendID
- set true if append application ID to IDs
-
getIdName
public String getIdName()
- Specified by:
getIdName
in interfaceWComponent
- Overrides:
getIdName
in classAbstractWComponent
- Returns:
- the component identifier of this Component (if any).
-
isNamingContext
public boolean isNamingContext()
Description copied from class:AbstractNamingContextContainer
A naming context is only considered active if an Id name has been set.- Specified by:
isNamingContext
in interfaceNamingContextable
- Overrides:
isNamingContext
in classAbstractNamingContextContainer
- Returns:
- true as always a naming context
-
getNamingContextId
public String getNamingContextId()
Allow components that implementNamingContextable
to selectively disable prepending their ID to their descendent's IDs by breaking the prepending logic into a seperately callable method.See
WComponent.getId()
for usage.By default, this method will call through to
WComponent.getId()
and return the result.- Specified by:
getNamingContextId
in interfaceNamingContextable
- Overrides:
getNamingContextId
in classAbstractNamingContextContainer
- Returns:
- by default, return getId().
-
handleStepError
public void handleStepError()
This method is called when a wrong step error has occurred, for example as a result of the user using the browser's navigation controls.
The method can be overridden to allow projects to handle the step error in a manner appropriate to their Application.
-
instance
public static WApplication instance(WComponent base)
Returns the closest WApplication instance (ancestor component) from the given base component.- Parameters:
base
- the component from which we start scanning up the tree for a WApplication instance- Returns:
- the closest WApplication instance from the given base component
-
addJsUrl
public WApplication.ApplicationResource addJsUrl(String url)
Add custom javaScript located at the specified URL to be used by the Application.- Parameters:
url
- URL to a javaScript resource- Returns:
- the application resource in which the URL details are held
-
addJsFile
public WApplication.ApplicationResource addJsFile(String fileName)
Add custom JavaScript held as an internal resource to be used by the application.- Parameters:
fileName
- the JavaScript file name- Returns:
- the application resource in which the resource details are held
-
addJsResource
public void addJsResource(WApplication.ApplicationResource resource)
Add a custom javaScript resource that is to be loaded and used by the application.- Parameters:
resource
- the JavaScript resource
-
removeAllJsResources
public void removeAllJsResources()
Remove all custom JavaScript resources.
-
removeJsResource
public void removeJsResource(WApplication.ApplicationResource resource)
Remove a custom JavaScript resource.- Parameters:
resource
- the javaScript resource to remove
-
getJsResources
public List<WApplication.ApplicationResource> getJsResources()
- Returns:
- the set of custom JavaScript application resources
-
addCssUrl
public WApplication.ApplicationResource addCssUrl(String url)
Add custom CSS located at the specified URL to be used by the Application.- Parameters:
url
- URL to a CSS resource- Returns:
- the application resource in which the URL details are held
-
addCssFile
public WApplication.ApplicationResource addCssFile(String fileName)
Add custom CSS held as an internal resource to be used by the Application.- Parameters:
fileName
- the CSS file name- Returns:
- the application resource in which the resource details are held
-
addCssResource
public void addCssResource(WApplication.ApplicationResource resource)
Add a custom CSS resource that will be loaded and used by this application.- Parameters:
resource
- the CSS resource
-
removeAllCssResources
public void removeAllCssResources()
Remove all custom CSS resources.
-
removeCssResource
public void removeCssResource(WApplication.ApplicationResource resource)
Remove a custom CSS resource.- Parameters:
resource
- the CSS resource to remove
-
getCssResources
public List<WApplication.ApplicationResource> getCssResources()
- Returns:
- the list of custom CSS resources
-
toString
public String toString()
Description copied from class:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component for debugging purposes
-
getIcon
public static String getIcon()
- Returns:
- the application icon URL
-
getUiVersionKey
protected String getUiVersionKey()
Projects can override this method if different versions of the same Application need to be registered byUIRegistry
.Projects need to make sure the implementation of
UIRegistry
used by the project uses this key correctly. The default implementation ofUIRegistry
simply uses the class name returned by this method.It is also important to note that the serialization of the WComponent tree using
AbstractWComponent.WComponentRef
also relies on this version key.- Returns:
- the key used for the version of the application.
-
newComponentModel
protected WApplication.WApplicationModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new
WApplication.WApplicationModel
-
getComponentModel
protected WApplication.WApplicationModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classAbstractWComponent
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WApplication.WApplicationModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classAbstractWComponent
- Returns:
- the model for this component
-
-