/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import HBox from "sap/m/HBox"; import Image from "sap/m/Image"; import Label from "sap/m/Label"; import Control from "sap/ui/core/Control"; import Icon from "sap/ui/core/Icon"; import SearchLink, { $SearchLinkSettings } from "../../controls/SearchLink"; import { Assembler } from "./Assembler"; import SearchText from "../../controls/resultview/SearchText"; enum ControlItemType { text = "text", other = "other", } interface ControlItem { type: ControlItemType; control: Control; } export class ControlAssembler implements Assembler { items: Array = []; public addText(text: string) { const lastItem = this.items.at(-1); if (!lastItem || lastItem.type !== ControlItemType.text) { // create new SearchText const searchText = new SearchText(); searchText.setText(text); this.items.push({ type: ControlItemType.text, control: searchText }); return; } // add text to last SearchText const lastSearchText = lastItem.control as SearchText; lastSearchText.setText(lastSearchText.getText() + text); return; } public addImage(src: string, styleClass?: string) { const image = new Image({ src: src }); if (styleClass) { image.addStyleClass(styleClass); } this.addControl(image); } public addIcon(src: string) { this.addControl(new Icon({ src: src })); } public addLink(props: $SearchLinkSettings) { this.addControl(new SearchLink("", props)); } public addControl(control: Control) { this.items.push({ type: ControlItemType.other, control: control }); } public getResult(): Control { if (this.items.length === 0) { // no items => empty label return new Label({ text: "" }); } if (this.items.length === 1) { // single item => no wrapper needed, return item return this.items[0].control; } // more than one item => wrap in hbox and return return new HBox({ items: this.items.map((item) => item.control) }); } }