Class GroovyStaticImports

java.lang.Object
org.freeplane.plugin.script.GroovyStaticImports

public class GroovyStaticImports extends Object
Provides static imports for Freeplane scripting utilities to enable easy access to common functionality when compiling Groovy source code outside of Freeplane's script environment.

This class is particularly useful when creating utility scripts or add-on classes that need to be compiled as JAR files. In regular Freeplane scripts, these utilities are available as global variables, but when compiling outside Freeplane, you need to import them explicitly.

Usage:

 import static org.freeplane.plugin.script.GroovyStaticImports.*
 
 // Now you can use:
 logger.info("Hello from my utility script")
 ui.informationMessage("This is a message")
 String plainText = htmlUtils.htmlToPlain("<b>Bold text</b>")
 

The following utilities are made available through static imports:

Additionally, this class provides utility methods for common operations like null checking, number rounding, text parsing, and formatting.

Since:
1.12.x (created on 30 Jan 2024)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Accessor for Freeplane's configuration properties.
    static final HtmlUtils
    Utilities for HTML/XML processing including conversion between HTML and plain text.
    static final LogUtils
    Utilities for logging messages to Freeplane's log file.
    static final MenuUtils
    Utilities for menu operations and menu item execution.
    static final ScriptUtils
    Utilities for script-specific operations, particularly useful in utility scripts and add-ons.
    static final TextUtils
    Utilities for text processing, translations, formatting, and string operations.
    static final UITools
    Utilities for GUI operations including dialogs, message boxes, and UI components access.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    format(Object object)
    Applies default date-time format for dates or default number format for numbers.
    static Object
    format(Object object, String formatString)
    uses formatString to return a FormattedObject.
    static Object
    Applies default date format (instead of standard date-time) format on the given date.
    static Object
    ifNull(Object value, Object valueIfNull)
    returns valueIfNull if value is null and value otherwise.
    static <T> T
    ignoreCycles(Supplier<T> closure)
    Executes the given closure while ignoring any cyclic dependencies in formulas.
    static Object
    parse(String text)
    parses text to the proper data type, if possible, setting format to the standard.
    static Long
    rounds a number to integral type.
    static Double
    round(Double d, int precision)
    round to the given number of decimal places: round(0.1234, 2) → 0.12
    static String
    formats according to the internal standard, that is the conversion will be reversible for types that are handled special by the scripting api namely Dates and Numbers.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      public static final LogUtils logger
      Utilities for logging messages to Freeplane's log file. Use for debugging and error reporting.
      See Also:
    • ui

      public static final UITools ui
      Utilities for GUI operations including dialogs, message boxes, and UI components access.
      See Also:
    • htmlUtils

      public static final HtmlUtils htmlUtils
      Utilities for HTML/XML processing including conversion between HTML and plain text.
      See Also:
    • textUtils

      public static final TextUtils textUtils
      Utilities for text processing, translations, formatting, and string operations.
      See Also:
    • scriptUtils

      public static final ScriptUtils scriptUtils
      Utilities for script-specific operations, particularly useful in utility scripts and add-ons.
      See Also:
    • config

      public static final FreeplaneScriptBaseClass.ConfigProperties config
      Accessor for Freeplane's configuration properties. Provides access to all configuration settings.

      Note: In utility scripts and add-on classes, this static instance is the recommended way to access configuration, as the global config variable is not available when compiling outside Freeplane.

  • Constructor Details

    • GroovyStaticImports

      public GroovyStaticImports()
  • Method Details

    • ignoreCycles

      public static <T> T ignoreCycles(Supplier<T> closure)
      Executes the given closure while ignoring any cyclic dependencies in formulas. If there are cyclic dependencies, formulas are skipped without warnings or exceptions.
      Type Parameters:
      T - the return type of the closure
      Parameters:
      closure - the operation to execute
      Returns:
      the result of the closure execution
    • ifNull

      public static Object ifNull(Object value, Object valueIfNull)
      returns valueIfNull if value is null and value otherwise.
    • round

      public static Long round(Double d)
      rounds a number to integral type.
    • round

      public static Double round(Double d, int precision)
      round to the given number of decimal places: round(0.1234, 2) → 0.12
    • parse

      public static Object parse(String text)
      parses text to the proper data type, if possible, setting format to the standard. Parsing is configured via config file scanner.xml
       assert parse('2012-11-30') instanceof Date
       assert parse('1.22') instanceof Number
       // if parsing fails the original string is returned
       assert parse('2012XX11-30') == '2012XX11-30'
      
       def d = parse('2012-10-30')
       c.statusInfo = "${d} is ${new Date() - d} days ago"
       
    • format

      public static Object format(Object object, String formatString)
      uses formatString to return a FormattedObject.

      Note: If you want to format the node core better use the format node attribute instead:

       node.object = new Date()
       node.format = 'dd/MM/yy'
       
      Returns:
      invalid reference
      IFormattedObject
      if object is formattable and the unchanged object otherwise.
    • format

      public static Object format(Object object)
      Applies default date-time format for dates or default number format for numbers. All other objects are left unchanged.
      Returns:
      invalid reference
      IFormattedObject
      if object is formattable and the unchanged object otherwise.
    • formatDate

      public static Object formatDate(Date date)
      Applies default date format (instead of standard date-time) format on the given date.
      Returns:
      invalid reference
      IFormattedObject
      if object is formattable and the unchanged object otherwise.
    • toString

      public static String toString(Object o)
      formats according to the internal standard, that is the conversion will be reversible for types that are handled special by the scripting api namely Dates and Numbers.
      See Also: