Content Proposal Dialog Reopens if ENTER is used for ContentProposalAdapter's KeyStroke in RWT
Moved from Bug 580712.
Content Proposal Dialog Reopens if ENTER is used for ContentProposalAdapter's KeyStroke in RWT
Summary
In our solution, we're using a text field paired with a ContentProposalAdapter. Then keystroke to activate the ContentProposalAdapter is ENTER. In our SWT application the process of hitting ENTER and selecting a proposal works without any issue. However in RWT, the problem is that once ENTER is used to select a proposal, the proposal pop-up opens again.
- RAP version:
- 3.14.0-SDK-4.17.0
- Browser (issue present in all browsers that I tried):
- 105.0.1343.27 Edge
- 105.0.5195.102 Chrome
- 104.0.2 Firefox
Possibly similar issue: Bug 445464 - ContentProposalAdapter proposals popup stays visible if Combo is used as a control
Steps to Recreate Issue
Run the attached snippet as an RWT application
- In the field labeled
"Content Proposal KeyStroke = ENTER", hitENTER - Select a proposal and hit
ENTERExpected: Content Proposal Dialog closes Actual: Content Proposal Dialog reopens
NOTE: I've also added another field titled "Content Proposal KeyStroke = HOME" to demonstrate that this workflow works fine if the Content Proposal keystroke is set to anything else. This would indicate that the issue is around enter being used both by the ContentProposalAdapter and selecting items in the proposal pop-up.
Snippet to reproduce the issue:
package main;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposal;
import org.eclipse.jface.fieldassist.IContentProposalListener;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@SuppressWarnings({ "javadoc", "serial" })
public class Snippet extends AbstractEntryPoint
{
@Override
protected void createContents(Composite parent)
{
new Label(parent, SWT.NONE).setText("Content Proposal KeyStroke = ENTER"); //$NON-NLS-1$
Text enterTextField = new Text(parent, SWT.BORDER);
ContentProposalAdapter enterContentProposalAdapter = new ContentProposalAdapter(enterTextField,
new TextContentAdapter(), new SnippetContentProposalProvider(), KeyStroke.getInstance(SWT.CR), null);
enterContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
enterContentProposalAdapter.addContentProposalListener(new SnippetContentProposalListener());
new Label(parent, SWT.NONE).setText("Content Proposal KeyStroke = HOME"); //$NON-NLS-1$
Text escTextField = new Text(parent, SWT.BORDER);
ContentProposalAdapter escContentProposalAdapter = new ContentProposalAdapter(escTextField,
new TextContentAdapter(), new SnippetContentProposalProvider(), KeyStroke.getInstance(SWT.HOME), null);
escContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
escContentProposalAdapter.addContentProposalListener(new SnippetContentProposalListener());
}
private class SnippetContentProposalProvider implements IContentProposalProvider
{
public IContentProposal[] getProposals(String contents, int position)
{
return new SnippetContentProposal[] { new SnippetContentProposal("Proposal A"), //$NON-NLS-1$
new SnippetContentProposal("Proposal B"), new SnippetContentProposal("Proposal C") }; //$NON-NLS-1$ //$NON-NLS-2$
}
}
private class SnippetContentProposal implements IContentProposal
{
private final String label;
public SnippetContentProposal(String label)
{
this.label = label;
}
public String getContent()
{
return null;
}
public int getCursorPosition()
{
return 0;
}
public String getLabel()
{
return label;
}
public String getDescription()
{
return null;
}
}
private class SnippetContentProposalListener implements IContentProposalListener
{
public void proposalAccepted(IContentProposal proposal)
{
System.out.println("Proposal Accepted: " + ((SnippetContentProposal)proposal).getLabel()); //$NON-NLS-1$
}
}
}