Interface IPluginFormElementTemplateStatic

All Superinterfaces:
IFCPlugin, INamedUiElement, INameProviding, IPluginFormElementTemplate, ITransferable, Serializable

public interface IPluginFormElementTemplateStatic extends IPluginFormElementTemplate
Mixin that implements the methods of IPluginFormElementTemplate 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 at src/main/resources/properties/i18n_*.properties

You then need implement getTemplateBasePath() and return data/templates, as well as getResourceBundlePath() and return properties/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 for template1.tags and template2.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 an XTextField and that template2 is an XFieldSet, that method should return

 return Map.of("template1", "XTextField", "template2", "XFieldSet");
 
Note on message keys: The name of the message key is derived from the template path as returned by getTemplateResources(), 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, the prefix is added with a dot in between. So, for example, if the prefix is set to my.plugin, and the path is sub/folder/special&char, then e.g. the template name would be looked up with the key my.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
  • Method Details

    • 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 the template 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

      Description copied from interface: IPluginFormElementTemplate
      Finds all templates that should be made available for a given form.
      Specified by:
      getTemplateList in interface IPluginFormElementTemplate
      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 interface IPluginFormElementTemplate
      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 the getTemplateBasePath(), 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.