ListView

ListView 是一个基本实现,提供了绘制 items 列表的功能。继承 BoxView

ListView is a base implementation providing functionality to draw a list of items. Inherits BoxView.

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

ListView<T> is typed as its item and can take any object. Further item processing happens in a CellFactory. For conveniance there is a support for generic higher level list feature showing checked states as normal check and radio types. Essentially what you can have is a list of items which are shown as is, shown where any items can have a checked state or only one item can have a checked state.

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

默认是 item style nocheck,但可以更改。

Default item style is nocheck but can be changed.

支持 NOCHECK, CHECKRADIO`

Supports NOCHECK, CHECK and RADIO`

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

How individual cells are shown depends on a CellFactory. Default implementation simply shows item using its toString() method.

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

It can be customised by modifying a used CellFactory.

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

并将其设置为工厂:

And set it as a factory:

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 为:

Default view commands are:

Table 1. ViewCommands
Command Description

LINE_UP

Selection moves up.

LINE_DOWN

Selection moves down.

默认 key bindigs 为:

Default key bindigs are:

Table 2. Key
Command Description

CursorUp

Bound ViewCommand LINE_UP

CursorDown

Bound ViewCommand LINE_DOWN

Enter

Choose active item.

Space

Change active item selection state.

默认 mouse bindigs 为:

Default mouse bindigs are:

Table 3. Mouse
Command Description

Wheel

WheelUp

Bound ViewCommand LINE_UP

Wheel

WheelDown

Bound ViewCommand LINE_DOWN

Released

Button1

Events

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

Events are sent depending on a used list type.

Table 4. ListView Events
Event Description

ListViewOpenSelectedItemEvent

Active item is requested to get opened.

ListViewSelectedItemChangedEvent

Active item is changed.