Class PreviewActionSupport
java.lang.Object
io.jmix.flowui.kit.meta.component.preview.loader.PreviewActionSupport
Shared helpers for preview loaders that build menu items from XML.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA menu entry fromStudioPreviewEnvironment.mainMenuItems(). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddPlaceholderItems(BiConsumer<String, String> itemAdder) static voidapplyButtonAction(JmixButton button, String actionRef, org.dom4j.Element viewElement, StudioPreviewEnvironment environment) Applies anaction="..."reference to a button the way the runtime binder does: the button's own text/icon win, then the action element's attributes, then the standard type defaults.static BaseAction<?> buildAction(org.dom4j.Element actionElement, String fallbackId, StudioPreviewEnvironment environment) Builds aBaseActionfrom a declarative<action>element:idattribute (falling back tofallbackId),text(resolved viaresolveText(io.jmix.flowui.kit.meta.component.preview.StudioPreviewEnvironment, java.lang.String)),icon(viaComponentLoaderUtils.loadIconSetIcon(Element)), andenabled.static @Nullable StringcontainerEntityClass(org.dom4j.Element element, @Nullable String containerId) Theclassattribute of the data container with the given id in this element's own document,nullwhen the container or the attribute is absent.enumPlaceholderItems(org.dom4j.Element element, StudioPreviewEnvironment environment) Placeholder items for a list component bound to an enum entity attribute: the enum's localized constants instead of the generic "Item N".static @Nullable org.dom4j.ElementfindDescendantAction(org.dom4j.Element parent, String actionId) Recursively searchesparent's descendants for an<action id="...">element matchingactionId(covers e.g.static booleanhasRenderableItem(@Nullable org.dom4j.Element itemsElement, Set<String> renderableNames) WhetheritemsElementholds at least one child the caller can actually render.static voidloadActionItem(org.dom4j.Element itemElement, org.dom4j.Element viewElement, StudioPreviewEnvironment environment, BiConsumer<String, BaseAction<?>> actionItemAdder, BiConsumer<String, String> textItemAdder) static List<PreviewActionSupport.MenuEntry> parseMenuItems(@Nullable String json) Parses theStudioPreviewEnvironment.mainMenuItems()JSON.parseObjectArray(@Nullable String json) Parses a flat JSON array of objects with string fields (entityProperties/enumItems formats).static @Nullable StringresolveDataContainer(org.dom4j.Element element) The data container id relevant for an element: an inheriteddataContainer, or — for filter components that reference adataLoader— the container owning that loader in the descriptor's<data>section (Studio resolves containers, not loaders).static @Nullable StringresolveText(StudioPreviewEnvironment environment, @Nullable String value) Resolves amsg://message reference through the environment, falling back to the raw value when the reference isn't a message key or the environment can't resolve it (e.g.
-
Method Details
-
resolveText
public static @Nullable String resolveText(StudioPreviewEnvironment environment, @Nullable String value) Resolves amsg://message reference through the environment, falling back to the raw value when the reference isn't a message key or the environment can't resolve it (e.g.StudioPreviewEnvironment.NOOP). Null-safe: anullvalue passes through. -
buildAction
public static BaseAction<?> buildAction(org.dom4j.Element actionElement, String fallbackId, StudioPreviewEnvironment environment) Builds aBaseActionfrom a declarative<action>element:idattribute (falling back tofallbackId),text(resolved viaresolveText(io.jmix.flowui.kit.meta.component.preview.StudioPreviewEnvironment, java.lang.String)),icon(viaComponentLoaderUtils.loadIconSetIcon(Element)), andenabled. -
findDescendantAction
public static @Nullable org.dom4j.Element findDescendantAction(org.dom4j.Element parent, String actionId) Recursively searchesparent's descendants for an<action id="...">element matchingactionId(covers e.g. an<actions>block declared in the view).- Returns:
- the matching element, or
nullif none is found
-
loadActionItem
public static void loadActionItem(org.dom4j.Element itemElement, org.dom4j.Element viewElement, StudioPreviewEnvironment environment, BiConsumer<String, BaseAction<?>> actionItemAdder, BiConsumer<String, String> textItemAdder) -
applyButtonAction
public static void applyButtonAction(JmixButton button, String actionRef, org.dom4j.Element viewElement, StudioPreviewEnvironment environment) Applies anaction="..."reference to a button the way the runtime binder does: the button's own text/icon win, then the action element's attributes, then the standard type defaults. Unresolvable references (e.g. actions created in the controller) fall back to a humanized action id so the button is not blank. -
addPlaceholderItems
-
parseMenuItems
Parses theStudioPreviewEnvironment.mainMenuItems()JSON. Empty list on any problem. -
parseObjectArray
Parses a flat JSON array of objects with string fields (entityProperties/enumItems formats). Empty list on any problem. -
resolveDataContainer
The data container id relevant for an element: an inheriteddataContainer, or — for filter components that reference adataLoader— the container owning that loader in the descriptor's<data>section (Studio resolves containers, not loaders). -
containerEntityClass
public static @Nullable String containerEntityClass(org.dom4j.Element element, @Nullable String containerId) Theclassattribute of the data container with the given id in this element's own document,nullwhen the container or the attribute is absent. -
enumPlaceholderItems
public static List<String> enumPlaceholderItems(org.dom4j.Element element, StudioPreviewEnvironment environment) Placeholder items for a list component bound to an enum entity attribute: the enum's localized constants instead of the generic "Item N". Empty when the property is not an enum or the environment cannot resolve it. -
hasRenderableItem
public static boolean hasRenderableItem(@Nullable org.dom4j.Element itemsElement, Set<String> renderableNames) WhetheritemsElementholds at least one child the caller can actually render. An<items>block of only non-renderable children (e.g.componentItem, which needs the runtimeLayoutLoader) would otherwise preview as an empty menu, so callers use this to fall back toaddPlaceholderItems(java.util.function.BiConsumer<java.lang.String, java.lang.String>)instead.- Parameters:
renderableNames- item tag names the calling loader renders
-