ListView

ListView 是一个基本实现,提供了绘制 items 列表的功能。继承 BoxViewListView<T> 是其 item 的类型,可以接收任何对象。item 中的进一步处理在 CellFactory 中进行。为方便起见,它支持显示选中状态的通用较高层列表功能,如 checkradio 类型。基本上,您可以拥有一个项目列表,这些项目可以原样显示、显示其中任何项目具有选中状态或只有一个项目具有选中状态。

Unresolved include directive in modules/ROOT/pages/tui/views/list.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/ListViewSnippets.java[]

默认是 item style nocheck,但可以更改。 支持 NOCHECK, CHECKRADIO`

Unresolved include directive in modules/ROOT/pages/tui/views/list.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/ListViewSnippets.java[]

Customisation

具体如何显示各个单元取决于 CellFactory。默认实现只是使用 toString() 方法显示 item

可以通过修改已使用的 CellFactory 进行自定义。

Unresolved include directive in modules/ROOT/pages/tui/views/list.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/ListViewSnippets.java[]

并将其设置为工厂:

Unresolved include directive in modules/ROOT/pages/tui/views/list.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/ListViewSnippets.java[]

Default Bindings

默认 view commands 为:

Table 1. ViewCommands
Command Description

LINE_UP

Selection moves up.

LINE_DOWN

Selection moves down.

默认 key bindigs 为:

Table 2. Key
Command Description

CursorUp

Bound ViewCommand LINE_UP

CursorDown

Bound ViewCommand LINE_DOWN

Enter

Choose active item.

Space

更改活动项选项状态。

默认 mouse bindigs 为:

Table 3. Mouse
Command Description

Wheel

WheelUp

Bound ViewCommand LINE_UP

Wheel

WheelDown

Bound ViewCommand LINE_DOWN

Released

Button1

Events

事件根据使用的列表类型发送。

Table 4. ListView Events
Event Description

ListViewOpenSelectedItemEvent

请求打开活动项。

ListViewSelectedItemChangedEvent

Active item is changed.