如何使用 jfce AutoCompleteField 从字符串中搜索任何关键字
how to search any keyword from string using jfce AutoCompleteField
我有 swt 文本,其中我写了像“new AutoCompleteField (textSearch,new TextContentProvider(), searchList); 它有效,但它发现字符串以表达式开头。我想创建我自己的提案提供者,我在这里如果我的字符串包含任何关键字,我可以写一些东西,我应该得到自动完成弹出窗口。
您不能为此使用现有的 AutoCompleteField
,因为您需要更改内容提案提供者。
一个合适的 IContentProposalProvider
应该是这样的:
public class AnyPositionContentProposalProvider implements IContentProposalProvider
{
private final String [] proposals;
public AnyPositionContentProposalProvider(String [] theProposals)
{
proposals = theProposals;
}
@Override
public IContentProposal [] getProposals(String contents, int position)
{
List<IContentProposal> result = new ArrayList<>();
for (String proposal : proposals) {
if (proposal.contains(contents)) {
result.add(new ContentProposal(proposal));
}
}
return result.toArray(new IContentProposal [result.size()]);
}
}
以下方法将其设置为像 AutoCompleteField
一样工作:
// Installs on a Text control
public static void installAnyPositionMatch(Text control, String [] proposals)
{
installAnyPositionMatch(control, new TextContentAdapter(), proposals);
}
// Install on any control with a content adapter
public static void installAnyPositionMatch(Control control, IControlContentAdapter controlContentAdapter, String [] proposals)
{
IContentProposalProvider proposalProvider = new AnyPositionContentProposalProvider(proposals);
ContentProposalAdapter adapter = new ContentProposalAdapter(control, controlContentAdapter, proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
我有 swt 文本,其中我写了像“new AutoCompleteField (textSearch,new TextContentProvider(), searchList); 它有效,但它发现字符串以表达式开头。我想创建我自己的提案提供者,我在这里如果我的字符串包含任何关键字,我可以写一些东西,我应该得到自动完成弹出窗口。
您不能为此使用现有的 AutoCompleteField
,因为您需要更改内容提案提供者。
一个合适的 IContentProposalProvider
应该是这样的:
public class AnyPositionContentProposalProvider implements IContentProposalProvider
{
private final String [] proposals;
public AnyPositionContentProposalProvider(String [] theProposals)
{
proposals = theProposals;
}
@Override
public IContentProposal [] getProposals(String contents, int position)
{
List<IContentProposal> result = new ArrayList<>();
for (String proposal : proposals) {
if (proposal.contains(contents)) {
result.add(new ContentProposal(proposal));
}
}
return result.toArray(new IContentProposal [result.size()]);
}
}
以下方法将其设置为像 AutoCompleteField
一样工作:
// Installs on a Text control
public static void installAnyPositionMatch(Text control, String [] proposals)
{
installAnyPositionMatch(control, new TextContentAdapter(), proposals);
}
// Install on any control with a content adapter
public static void installAnyPositionMatch(Control control, IControlContentAdapter controlContentAdapter, String [] proposals)
{
IContentProposalProvider proposalProvider = new AnyPositionContentProposalProvider(proposals);
ContentProposalAdapter adapter = new ContentProposalAdapter(control, controlContentAdapter, proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}