/* * Copyright (c) 2010, 2025 BSI Business Systems Integration AG * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 */ import { Action, ActionStyle, ActionTextPosition, Button, ButtonAdapterMenuModel, ButtonDisplayStyle, ButtonModel, Event, EventHandler, FormFieldLabelPosition, GridData, InitModelOf, Menu, MenuBar, PropertyChangeEvent, SomeRequired } from '../index'; export class ButtonAdapterMenu extends Menu implements ButtonAdapterMenuModel { declare model: ButtonAdapterMenuModel; declare initModel: SomeRequired; button: Button; menubar: MenuBar; protected _buttonPropertyChangeHandler: EventHandler; protected _buttonDestroyHandler: EventHandler>; constructor() { super(); this._removeWidgetProperties('childActions'); // managed by button this._buttonPropertyChangeHandler = this._onButtonPropertyChange.bind(this); this._buttonDestroyHandler = this._onButtonDestroy.bind(this); this._addCloneProperties(['button']); this.button = null; this.menubar = null; } protected override _init(model: InitModelOf) { super._init(model); if (!this.button) { throw new Error('Cannot adapt to undefined button'); } this.button.adaptedBy = this; this._installListeners(); } protected override _destroy() { super._destroy(); delete this.button.adaptedBy; } protected _installListeners() { this.button.on('propertyChange', this._buttonPropertyChangeHandler); this.button.on('destroy', this._buttonDestroyHandler); } protected _uninstallListeners() { this.button.off('propertyChange', this._buttonPropertyChangeHandler); this.button.off('destroy', this._buttonDestroyHandler); } protected override _render() { super._render(); // Convenience: Add ID of original button to DOM for debugging purposes this.$container.attr('data-buttonadapter', this.button.id); } protected _onButtonPropertyChange(event: PropertyChangeEvent) { // Whenever a button property changes, apply the changes to the menu let changedProperties: Partial = {}; changedProperties[event.propertyName] = event.newValue; changedProperties = ButtonAdapterMenu.adaptButtonProperties(changedProperties); for (let prop in changedProperties) { // NOSONAR // Set the property (don't use callSetter because this may delegate to the button) this.setProperty(prop, changedProperties[prop]); } } protected _onButtonDestroy(event: Event