Interface IPluginFormElementTemplateStatic
-
- All Superinterfaces:
IFCPlugin
,INamedUiElement
,INameProviding
,IPluginFormElementTemplate
,ITransferable
,Serializable
public interface IPluginFormElementTemplateStatic extends IPluginFormElementTemplate
Mixin that implements the methods ofIPluginFormElementTemplate
with defaults for static form element template plugins, when you have all templates stored as resources in the plugin's class path (i.e.src/main/resources
folder).For the following example, let us assume all templates files are located at
src/main/resources/data/templates
, and your resource bundle with the translated names and descriptions is located atsrc/main/resources/properties/i18n_*.properties
You then need implement
getTemplateBasePath()
and returndata/templates
, as well asgetResourceBundlePath()
and returnproperties/i18n
Next, place JSON files with the template data and image files with the icon in
src/main/resources/data/templates
, e.g.src/main/resources/data/templates/template1.json src/main/resources/data/templates/template1.png src/main/resources/data/templates/template2.json src/main/resources/data/templates/template2.jpeg
Note : If you already have the form elements configured in the form designer, you can simply select the form element, press Ctrl+c to copy the form element, go to a text editor and press Ctrl+v to paste the JSON string with the form element into the editor. This is the JSON string that you need to put in the *.json files.Also, make sure you add the add translation for the following message keys in the
resource bundle
:template1.name template1.desc template2.name template2.desc
The image must have one of the extensions.png
,.jpeg
, or.svg
. Optionally, you can also include a message key fortemplate1.tags
andtemplate2.tags
with a comma separated list of tags.Finally, you only need to return the template names and types in the
getTemplateResources()
method. If we assume that template1 is anXTextField
and that template2 is anXFieldSet
, that method should returnreturn Map.of("template1", "XTextField", "template2", "XFieldSet");
Note on message keys: The name of the message key is derived from the template path as returned bygetTemplateResources()
, with all slashes replaced special dots and all other special characters (everything other than 0-9, a-z, A-Z, underscore, dash, or dot) replaced by underscores. For the template name, the suffix.name
is added, for the template description.desc
, for the template tags.tags
. If provided, theprefix
is added with a dot in between. So, for example, if the prefix is set tomy.plugin
, and the path issub/folder/special&char
, then e.g. the template name would be looked up with the keymy.plugin.sub.folder.special_char
A static template plugin for the above example might look like this:
import java.util.Map; import de.xima.fc.plugin.interfaces.form.IPluginFormElementTemplateStatic; public class DemoStaticTemplatePlugin implements IPluginFormElementTemplateStatic { @Override public String getName() { return "demo static template plugin"; } @Override public String getResourceBundlePath() { return "properties/i18n"; } @Override public String getTemplateBasePath() { return "data/templates"; } @Override public Map<String, String> getTemplateResources() { return Map.of("template1", "XTextField", "template2", "XFieldSet"); } }
- Since:
- 8.0.1
- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
-
Fields inherited from interface de.xima.fc.plugin.interfaces.IFCPlugin
CONFIG_FILENAME
-
Fields inherited from interface de.xima.fc.interfaces.INamedUiElement
ATTR_DISPLAY_NAME
-
Fields inherited from interface de.xima.fc.entities.interfaces.INameProviding
ATTR_NAME, COL_NAME
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
getResourceBundlePath()
Gets the base path to the resource bundle, e.g.default String
getResourceKeyPrefix()
Optional prefix for the messages keys for the name, descriptions and tags.String
getTemplateBasePath()
The base path that contains the templates and icons.default IPluginFormElementTemplateList
getTemplateList(IPluginFormElementTemplateParams params)
Finds all templates that should be made available for a given form.default IPluginFormElementTemplateLoader
getTemplateLoader()
Map<String,String>
getTemplateResources()
Gets the list of paths with the available templates.default String
getTemplateSetVersion()
Gets the version of this set of form element templates.default boolean
isAppliesToContext(IPluginFormElementTemplateParams params)
Checks whether the templates should be offered for the given client, project, and form version.-
Methods inherited from interface de.xima.fc.plugin.interfaces.IFCPlugin
getDescription, getDescription, getDisplayName, getName, initialize, initPlugin, install, shutdown, shutdown, uninstall, validateConfigurationData
-
-
-
-
Method Detail
-
getResourceBundlePath
String getResourceBundlePath()
Gets the base path to the resource bundle, e.g.com/example/i18n
.- Returns:
- Path to the resource bundle.
-
getResourceKeyPrefix
default String getResourceKeyPrefix()
Optional prefix for the messages keys for the name, descriptions and tags. The message key for each template is derived from thetemplate path
.- Returns:
- Prefix for all message keys.
-
getTemplateBasePath
String getTemplateBasePath()
The base path that contains the templates and icons.- Returns:
- Base for the class path that contains the templates and icons.
-
getTemplateList
default IPluginFormElementTemplateList getTemplateList(IPluginFormElementTemplateParams params)
Description copied from interface:IPluginFormElementTemplate
Finds all templates that should be made available for a given form.- Specified by:
getTemplateList
in interfaceIPluginFormElementTemplate
- Parameters:
params
- Parameters with the current form for which to find additional templates. Implementors may choose to ignore the parameters if the templates should be available for all forms.- Returns:
- The return value with the additional templates.
-
getTemplateLoader
default IPluginFormElementTemplateLoader getTemplateLoader()
- Specified by:
getTemplateLoader
in interfaceIPluginFormElementTemplate
- Returns:
- The loader for retrieving the icon and persist JSON data of the templates.
-
getTemplateResources
Map<String,String> getTemplateResources()
Gets the list of paths with the available templates. Each path must be relative to thegetTemplateBasePath()
, and must not contain a file extension. The persist JSON must have the extension.json
, the icon (if available), must have the extension.png
,.jpeg
, or.svg
.- Returns:
- A list of paths with the available templates.
-
isAppliesToContext
default boolean isAppliesToContext(IPluginFormElementTemplateParams params)
Checks whether the templates should be offered for the given client, project, and form version.- Parameters:
params
- Parameters with the client, project, and form version.- Returns:
- Whether the templates are available in the given context.
-
getTemplateSetVersion
default String getTemplateSetVersion()
Gets the version of this set of form element templates. The version is used e.g. for caching. The default implementation returns the current timestamp, which effectively disabled caching.- Returns:
- The version of this set of form element templates.
-
-