Layout templates
Technically, the layout editor offers such components for which templates are available. Such a layout template is a file *.template.xml
in the folder WEB-INF/layouts
of the running application. A template can either be provided by the application itself, or by a TopLogic module.
Structure of a layout template
A layout template is an XML file in the namespace http://www.top-logic.com/ns/config/6.0
with the root tag template
:
<config:template
xmlns:config="http://www.top-logic.com/ns/config/6.0"
groups="..."
>
<properties extends="...">
<property name="myProp"
type="..."
>
...
</property>
...
</properties>
<component name="..."
class="..."
option="${myProp}"
>
...
</component>
</config:template>
properties
header defines the options provided by the layout editor (property
). The next (and only) element after the properties
section is the component configuration to be generated by the template. The configuration options of the configured component can refer to the value of the property named myProp
via ${myProp}
.
A property of a layout template behaves like a property of the typed configuration, which is defined instead of over the Getter of a Java interface in XML. The name of the property is given in the attribute name
. The type of the property is specified either directly in the type
attribute as a fully qualified class name if it is a primitive property. If it is a list-valued property, the type
is equal to List
and the list value type is given in element-type
. If it is an instance subconfiguration, the type
or element-type
is equal to PolymorphicConfiguration
and the type of the configured instance is given by instance-type
. Examples of properties are:
A simple Boolean property "tabVisible
" (the default value can be given via the default
attribute):
<property name="tabVisible"
default="true"
type="boolean"
/>
An instance configuration of a model builder (annotations to the property can be given in the content area of the property):
<property name="modelBuilder"
instance-type="com.top_logic.mig.html.ListModelBuilder"
type="PolymorphicConfiguration"
>
<mandatory/>
<options fun="com.top_logic.layout.form.values.edit.AllInAppImplementations"/>
</property>
A list of button instance configurations:
<property name="buttons"
element-type="com.top_logic.basic.config.PolymorphicConfiguration"
instance-type="com.top_logic.tool.boundsec.CommandHandler"
type="List"
>
<acceptable-classifiers value="commons, dialog"/>
</property>
Wizard templates
Normal templates expect the same set of options for the creation of a new component as for the subsequent editing of an already created component. However, sometimes it is useful to request only a small set of initial values when creating a new component and use them to fill the parameters of the actual template with meaningful default values. Thus from the input of a type a good default value for various lookup and test functions of a model builder can be generated.
In order to simplify the component generation in such a way, there are assistant templates, which call another template with few initial parameters to be filled and occupy the "real" parameters from the entered values. If a component created via a wizard template is edited later, the complete parameters of the actual template are then offered for editing. The following template is a wizard for the actual template my-real-component.template.xml
, which is specified in the assistant-for
attribute. In the content area of a wizard template, no component configuration is created, but the configuration of the parameters of the target template (config
):
<config:template
xmlns:config="http://www.top-logic.com/ns/config/6.0"
assistant-for="my-real-component.template.xml"
>
<properties>
<property name="initProp" type="String">
...
</properties>
<config>
<realProp>${initProp}</realProp>
</config>
</config:template>
View templates
A template can create not only a single component, but a whole view consisting of several simultaneously displayed components, dialogs and buttons. For this, a template can call other templates via temlate-call
. To a template-call
one passes the template to be instantiated with the template
-attribute and in the content area the arguments for the parameters of this template with the arguments
-element. If you turn a view template into a wizard template (see above), this has the positive side effect that the template calls become independently configurable components. I.e. after creating a view with a view wizard, several components are created that can be further processed independently of each other. The properties of each of these components can then be adjusted in the layout editor.
The following view wizard creates three components: A table next to a form and a Create dialog at the table:
<config:template
xmlns:config="http://www.top-logic.com/ns/config/6.0"
assistant-for="com.top_logic/layout.template.xml"
>
<properties extends="com.top_logic.layout.editor.config.TypeTemplateParameters">
...
</properties>
<config>
<components>
<config:template-call
layout-scope="__tableTemplateScope__"
template="com.top_logic/table.template.xml"
>
<arguments name="..."
type="..."
>
<dialogs>
<config:template-call template=".../genericCreateDialog.template.xml">
<arguments>
...
</arguments>
</config:template-call>
</dialogs>
</arguments>
</config:template-call>
<config:template-call template=".../form.template.xml">
<arguments
model="selection(__tableTemplateScope__#Table)"
/>
</config:template-call>
</components>
</config>
</config:template>
A special feature here is that a link between the selection of the table and the model of the form is created at the same time. Since table and form are created after expansion of the template by two different templates and a component reference always refers to the file, in which the component is defined, this relationship cannot be formulated actually before expansion of the template yet, because the two target files, into which the templates for table and form are expanded do not exist yet.
To realize this nevertheless, a variable for the target file ("layout scope") can be specified with a template call. With the declaration layout-scope="__tableTemplateScope__"
at the template call for the table it is said that the target file into which this template is expanded should be named __tableTemplateScope__
. This variable can then be used to refer to the table component in the model definition of the form: selection(__tableTemplateScope__#Table)
The scope variable __tableTemplateScope__
can be used like a file name to build a component reference. With expansion of the View Wizard, this variable is consistently replaced by the filenames into which the templates are expanded.