org.wings
Class STemplateLayout

java.lang.Object
  extended by org.wings.SAbstractLayoutManager
      extended by org.wings.STemplateLayout
All Implemented Interfaces:
Serializable, Renderable, SConstants, SLayoutManager
Direct Known Subclasses:
SRootLayout

public class STemplateLayout
extends SAbstractLayoutManager

Static layout manager that uses template files to arrange components.

Like any other layout manager it allows to place arbitrary elements, but you can write a simple HTML-page being the template for your container component. Though we encourage the use of the dynamic layout managers, this layout manager can be very useful in realising the main page layout of your web application.

To use this layout manager you have to define a template file required by the STemplateLayout instance. Inside this template file you can insert inside your custom HTML code desired wingS objects using tags like

<input name="compname">

or

<object name="compname"></object>

The name attribute of these input or object tag is the name you have to use as layout constraint when you add the desired component to the template layout managed SContainer:

panel.add(new SLabel("a test label), "compname"));

Besides this simple inlining mechanism the STemplateLayout manager has also another very powerful feature: Specific components bean attributes can be overwritten by specific optional inline attributes attached to your object html tags i.e. like

<object name="compname" background="#ff0000" text="new text"></object>

Please refer to javadoc of PropertyManager for more information on this feature.

Sample template file:
<HTML><BODY> Name der Person: <COMPONENT NAME=NAME><BR> Vorname der Person: <COMPONENT NAME=VORNAME ICON="vorname.gif"><BR> Wohnort der Person: <COMPONENT NAME=WOHNORT><BR> </BODY></HTML>
According java sample code::
templateContainer.setLayout(new STemplateLayout("templatefile")); templateContainer.addComponent(new SLabel("Haaf"), "NAME"); templateContainer.addComponent(new SButton("Armin"), "VORNAME"); templateContainer.addComponent(new SLabel("Neu-Ulm"), "WOHNORT");

Author:
Armin Haaf, Jochen Woehrle, Henner Zeller
See Also:
PropertyManager, Serialized Form

Field Summary
protected  HashMap components
          Abstraction of the template source (file, resource, ..)
protected  PageParser pageParser
          PageParser to use
 
Fields inherited from class org.wings.SAbstractLayoutManager
border, cg, container, preferredSize
 
Fields inherited from interface org.wings.SConstants
BASELINE, BLOCK_ALIGN, BOTTOM, BOTTOM_ALIGN, CENTER, CENTER_ALIGN, HORIZONTAL, JUSTIFY, LEFT, LEFT_ALIGN, NO_ALIGN, RIGHT, RIGHT_ALIGN, TOP, TOP_ALIGN, UID_DIVIDER, VERTICAL
 
Constructor Summary
STemplateLayout()
           
STemplateLayout(File tmplFile)
          Read the template from a file.
STemplateLayout(String tmplFileName)
          Open a template from a file with the given name.
STemplateLayout(TemplateSource source)
          Create a TemplateLayout that reads its content from the generic TemplateSource.
STemplateLayout(URL url)
          Read the template from an URL.
 
Method Summary
 void addComponent(SComponent c, Object constraint, int index)
          add a component with the given constraint.
static void addPropertyManager(PropertyManager p)
          Adds a PropertyManager.
 SComponent getComponent(String name)
          returns a map of the constraint/component.
 PageParser getPageParser()
          Retrieve the PageParser of this instance
static PropertyManager getPropertyManager(Class c)
          Determines appropriate property manager for the given SComponent or derived class.
 TemplateSource getTemplateSource()
          Returns the source of the template layout.
 void removeComponent(SComponent comp)
          removes the given component.
static PropertyManager removePropertyManager(Class supportedComponentClass)
          Deregisters a property manager for a given component class to be able to replace it.
 void setPageParser(PageParser pageParser)
          Set the PageParser for this instance
 void setTemplate(File templateFile)
          Set the template to the template stored in the given file.
 void setTemplate(String templateFileName)
          Set the template to the template given as file name.
 void setTemplate(TemplateSource source)
          Sets the template from the DataSource.
 void setTemplate(URL templateURL)
          Set the template to the template which can be retrieved from the given URL.
 
Methods inherited from class org.wings.SAbstractLayoutManager
getBorder, getCG, getContainer, getPreferredSize, setBorder, setCG, setContainer, setPreferredSize, updateCG, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

protected HashMap components
Abstraction of the template source (file, resource, ..)


pageParser

protected transient PageParser pageParser
PageParser to use

Constructor Detail

STemplateLayout

public STemplateLayout()

STemplateLayout

public STemplateLayout(TemplateSource source)
Create a TemplateLayout that reads its content from the generic TemplateSource. The template source can be implemented to be read from any source you want to, e.g. database BLOBs. Whenever the source changes (i.e. lastModified() returns a different modification time the last time this source has been parsed), the template is reparsed.

Parameters:
source - the TemplateSource this template is to be read from.

STemplateLayout

public STemplateLayout(String tmplFileName)
                throws IOException
Open a template from a file with the given name. Whenever the file changes, the Template is reloaded.

Parameters:
tmplFileName - the filename to read the file from.
Throws:
IOException

STemplateLayout

public STemplateLayout(File tmplFile)
                throws IOException
Read the template from a file. Open a template from a file. Whenever the file changes, the Template is reloaded.

Parameters:
tmplFile - the File to read the template from.
Throws:
IOException

STemplateLayout

public STemplateLayout(URL url)
                throws IOException
Read the template from an URL. The content is cached.

Parameters:
url - the URL to read the template from.
Throws:
IOException
Method Detail

getPropertyManager

public static final PropertyManager getPropertyManager(Class c)
Determines appropriate property manager for the given SComponent or derived class. Goes up the hierarchy.


addPropertyManager

public static final void addPropertyManager(PropertyManager p)
Adds a PropertyManager. A Property Manager provides a mapping from properties given in template tags to properties of components. PropertyManager are responsible for a number of component classes; if there is already a mapping for a certain class, then this mapping is not added.


removePropertyManager

public static final PropertyManager removePropertyManager(Class supportedComponentClass)
Deregisters a property manager for a given component class to be able to replace it.

Parameters:
supportedComponentClass - Target class as in PropertyManager.getSupportedClasses()

setTemplate

public void setTemplate(String templateFileName)
                 throws IOException
Set the template to the template given as file name.

Throws:
IOException

setTemplate

public void setTemplate(File templateFile)
                 throws IOException
Set the template to the template stored in the given file.

Throws:
IOException

setTemplate

public void setTemplate(URL templateURL)
                 throws IOException
Set the template to the template which can be retrieved from the given URL.

Throws:
IOException

setTemplate

public void setTemplate(TemplateSource source)
Sets the template from the DataSource. Use this, if you hold your templates in databases etc. and write your own DataSource.

Parameters:
source - the source this template is to be read.
See Also:
TemplateSource

addComponent

public void addComponent(SComponent c,
                         Object constraint,
                         int index)
add a component with the given constraint. The contstraint in the TemplateLayout is the value of the name attribute of the object in the HTML-template.

Parameters:
c - the component to be added
constraint - the string describing the

removeComponent

public void removeComponent(SComponent comp)
removes the given component.

Parameters:
comp - the component to be removed.

getComponent

public SComponent getComponent(String name)
returns a map of the constraint/component.


getTemplateSource

public TemplateSource getTemplateSource()
Returns the source of the template layout.

Returns:
the template source
See Also:
setTemplate(TemplateSource)

getPageParser

public PageParser getPageParser()
Retrieve the PageParser of this instance

Returns:
the current PageParser

setPageParser

public void setPageParser(PageParser pageParser)
Set the PageParser for this instance

Parameters:
pageParser - the new PageParser


wingS Swings ;-)