Class GroovyStaticImports
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:
logger
- for logging messages (seeLogUtils
)ui
- for GUI operations and dialogs (seeUITools
)htmlUtils
- for HTML/XML processing (seeHtmlUtils
)textUtils
- for text processing and translations (seeTextUtils
)menuUtils
- for menu operations (seeMenuUtils
)scriptUtils
- for script-specific utilities (seeScriptUtils
)config
- for accessing Freeplane configuration (seeFreeplaneScriptBaseClass.ConfigProperties
)
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
FieldsModifier and TypeFieldDescriptionstatic final FreeplaneScriptBaseClass.ConfigProperties
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Applies default date-time format for dates or default number format for numbers.static Object
uses formatString to return a FormattedObject.static Object
formatDate
(Date date) Applies default date format (instead of standard date-time) format on the given date.static Object
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
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 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.
-
Field Details
-
logger
Utilities for logging messages to Freeplane's log file. Use for debugging and error reporting.- See Also:
-
ui
Utilities for GUI operations including dialogs, message boxes, and UI components access.- See Also:
-
htmlUtils
Utilities for HTML/XML processing including conversion between HTML and plain text.- See Also:
-
textUtils
Utilities for text processing, translations, formatting, and string operations.- See Also:
-
scriptUtils
Utilities for script-specific operations, particularly useful in utility scripts and add-ons.- See Also:
-
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
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
returns valueIfNull if value is null and value otherwise. -
round
rounds a number to integral type. -
round
round to the given number of decimal places:round(0.1234, 2) → 0.12
-
parse
parses text to the proper data type, if possible, setting format to the standard. Parsing is configured via config file scanner.xmlassert 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
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
-
format
Applies default date-time format for dates or default number format for numbers. All other objects are left unchanged.- Returns:
-
invalid reference
IFormattedObject
-
formatDate
Applies default date format (instead of standard date-time) format on the given date.- Returns:
-
invalid reference
IFormattedObject
-
toString
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:
-