eclipse AutoCompleteField是否仅建议以输入文本开头的条目?

时间:2020-12-30 22:24:44

I am using org.eclipse.jface.fieldassist.AutoCompleteField class to suggest my combo box options. But it's not useful, because it only suggests entries matching entered text at the beginning.

我正在使用org.eclipse.jface.fieldassist.AutoCompleteField类来建议我的组合框选项。但它没用,因为它只建议在开头匹配输入文本的条目。

JavaCode:

JavaCode:

   ComboContentAdapter comboAdapter = new ComboContentAdapter();                    
   new  AutoCompleteField(branchCombo,comboAdapter,branchCombo.getItems());

Example :

示例:

Combo Box Options:

组合框选项:

['ZMEDIA_TWITTER_MIGRATION_BRANCH','ZMEDIA_TWITTER_HOTFIX_BRANCH','ZMEDIA_FB_BRANCH'].

If I type TWITTER in combo box it suggests nothing . It looks like the TWITTER with startswith match in combobox options .

如果我在组合框中键入TWITTER,它什么都没有。看起来TWITTER与combobox选项中的startwith匹配。

Is there any option to override this?

有没有选项来覆盖这个?

Thanks You

谢谢

2 个解决方案

#1


4  

Simply put, there isn't.

简单地说,没有。

However, this can be achieved by creating your own proposal provider by implementing org.eclipse.jface.fieldassist.IContentProposalProvider and implementing your filtering logic in its' getProposals(String contents, int position) method.

但是,这可以通过实现org.eclipse.jface.fieldassist.IContentProposalProvider并在其'getProposals(String contents,int position)方法中实现过滤逻辑来创建自己的提议提供程序来实现。

Then, just add your proposal provider to a ContentProposalAdapter and adapt the combobox, as follows:

然后,只需将您的提案提供程序添加到ContentProposalAdapter并调整组合框,如下所示:

MyContentProposalProvider provider = new  MyContentProposalProvider(combo.getItems());
ContentProposalAdapter adapter = new ContentProposalAdapter(combo, comboAdapter, provider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

#2


1  

Exactly as tkotisis said, you can implement your own IContentProposalProvider, if you want a Provider to give all proposals containing any of the chars that the user have typed you can use this code I came up with.

NOTE: The convertion to a char is not neccessary you can use the raw byte too, but if you want to further proccess your Provider it can be easier to use a char!

正如tkotisis所说,您可以实现自己的IContentProposalProvider,如果您希望Provider提供包含用户键入的任何字符的所有提议,您可以使用我提供的代码。注意:转换为char不是必需的,您也可以使用原始字节,但如果您想进一步处理您的Provider,则可以更容易地使用char!

IContentProposalProvider proposalProvider = new IContentProposalProvider() {

            @Override
            public IContentProposal[] getProposals(String contents, int position) {
                String[] props = new String[] { "Test0", "Test1", "Test2",
                        "Test3" }; // This is all your propsals.
                List<IContentProposal> validProposals = new ArrayList<IContentProposal>();
                for (String prop : props) {
                    contents = contents.substring(0, position);
                    for (byte b : contents.getBytes()) {
                        char c = (char) (b & 0xFF);
                        if (prop.indexOf(c) != -1) { // This is where it checks if the proposal contains the chars.
                            validProposals.add(new ContentProposal(prop));
                            break;
                        }
                    }
                }
                return validProposals.toArray(new IContentProposal[validProposals.size()]);
            }
        };

#1


4  

Simply put, there isn't.

简单地说,没有。

However, this can be achieved by creating your own proposal provider by implementing org.eclipse.jface.fieldassist.IContentProposalProvider and implementing your filtering logic in its' getProposals(String contents, int position) method.

但是,这可以通过实现org.eclipse.jface.fieldassist.IContentProposalProvider并在其'getProposals(String contents,int position)方法中实现过滤逻辑来创建自己的提议提供程序来实现。

Then, just add your proposal provider to a ContentProposalAdapter and adapt the combobox, as follows:

然后,只需将您的提案提供程序添加到ContentProposalAdapter并调整组合框,如下所示:

MyContentProposalProvider provider = new  MyContentProposalProvider(combo.getItems());
ContentProposalAdapter adapter = new ContentProposalAdapter(combo, comboAdapter, provider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

#2


1  

Exactly as tkotisis said, you can implement your own IContentProposalProvider, if you want a Provider to give all proposals containing any of the chars that the user have typed you can use this code I came up with.

NOTE: The convertion to a char is not neccessary you can use the raw byte too, but if you want to further proccess your Provider it can be easier to use a char!

正如tkotisis所说,您可以实现自己的IContentProposalProvider,如果您希望Provider提供包含用户键入的任何字符的所有提议,您可以使用我提供的代码。注意:转换为char不是必需的,您也可以使用原始字节,但如果您想进一步处理您的Provider,则可以更容易地使用char!

IContentProposalProvider proposalProvider = new IContentProposalProvider() {

            @Override
            public IContentProposal[] getProposals(String contents, int position) {
                String[] props = new String[] { "Test0", "Test1", "Test2",
                        "Test3" }; // This is all your propsals.
                List<IContentProposal> validProposals = new ArrayList<IContentProposal>();
                for (String prop : props) {
                    contents = contents.substring(0, position);
                    for (byte b : contents.getBytes()) {
                        char c = (char) (b & 0xFF);
                        if (prop.indexOf(c) != -1) { // This is where it checks if the proposal contains the chars.
                            validProposals.add(new ContentProposal(prop));
                            break;
                        }
                    }
                }
                return validProposals.toArray(new IContentProposal[validProposals.size()]);
            }
        };