路径搜索

路径搜索组件要求提供用于扫描的基础目录和可选的搜索表达式。结果显示在一个单选列表中,用户可以从中选择一个路径。PathSearchConfig 可用于自定义组件行为。

PathSearchConfig config = new PathSearch.PathSearchConfig();
config.setMaxPathsShow(5);
config.setMaxPathsSearch(100);
config.setSearchForward(true);
config.setSearchCaseSensitive(false);
config.setSearchNormalize(false);

PathSearch component = new PathSearch(getTerminal(), "Enter value", config);
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());

PathSearchContext context = component.run(PathSearchContext.empty());
return "Got value " + context.getResultValue();
搜索逻辑会原样传递给搜索算法中描述的算法。

以下截屏演示了路径搜索组件的典型输出

上下文对象是 PathSearchContext。下表描述了其上下文变量

表 1. PathSearchContext 模板变量
描述

pathViewItems

可用于渲染搜索结果的项。

model

父上下文变量(参见TextComponentContext 模板变量)。

© . This site is unofficial and not affiliated with VMware.