MainTabSheet 组件

是一个在多标签页中显示视图的容器。一次只能选择并显示一个标签页的内容。

XML 元素

mainTabSheet

Java 类

MainTabSheet

XML 属性

id - alignSelf - classNames - colspan - css - height - width - maxHeight - maxWidth - minHeight - minWidth - visible - themeNames - tabsDraggable

事件和处理器

AttachEvent - DetachEvent - SelectedChangeEvent - TabsCollectionChangeEvent

XML 内部元素

actions

基本用法

在 XML 的 workArea 元素中使用 mainTabSheet 元素创建该组件。workAreamainTabSheet 仅能在主视图的 XML 中使用。

下面是一个创建 mainTabSheet 的基础示例:

<mainTabSheet id="mainTabSheet"
              classNames="jmix-main-tabsheet"
              tabsDraggable="true"
              width="100%" height="100%">
    <actions>
        <action id="closeThisTabAction" type="tabmod_closeThisTab"/>
        <action id="closeOthersTabsAction" type="tabmod_closeOtherTabs"/>
        <action id="closeAllTabsAction" type="tabmod_closeAllTabs"/>
    </actions>
</mainTabSheet>

操作

mainTabSheet 组件实现了 HasActions 接口,因此可以包含标准和自定义的操作。操作通过标签页的右键菜单调用。

tabsheet context menu

标准操作包含:

tabmod_closeThisTab

操作类:CloseThisTabAction

关闭所选的标签页。

tabmod_closeOtherTabs

操作类:CloseOtherTabsAction

保留所选的标签页,关闭其他标签页。

tabmod_closeAllTabs

操作类:CloseAllTabsAction

关闭所有打开的标签页。

拖拽

mainTabSheet 还支持标签页的拖拽。这个功能可以用来对标签页进行排序。

该功能通过 tabsDraggable 属性启用。默认值为 false

tabs reordering

事件和处理器

SelectedChangeEvent

当用户切换标签页时,会触发 io.jmix.tabbedmode.component.workarea.TabbedViewsContainer.SelectedChangeEvent 事件。可以创建自定义的处理器,在标签页切换时执行特定逻辑。

下面的代码会在每次切换标签页时发出一个通知:

@Autowired
private Notifications notifications;

@Subscribe("mainTabSheet")
public void onMainTabSheetSelectedChange(final SelectedChangeEvent<MainTabSheet> event) {
    notifications.create(event.getSelectedTab() + " is now selected")
            .show();
}
如需通过 Studio 生成处理器方法的桩代码,请使用视图控制器代码顶部的 Generate Handler 按钮。或者可以在视图 XML 中选择该组件,然后在组件属性面板的 Handlers tab 生成。

TabsCollectionChangeEvent

当用户打开或关闭视图时,会创建新的标签页或删除已有的标签页,此时触发 io.jmix.tabbedmode.component.workarea.TabbedViewsContainer.TabsCollectionChangeEvent 事件。可以创建自定义的处理器,在标签页集合发生变化时执行特定逻辑。

下面的代码会在标签页集合发生变化时发出一个通知:

@Autowired
private Notifications notifications;

@Subscribe("mainTabSheet")
public void onMainTabSheetTabsCollectionChange(final TabsCollectionChangeEvent<MainTabSheet> event) {
    notifications.create("Tabs collection changed", "Change type: " + event.getChangeType())
            .show();
}
如需通过 Studio 生成处理器方法的桩代码,请使用视图控制器代码顶部的 Generate Handler 按钮。或者可以在视图 XML 中选择该组件,然后在组件属性面板的 Handlers tab 生成。

主题样式

centered

将标签页放置在主视图的中间位置,而不是默认的靠左排列:

tabs centered
small

使用小的标签页:

tabs small

minimal

减少可视化样式,仅显示标签页的文本,不带任何可视化元素:

tabs minimal

hide-scroll-buttons

隐藏标签的滚动按钮:

tabs hide scroll buttons

bordered

为标签和内容区域添加边框。

tabsheet bordered

标签文本最大宽度

标签文本最大宽度可以在应用程序主题中通过 CSS 变量设置:

html {
  --jmix-tabmod-main-tab-text-max-width: 5em;
}

tab text max width