Class StaticFormTheme

  • All Implemented Interfaces:
    IFormTheme

    public final class StaticFormTheme
    extends Object
    implements IFormTheme
    A generic implementation of IFormTheme with a builder. Assumes the set of available files in the theme is known statically. Not intended for use cases when the set of available files must be determined dynamically.

    The builder lets configure various options. It also lets you add files to the theme. The available files must be known beforehand, but the contents can be loaded dynamically. You can either specify the content for each file separately, or use a global loader that is able to load files for a given context and file path.

    This implementation is immutable and thread-safe, providing user provided logic such as loaders are also immutable and thread-safe.

    Since:
    8.3.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • containsFile

        public boolean containsFile​(String context,
                                    String filePath)
        Description copied from interface: IFormTheme
        Checks if the form theme contains a file with the given name. This method only checks files from this particular form theme, implementations must NOT attempt to check files from the parent theme (if any).
        Specified by:
        containsFile in interface IFormTheme
        Parameters:
        context - The context from which to retrieve the file. See EFormThemeResourceContext for common contexts. Other resource contexts may be used by plugins.
        filePath - The name of the file to check.
        Returns:
        True if the file exists, false otherwise.
      • getCssClasses

        public Set<String> getCssClasses()
        Description copied from interface: IFormTheme
        Gets a list of CSS classes that should be added to the container element. The exact nature of the container element depends on how and where the form is used. You should not make any assumptions about the container element, other than that all relevant elements will be inside that container.

        You could e.g. use these CSS classes as part of a CSS selector to style the form.

        Specified by:
        getCssClasses in interface IFormTheme
        Returns:
        A list of CSS classes to add to the container element.
      • getDisplayName

        public String getDisplayName​(Locale locale)
        Description copied from interface: IFormTheme
        Gets the display name of this theme in the given locale. The display name is a human-readable name that can be shown to the user, e.g. in the form designer.
        Specified by:
        getDisplayName in interface IFormTheme
        Parameters:
        locale - The locale for which to retrieve the display name.
        Returns:
        The display name of this theme in the given locale.
      • getFileInheritanceMode

        public EFormThemeFileInheritanceMode getFileInheritanceMode​(String context,
                                                                    String filePath)
        Description copied from interface: IFormTheme
        Controls the behavior when a IFormTheme and its parent both contain a file with the same name.
        Specified by:
        getFileInheritanceMode in interface IFormTheme
        Parameters:
        context - The context for which to retrieve the inheritance mode. See EFormThemeResourceContext for well-known contexts. Other resource contexts may be used by plugins.
        filePath - The path of the file to check. Should be one of the paths returned by getFilePaths.
        Returns:
        The inheritance mode for the given file.
      • getFilePaths

        public Set<String> getFilePaths​(String context)
        Description copied from interface: IFormTheme
        Returns a list of all file paths in this form theme. This method only returns files from this particular form theme, implementations must NOT attempt to access files from the parent theme (if any).

        The order in which the file names are returned is irrelevant. If an order is required, the framework will sort the file names as needed.

        Note regarding file paths: Paths are used as-is, and passed on to other methods that require a file path. If you need case-insensitive file paths, you need to implement the other methods appropriately. Also, when a file name contains a forward slash, this is interpreted as a path separator and used e.g. when generating URLs. For example, a file named a/b/c.css can reference a file named a/b/d.png via background-image: url(../d.png).

        Specified by:
        getFilePaths in interface IFormTheme
        Parameters:
        context - The context for which to retrieve the file name. See EFormThemeResourceContext for common contexts. Other resource contexts may be used by plugins.
        Returns:
        A list of all file names in this form theme.
      • getGroupName

        public String getGroupName​(Locale locale)
        Description copied from interface: IFormTheme
        Gets the localized group name of this theme in the given locale. The group name may be used on the UI, e.g. when displaying a select list of all available themes.
        Specified by:
        getGroupName in interface IFormTheme
        Parameters:
        locale - The locale for which to retrieve the group name.
        Returns:
        The group name of this theme in the given locale.
      • getParentFormTheme

        public FormThemeReference getParentFormTheme()
        Description copied from interface: IFormTheme
        The parent form theme from which this form theme inherits. If this form theme has no parent, this method returns null. When a form theme has a parent.
        Specified by:
        getParentFormTheme in interface IFormTheme
        Returns:
        The parent form theme, or null if this form theme has no parent.
      • isOfferCssClassesAsSuggestions

        public boolean isOfferCssClassesAsSuggestions​(String context,
                                                      String filePath)
        Description copied from interface: IFormTheme
        Controls the behavior in the form designer. Users can add custom classes to form elements. The form designer offers the CSS classes from themes as suggestions. If this method returns false, the CSS classes from this file (and all files it @imports) are not offered as suggestions.

        This method will only be called for CSS files.

        Specified by:
        isOfferCssClassesAsSuggestions in interface IFormTheme
        Parameters:
        context - The context of the CSS file to check. See EFormThemeResourceContext for common contexts. Other resource contexts may be used by plugins.
        filePath - The path of the file to check. Should be one of the paths returned by getFilePaths.
        Returns:
        True if the CSS classes from this file should be offered as suggestions, false otherwise.
      • openFile

        public InputStream openFile​(String context,
                                    String filePath)
                             throws IOException
        Description copied from interface: IFormTheme
        Opens an input stream to the file with the given name. The file name must be one of the file names returned by IFormTheme.getFilePaths(String) . This method only returns files from this particular form theme, implementations must NOT attempt to access files from the parent theme (if any).
        Specified by:
        openFile in interface IFormTheme
        Parameters:
        context - The context from which to retrieve the file. See EFormThemeResourceContext for common contexts. Other resource contexts may be used by plugins.
        filePath - The path of the file to open. Should be one of path returned by IFormTheme.getFilePaths(String).
        Returns:
        An input stream to the contents of the file.
        Throws:
        IOException - If the file could not be opened.
      • builder

        public static StaticFormTheme.Builder builder()
        Creates a new builder for a form theme.

        The builder lets configure various options. It also lets you add files to the theme. The available files must be known beforehand, but the contents can be loaded dynamically. You can either specify the content for each file separately, or use a global loader that is able to load files for a given context and file path.

        Returns:
        A new form theme builder.