Configure a Content Adapter to use multiple Templates
In a Content Adapter you can declare to use multiple Templates. This is useful if the selected Datasource contains different types of elements. Each type can then use a dedicated Template to display its data.
To add multiple Templates to a Content Adapter
2. In the Model section of the Outline Editor, expand the project so that you view the Content Adapter where you want to add multiple Templates.
3. Right-click and select
New Child > TemplateAssignment. Select the Template you want to use from the Dropdown list. If you need create a new Template, please refer to
Creating a Template for a Custom
Object.
4. Enter the Filter Expression for this type of element. This String is required later on to identify the different types of elements from the Datasource. The String should be unique across all TemplatesAssignments within that Content Adapter.
5. Repeat steps 3 and 4 for all different types of elements that you want to display. See below for an example of a model using 3 different Templates.
6. Open the Java Source file for the Datasource that you defined in the Content Adapter.
7. Overwrite the method public boolean matchesExpression(String filterExpression, int elementIndex).
8. This method is called for each element of the Datasource to identify which Template should be used for displaying it.
a. The parameter filterExpression is one of the Filter Expression that you just defined in the TemplateAssignment.
b. The parameter elementIndex defines the index of the element in the Datasource. You can use the methods getEntityForIndex(int) (in an EntityDatasource) or getElementAtIndex(int) (in a ListDatasource) to get the element at this position.
9. In the given example we could implement this method like this:
public boolean matchesExpression(final String filterExpr, final int elementIndex) {
final IEntity entity = getEntityForIndex(elementIndex);
if ((entity instanceof TaskTypeImpl) && "task".equalsIgnoreCase(filterExpr)) {
return true;
} else if ((entity instanceof ProcessTypeImpl)
&& "process".equalsIgnoreCase(filterExpr)) {
return true;
} else if ((entity instanceof SectionTitleImpl)
&& "section".equalsIgnoreCase(filterExpr)) {
return true;
}
return false;
}